mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-31 12:00:16 -07:00
Use nested namespaces definition syntax
This commit is contained in:
parent
04a9ce6e81
commit
552ff0489d
10 changed files with 196 additions and 226 deletions
|
@ -37,59 +37,56 @@
|
|||
|
||||
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);
|
||||
template <Qt::CaseSensitivity caseSensitivity>
|
||||
bool naturalLessThan(const QString &left, const QString &right)
|
||||
QString wildcardToRegex(const QString &pattern);
|
||||
|
||||
template <typename T>
|
||||
T unquote(const T &str, const QString "es = QChar('"'))
|
||||
{
|
||||
if (str.length() < 2) return str;
|
||||
|
||||
for (const QChar quote : quotes)
|
||||
{
|
||||
return (naturalCompare(left, right, caseSensitivity) < 0);
|
||||
if (str.startsWith(quote) && str.endsWith(quote))
|
||||
return str.mid(1, (str.length() - 2));
|
||||
}
|
||||
|
||||
QString wildcardToRegex(const QString &pattern);
|
||||
return str;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T unquote(const T &str, const QString "es = QChar('"'))
|
||||
{
|
||||
if (str.length() < 2) return str;
|
||||
bool parseBool(const QString &string, bool defaultValue);
|
||||
|
||||
for (const QChar quote : quotes)
|
||||
{
|
||||
if (str.startsWith(quote) && str.endsWith(quote))
|
||||
return str.mid(1, (str.length() - 2));
|
||||
}
|
||||
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
||||
|
||||
return str;
|
||||
}
|
||||
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
QString fromEnum(const T &value)
|
||||
{
|
||||
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>,
|
||||
"Enumeration underlying type has to be int.");
|
||||
|
||||
bool parseBool(const QString &string, bool defaultValue);
|
||||
const auto metaEnum = QMetaEnum::fromType<T>();
|
||||
return QString::fromLatin1(metaEnum.valueToKey(static_cast<int>(value)));
|
||||
}
|
||||
|
||||
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
||||
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
T toEnum(const QString &serializedValue, const T &defaultValue)
|
||||
{
|
||||
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>,
|
||||
"Enumeration underlying type has to be int.");
|
||||
|
||||
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
QString fromEnum(const T &value)
|
||||
{
|
||||
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>,
|
||||
"Enumeration underlying type has to be int.");
|
||||
|
||||
const auto metaEnum = QMetaEnum::fromType<T>();
|
||||
return QString::fromLatin1(metaEnum.valueToKey(static_cast<int>(value)));
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
T toEnum(const QString &serializedValue, const T &defaultValue)
|
||||
{
|
||||
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>,
|
||||
"Enumeration underlying type has to be int.");
|
||||
|
||||
const auto metaEnum = QMetaEnum::fromType<T>();
|
||||
bool ok = false;
|
||||
const T value = static_cast<T>(metaEnum.keyToValue(serializedValue.toLatin1().constData(), &ok));
|
||||
return (ok ? value : defaultValue);
|
||||
}
|
||||
const auto metaEnum = QMetaEnum::fromType<T>();
|
||||
bool ok = false;
|
||||
const T value = static_cast<T>(metaEnum.keyToValue(serializedValue.toLatin1().constData(), &ok));
|
||||
return (ok ? value : defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue