mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 08:48:07 -06:00
@@ -152,21 +152,6 @@ bool Utils::String::naturalCompareCaseInsensitive(const QString &left, const QSt
|
||||
#endif
|
||||
}
|
||||
|
||||
QString Utils::String::fromStdString(const std::string &str)
|
||||
{
|
||||
return QString::fromUtf8(str.c_str());
|
||||
}
|
||||
|
||||
std::string Utils::String::toStdString(const QString &str)
|
||||
{
|
||||
#ifdef QBT_USES_QT5
|
||||
return str.toStdString();
|
||||
#else
|
||||
QByteArray utf8 = str.toUtf8();
|
||||
return std::string(utf8.constData(), utf8.length());
|
||||
#endif
|
||||
}
|
||||
|
||||
// to send numbers instead of strings with suffixes
|
||||
QString Utils::String::fromDouble(double n, int precision)
|
||||
{
|
||||
@@ -193,29 +178,3 @@ bool Utils::String::slowEquals(const QByteArray &a, const QByteArray &b)
|
||||
|
||||
return (diff == 0);
|
||||
}
|
||||
|
||||
QString Utils::String::toHtmlEscaped(const QString &str)
|
||||
{
|
||||
#ifdef QBT_USES_QT5
|
||||
return str.toHtmlEscaped();
|
||||
#else
|
||||
// code from Qt
|
||||
QString rich;
|
||||
const int len = str.length();
|
||||
rich.reserve(int(len * 1.1));
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (str.at(i) == QLatin1Char('<'))
|
||||
rich += QLatin1String("<");
|
||||
else if (str.at(i) == QLatin1Char('>'))
|
||||
rich += QLatin1String(">");
|
||||
else if (str.at(i) == QLatin1Char('&'))
|
||||
rich += QLatin1String("&");
|
||||
else if (str.at(i) == QLatin1Char('"'))
|
||||
rich += QLatin1String(""");
|
||||
else
|
||||
rich += str.at(i);
|
||||
}
|
||||
rich.squeeze();
|
||||
return rich;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -39,16 +39,12 @@ namespace Utils
|
||||
{
|
||||
namespace String
|
||||
{
|
||||
QString fromStdString(const std::string &str);
|
||||
std::string toStdString(const QString &str);
|
||||
QString fromDouble(double n, int precision);
|
||||
|
||||
// Implements constant-time comparison to protect against timing attacks
|
||||
// Taken from https://crackstation.net/hashing-security.htm
|
||||
bool slowEquals(const QByteArray &a, const QByteArray &b);
|
||||
|
||||
QString toHtmlEscaped(const QString &str);
|
||||
|
||||
bool naturalCompareCaseSensitive(const QString &left, const QString &right);
|
||||
bool naturalCompareCaseInsensitive(const QString &left, const QString &right);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user