mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-02 05:38:06 -06:00
Replace QStringRef with QStringView
This commit is contained in:
@@ -28,14 +28,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <Qt>
|
||||
#include <QtContainerFwd>
|
||||
|
||||
class QByteArray;
|
||||
|
||||
namespace Utils::ByteArray
|
||||
{
|
||||
// Mimic QString::splitRef(sep, behavior)
|
||||
// Mimic QStringView(in).split(sep, behavior)
|
||||
QVector<QByteArray> splitToViews(const QByteArray &in, const QByteArray &sep, const Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
|
||||
|
||||
// Mimic QByteArray::mid(pos, len) but instead of returning a full-copy,
|
||||
|
||||
@@ -60,16 +60,16 @@ int Utils::Compare::naturalCompare(const QString &left, const QString &right, co
|
||||
{
|
||||
// Both are digits, compare the numbers
|
||||
|
||||
const auto numberView = [](const QString &str, int &pos) -> QStringRef
|
||||
const auto numberView = [](const QStringView str, int &pos) -> QStringView
|
||||
{
|
||||
const int start = pos;
|
||||
while ((pos < str.size()) && str[pos].isDigit())
|
||||
++pos;
|
||||
return str.midRef(start, (pos - start));
|
||||
return str.mid(start, (pos - start));
|
||||
};
|
||||
|
||||
const QStringRef numViewL = numberView(left, posL);
|
||||
const QStringRef numViewR = numberView(right, posR);
|
||||
const QStringView numViewL = numberView(left, posL);
|
||||
const QStringView numViewR = numberView(right, posR);
|
||||
|
||||
if (numViewL.length() != numViewR.length())
|
||||
return (numViewL.length() - numViewR.length());
|
||||
|
||||
@@ -498,7 +498,7 @@ QString Utils::Misc::opensslVersionString()
|
||||
#else
|
||||
static const auto version {QString::fromLatin1(SSLeay_version(SSLEAY_VERSION))};
|
||||
#endif
|
||||
return version.splitRef(' ', Qt::SkipEmptyParts)[1].toString();
|
||||
return QStringView(version).split(u' ', Qt::SkipEmptyParts)[1].toString();
|
||||
}
|
||||
|
||||
QString Utils::Misc::zlibVersionString()
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
// to send numbers instead of strings with suffixes
|
||||
QString Utils::String::fromDouble(const double n, const int precision)
|
||||
{
|
||||
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
|
||||
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f', 1) == 99.9
|
||||
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 The problem manifests when
|
||||
** the number has more digits after the decimal than we want AND the digit after
|
||||
** our 'wanted' is >= 5. In this case our last digit gets rounded up. So for each
|
||||
@@ -99,7 +99,7 @@ std::optional<double> Utils::String::parseDouble(const QString &string)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QString Utils::String::join(const QVector<QStringRef> &strings, const QString &separator)
|
||||
QString Utils::String::join(const QList<QStringView> &strings, const QStringView separator)
|
||||
{
|
||||
if (strings.empty())
|
||||
return {};
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
#include <Qt>
|
||||
#include <QtContainerFwd>
|
||||
|
||||
class QStringRef;
|
||||
|
||||
namespace Utils::String
|
||||
{
|
||||
QString wildcardToRegexPattern(const QString &pattern);
|
||||
@@ -61,7 +59,7 @@ namespace Utils::String
|
||||
std::optional<int> parseInt(const QString &string);
|
||||
std::optional<double> parseDouble(const QString &string);
|
||||
|
||||
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
||||
QString join(const QList<QStringView> &strings, QStringView separator);
|
||||
|
||||
QString fromDouble(double n, int precision);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user