|
|
@ -37,59 +37,56 @@ |
|
|
|
|
|
|
|
|
|
|
|
class QStringRef; |
|
|
|
class QStringRef; |
|
|
|
|
|
|
|
|
|
|
|
namespace Utils |
|
|
|
namespace Utils::String |
|
|
|
{ |
|
|
|
{ |
|
|
|
namespace String |
|
|
|
QString fromDouble(double n, int precision); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int naturalCompare(const QString &left, const QString &right, const Qt::CaseSensitivity caseSensitivity); |
|
|
|
|
|
|
|
template <Qt::CaseSensitivity caseSensitivity> |
|
|
|
|
|
|
|
bool naturalLessThan(const QString &left, const QString &right) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QString fromDouble(double n, int precision); |
|
|
|
return (naturalCompare(left, right, caseSensitivity) < 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int naturalCompare(const QString &left, const QString &right, const Qt::CaseSensitivity caseSensitivity); |
|
|
|
QString wildcardToRegex(const QString &pattern); |
|
|
|
template <Qt::CaseSensitivity caseSensitivity> |
|
|
|
|
|
|
|
bool naturalLessThan(const QString &left, const QString &right) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (naturalCompare(left, right, caseSensitivity) < 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString wildcardToRegex(const QString &pattern); |
|
|
|
template <typename T> |
|
|
|
|
|
|
|
T unquote(const T &str, const QString "es = QChar('"')) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (str.length() < 2) return str; |
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
for (const QChar quote : quotes) |
|
|
|
T unquote(const T &str, const QString "es = QChar('"')) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (str.length() < 2) return str; |
|
|
|
if (str.startsWith(quote) && str.endsWith(quote)) |
|
|
|
|
|
|
|
return str.mid(1, (str.length() - 2)); |
|
|
|
for (const QChar quote : quotes) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (str.startsWith(quote) && str.endsWith(quote)) |
|
|
|
|
|
|
|
return str.mid(1, (str.length() - 2)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return str; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool parseBool(const QString &string, bool defaultValue); |
|
|
|
return str; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool parseBool(const QString &string, bool defaultValue); |
|
|
|
|
|
|
|
|
|
|
|
QString join(const QVector<QStringRef> &strings, const QString &separator); |
|
|
|
QString join(const QVector<QStringRef> &strings, const QString &separator); |
|
|
|
|
|
|
|
|
|
|
|
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0> |
|
|
|
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0> |
|
|
|
QString fromEnum(const T &value) |
|
|
|
QString fromEnum(const T &value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>, |
|
|
|
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>, |
|
|
|
"Enumeration underlying type has to be int."); |
|
|
|
"Enumeration underlying type has to be int."); |
|
|
|
|
|
|
|
|
|
|
|
const auto metaEnum = QMetaEnum::fromType<T>(); |
|
|
|
const auto metaEnum = QMetaEnum::fromType<T>(); |
|
|
|
return QString::fromLatin1(metaEnum.valueToKey(static_cast<int>(value))); |
|
|
|
return QString::fromLatin1(metaEnum.valueToKey(static_cast<int>(value))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0> |
|
|
|
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0> |
|
|
|
T toEnum(const QString &serializedValue, const T &defaultValue) |
|
|
|
T toEnum(const QString &serializedValue, const T &defaultValue) |
|
|
|
{ |
|
|
|
{ |
|
|
|
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>, |
|
|
|
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>, |
|
|
|
"Enumeration underlying type has to be int."); |
|
|
|
"Enumeration underlying type has to be int."); |
|
|
|
|
|
|
|
|
|
|
|
const auto metaEnum = QMetaEnum::fromType<T>(); |
|
|
|
const auto metaEnum = QMetaEnum::fromType<T>(); |
|
|
|
bool ok = false; |
|
|
|
bool ok = false; |
|
|
|
const T value = static_cast<T>(metaEnum.keyToValue(serializedValue.toLatin1().constData(), &ok)); |
|
|
|
const T value = static_cast<T>(metaEnum.keyToValue(serializedValue.toLatin1().constData(), &ok)); |
|
|
|
return (ok ? value : defaultValue); |
|
|
|
return (ok ? value : defaultValue); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|