mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Cleanup headers
Move `class NaturalCompare` to .cpp file
This commit is contained in:
parent
626a224382
commit
d25430f377
2 changed files with 35 additions and 33 deletions
|
@ -27,24 +27,31 @@
|
||||||
* exception statement from your version.
|
* exception statement from your version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QString>
|
|
||||||
#include <QLocale>
|
|
||||||
#include <cmath>
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
QString Utils::String::fromStdString(const std::string &str)
|
#include <cmath>
|
||||||
{
|
|
||||||
return QString::fromUtf8(str.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::String::toStdString(const QString &str)
|
#include <QByteArray>
|
||||||
{
|
#include <QtGlobal>
|
||||||
QByteArray utf8 = str.toUtf8();
|
#include <QLocale>
|
||||||
return std::string(utf8.constData(), utf8.length());
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
||||||
}
|
#include <QCollator>
|
||||||
|
#endif
|
||||||
|
|
||||||
Utils::String::NaturalCompare::NaturalCompare()
|
class NaturalCompare
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NaturalCompare();
|
||||||
|
bool operator()(const QString &left, const QString &right);
|
||||||
|
bool lessThan(const QString &left, const QString &right);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
||||||
|
QCollator m_collator;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
NaturalCompare::NaturalCompare()
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
|
@ -57,7 +64,7 @@ Utils::String::NaturalCompare::NaturalCompare()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::String::NaturalCompare::operator()(const QString &left, const QString &right)
|
bool NaturalCompare::operator()(const QString &left, const QString &right)
|
||||||
{
|
{
|
||||||
// case-insensitive comparison
|
// case-insensitive comparison
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
||||||
|
@ -72,7 +79,7 @@ bool Utils::String::NaturalCompare::operator()(const QString &left, const QStrin
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::String::NaturalCompare::lessThan(const QString &left, const QString &right)
|
bool NaturalCompare::lessThan(const QString &left, const QString &right)
|
||||||
{
|
{
|
||||||
// Return value `false` indicates `right` should go before `left`, otherwise, after
|
// Return value `false` indicates `right` should go before `left`, otherwise, after
|
||||||
// case-insensitive comparison
|
// case-insensitive comparison
|
||||||
|
@ -123,6 +130,17 @@ bool Utils::String::NaturalCompare::lessThan(const QString &left, const QString
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Utils::String::fromStdString(const std::string &str)
|
||||||
|
{
|
||||||
|
return QString::fromUtf8(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Utils::String::toStdString(const QString &str)
|
||||||
|
{
|
||||||
|
QByteArray utf8 = str.toUtf8();
|
||||||
|
return std::string(utf8.constData(), utf8.length());
|
||||||
|
}
|
||||||
|
|
||||||
bool Utils::String::naturalCompare(const QString &left, const QString &right)
|
bool Utils::String::naturalCompare(const QString &left, const QString &right)
|
||||||
{
|
{
|
||||||
// provide a single `NaturalCompare` instance for easy use
|
// provide a single `NaturalCompare` instance for easy use
|
||||||
|
|
|
@ -31,13 +31,9 @@
|
||||||
#define UTILS_STRING_H
|
#define UTILS_STRING_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <QtGlobal>
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
|
||||||
#include <QCollator>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class QString;
|
|
||||||
class QByteArray;
|
class QByteArray;
|
||||||
|
class QString;
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
|
@ -51,18 +47,6 @@ namespace Utils
|
||||||
// Taken from https://crackstation.net/hashing-security.htm
|
// Taken from https://crackstation.net/hashing-security.htm
|
||||||
bool slowEquals(const QByteArray &a, const QByteArray &b);
|
bool slowEquals(const QByteArray &a, const QByteArray &b);
|
||||||
|
|
||||||
class NaturalCompare
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NaturalCompare();
|
|
||||||
bool operator()(const QString &left, const QString &right);
|
|
||||||
bool lessThan(const QString &left, const QString &right);
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
|
||||||
private:
|
|
||||||
QCollator m_collator;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
bool naturalCompare(const QString &left, const QString &right);
|
bool naturalCompare(const QString &left, const QString &right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue