mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-21 16:07:23 -06:00
Avoid redundant string length function calls
Also switch to `std::string_view` as it is more generic and can handle more types (including view types). PR #21861.
This commit is contained in:
@@ -60,7 +60,6 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QStorageInfo>
|
||||
|
||||
#include "base/global.h"
|
||||
#include "base/path.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,14 +49,14 @@ QString Utils::String::fromDouble(const double n, const int precision)
|
||||
return QLocale::system().toString(std::floor(n * prec) / prec, 'f', precision);
|
||||
}
|
||||
|
||||
QString Utils::String::fromLatin1(const std::string &string)
|
||||
QString Utils::String::fromLatin1(const std::string_view string)
|
||||
{
|
||||
return QString::fromLatin1(string.c_str(), string.size());
|
||||
return QString::fromLatin1(string.data(), string.size());
|
||||
}
|
||||
|
||||
QString Utils::String::fromLocal8Bit(const std::string &string)
|
||||
QString Utils::String::fromLocal8Bit(const std::string_view string)
|
||||
{
|
||||
return QString::fromLocal8Bit(string.c_str(), string.size());
|
||||
return QString::fromLocal8Bit(string.data(), string.size());
|
||||
}
|
||||
|
||||
QString Utils::String::wildcardToRegexPattern(const QString &pattern)
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <numeric>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include <QChar>
|
||||
#include <QMetaEnum>
|
||||
@@ -66,8 +67,8 @@ namespace Utils::String
|
||||
QStringList splitCommand(const QString &command);
|
||||
|
||||
QString fromDouble(double n, int precision);
|
||||
QString fromLatin1(const std::string &string);
|
||||
QString fromLocal8Bit(const std::string &string);
|
||||
QString fromLatin1(std::string_view string);
|
||||
QString fromLocal8Bit(std::string_view string);
|
||||
|
||||
template <typename Container>
|
||||
QString joinIntoString(const Container &container, const QString &separator)
|
||||
|
||||
Reference in New Issue
Block a user