2020-07-12 20:27:56 +02:00
|
|
|
#ifndef QSTRINGUTILS_H
|
|
|
|
#define QSTRINGUTILS_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2020-10-18 17:16:27 +02:00
|
|
|
#include <QVector>
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2021-11-16 18:12:56 +01:00
|
|
|
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
#include <QStringView>
|
|
|
|
#else
|
|
|
|
#include <QStringRef>
|
|
|
|
#endif
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
namespace QStringUtils {
|
|
|
|
|
|
|
|
enum class SplitBehavior {
|
|
|
|
KeepEmptyParts,
|
|
|
|
SkipEmptyParts,
|
|
|
|
};
|
|
|
|
|
|
|
|
inline QStringList split (const QString &string, const QString &sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive)
|
|
|
|
{
|
2020-10-18 17:16:27 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
2020-07-12 20:27:56 +02:00
|
|
|
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs);
|
2020-10-18 17:16:27 +02:00
|
|
|
#else
|
2020-07-12 20:27:56 +02:00
|
|
|
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs);
|
2020-10-18 17:16:27 +02:00
|
|
|
#endif
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline QStringList split (const QString &string, QChar sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive)
|
|
|
|
{
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
|
|
|
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs);
|
|
|
|
#else
|
|
|
|
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // QSTRINGUTILS_H
|