From 399d3ad85a539344baa9a5afc233824ef1a2842a Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Mon, 1 Mar 2021 09:40:30 +0300 Subject: [PATCH] Replace QStringRef with QStringView --- src/app/application.cpp | 4 +-- src/base/bittorrent/peeraddress.cpp | 12 +++---- src/base/bittorrent/peeraddress.h | 2 +- src/base/bittorrent/session.cpp | 2 +- src/base/bittorrent/torrentimpl.cpp | 6 ++-- src/base/bittorrent/torrentinfo.cpp | 2 +- src/base/http/connection.cpp | 12 +++---- src/base/http/requestparser.cpp | 18 +++++----- src/base/http/requestparser.h | 2 +- src/base/rss/rss_autodownloadrule.cpp | 2 +- src/base/search/searchdownloadhandler.cpp | 2 +- src/base/search/searchhandler.cpp | 4 +-- src/base/search/searchhandler.h | 2 +- src/base/utils/bytearray.h | 4 +-- src/base/utils/compare.cpp | 8 ++--- src/base/utils/misc.cpp | 2 +- src/base/utils/string.cpp | 4 +-- src/base/utils/string.h | 4 +-- src/gui/downloadfromurldialog.cpp | 8 ++--- src/gui/fspathedit_p.cpp | 34 ++++++++----------- src/gui/fspathedit_p.h | 5 ++- src/gui/mainwindow.cpp | 7 ++-- src/gui/properties/trackersadditiondialog.cpp | 2 +- src/gui/torrentcontentmodel.cpp | 10 +++--- src/gui/trackerentriesdialog.cpp | 4 +-- src/webui/webapplication.cpp | 10 +++--- 26 files changed, 82 insertions(+), 90 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 1bd586755..e87485751 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -561,7 +561,7 @@ void Application::processParams(const QStringList ¶ms) if (param.startsWith(QLatin1String("@addPaused="))) { - torrentParams.addPaused = (param.midRef(11).toInt() != 0); + torrentParams.addPaused = (QStringView(param).mid(11).toInt() != 0); continue; } @@ -591,7 +591,7 @@ void Application::processParams(const QStringList ¶ms) if (param.startsWith(QLatin1String("@skipDialog="))) { - skipTorrentDialog = (param.midRef(12).toInt() != 0); + skipTorrentDialog = (QStringView(param).mid(12).toInt() != 0); continue; } diff --git a/src/base/bittorrent/peeraddress.cpp b/src/base/bittorrent/peeraddress.cpp index 79ba90ee9..ebe73d637 100644 --- a/src/base/bittorrent/peeraddress.cpp +++ b/src/base/bittorrent/peeraddress.cpp @@ -32,18 +32,18 @@ using namespace BitTorrent; -PeerAddress PeerAddress::parse(const QString &address) +PeerAddress PeerAddress::parse(const QStringView address) { - QVector ipPort; + QList ipPort; - if (address.startsWith('[') && address.contains("]:")) + if (address.startsWith(u'[') && address.contains(QLatin1String("]:"))) { // IPv6 - ipPort = address.splitRef("]:"); + ipPort = address.split(QString::fromLatin1("]:")); ipPort[0] = ipPort[0].mid(1); // chop '[' } - else if (address.contains(':')) + else if (address.contains(u':')) { // IPv4 - ipPort = address.splitRef(':'); + ipPort = address.split(u':'); } else { diff --git a/src/base/bittorrent/peeraddress.h b/src/base/bittorrent/peeraddress.h index 142cf048f..3d7e5b391 100644 --- a/src/base/bittorrent/peeraddress.h +++ b/src/base/bittorrent/peeraddress.h @@ -39,7 +39,7 @@ namespace BitTorrent QHostAddress ip; ushort port = 0; - static PeerAddress parse(const QString &address); + static PeerAddress parse(QStringView address); QString toString() const; }; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index f2a58f6db..aebb53d54 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1590,7 +1590,7 @@ void Session::populateAdditionalTrackers() m_additionalTrackerList.clear(); const QString trackers = additionalTrackers(); - for (QStringRef tracker : asConst(trackers.splitRef('\n'))) + for (QStringView tracker : asConst(QStringView(trackers).split(u'\n'))) { tracker = tracker.trimmed(); if (!tracker.isEmpty()) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index a697bb30e..99e52d4dc 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1866,9 +1866,9 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p) if (m_oldPath[p->index].isEmpty()) m_oldPath.remove(p->index); - QVector oldPathParts = oldFilePath.splitRef('/', Qt::SkipEmptyParts); + QList oldPathParts = QStringView(oldFilePath).split('/', Qt::SkipEmptyParts); oldPathParts.removeLast(); // drop file name part - QVector newPathParts = newFilePath.splitRef('/', Qt::SkipEmptyParts); + QList newPathParts = QStringView(newFilePath).split('/', Qt::SkipEmptyParts); newPathParts.removeLast(); // drop file name part #if defined(Q_OS_WIN) @@ -1887,7 +1887,7 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p) for (int i = (oldPathParts.size() - 1); i >= pathIdx; --i) { - QDir().rmdir(savePath() + Utils::String::join(oldPathParts, QLatin1String("/"))); + QDir().rmdir(savePath() + Utils::String::join(oldPathParts, QString::fromLatin1("/"))); oldPathParts.removeLast(); } diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 00e18de6c..e1805026f 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -61,7 +61,7 @@ namespace { if (QDir::isAbsolutePath(filePath)) continue; - const auto filePathElements = filePath.splitRef('/'); + const auto filePathElements = QStringView(filePath).split(u'/'); // if at least one file has no root folder, no common root folder exists if (filePathElements.count() <= 1) return {}; diff --git a/src/base/http/connection.cpp b/src/base/http/connection.cpp index a27b68a1f..0dc5a8b98 100644 --- a/src/base/http/connection.cpp +++ b/src/base/http/connection.cpp @@ -137,9 +137,9 @@ bool Connection::acceptsGzipEncoding(QString codings) { // [rfc7231] 5.3.4. Accept-Encoding - const auto isCodingAvailable = [](const QVector &list, const QString &encoding) -> bool + const auto isCodingAvailable = [](const QList &list, const QStringView encoding) -> bool { - for (const QStringRef &str : list) + for (const QStringView &str : list) { if (!str.startsWith(encoding)) continue; @@ -149,7 +149,7 @@ bool Connection::acceptsGzipEncoding(QString codings) return true; // [rfc7231] 5.3.1. Quality Values - const QStringRef substr = str.mid(encoding.size() + 3); // ex. skip over "gzip;q=" + const QStringView substr = str.mid(encoding.size() + 3); // ex. skip over "gzip;q=" bool ok = false; const double qvalue = substr.toDouble(&ok); @@ -161,15 +161,15 @@ bool Connection::acceptsGzipEncoding(QString codings) return false; }; - const QVector list = codings.remove(' ').remove('\t').splitRef(',', Qt::SkipEmptyParts); + const QList list = QStringView(codings.remove(' ').remove('\t')).split(u',', Qt::SkipEmptyParts); if (list.isEmpty()) return false; - const bool canGzip = isCodingAvailable(list, QLatin1String("gzip")); + const bool canGzip = isCodingAvailable(list, QString::fromLatin1("gzip")); if (canGzip) return true; - const bool canAny = isCodingAvailable(list, QLatin1String("*")); + const bool canAny = isCodingAvailable(list, QString::fromLatin1("*")); if (canAny) return true; diff --git a/src/base/http/requestparser.cpp b/src/base/http/requestparser.cpp index 284783c3f..7f8af9a66 100644 --- a/src/base/http/requestparser.cpp +++ b/src/base/http/requestparser.cpp @@ -57,7 +57,7 @@ namespace return in; } - bool parseHeaderLine(const QString &line, HeaderMap &out) + bool parseHeaderLine(const QStringView line, HeaderMap &out) { // [rfc7230] 3.2. Header Fields const int i = line.indexOf(':'); @@ -67,8 +67,8 @@ namespace return false; } - const QString name = line.leftRef(i).trimmed().toString().toLower(); - const QString value = line.midRef(i + 1).trimmed().toString(); + const QString name = line.left(i).trimmed().toString().toLower(); + const QString value = line.mid(i + 1).trimmed().toString(); out[name] = value; return true; @@ -145,10 +145,10 @@ RequestParser::ParseResult RequestParser::doParse(const QByteArray &data) return {ParseStatus::BadRequest, Request(), 0}; // TODO: SHOULD respond "501 Not Implemented" } -bool RequestParser::parseStartLines(const QString &data) +bool RequestParser::parseStartLines(const QStringView data) { // we don't handle malformed request which uses `LF` for newline - const QVector lines = data.splitRef(CRLF, Qt::SkipEmptyParts); + const QList lines = data.split(QString::fromLatin1(CRLF), Qt::SkipEmptyParts); // [rfc7230] 3.2.2. Field Order QStringList requestLines; @@ -267,7 +267,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data) return false; } - const QByteArray delimiter = Utils::String::unquote(contentType.midRef(idx + boundaryFieldName.size())).toLatin1(); + const QByteArray delimiter = Utils::String::unquote(QStringView(contentType).mid(idx + boundaryFieldName.size())).toLatin1(); if (delimiter.isEmpty()) { qWarning() << Q_FUNC_INFO << "boundary delimiter field empty!"; @@ -311,13 +311,13 @@ bool RequestParser::parseFormData(const QByteArray &data) const QByteArray payload = viewWithoutEndingWith(list[1], CRLF); HeaderMap headersMap; - const QVector headerLines = headers.splitRef(CRLF, Qt::SkipEmptyParts); + const QList headerLines = QStringView(headers).split(QString::fromLatin1(CRLF), Qt::SkipEmptyParts); for (const auto &line : headerLines) { - if (line.trimmed().startsWith(HEADER_CONTENT_DISPOSITION, Qt::CaseInsensitive)) + if (line.trimmed().startsWith(QString::fromLatin1(HEADER_CONTENT_DISPOSITION), Qt::CaseInsensitive)) { // extract out filename & name - const QVector directives = line.split(';', Qt::SkipEmptyParts); + const QList directives = line.split(u';', Qt::SkipEmptyParts); for (const auto &directive : directives) { diff --git a/src/base/http/requestparser.h b/src/base/http/requestparser.h index cf510165e..b9eb7cdfa 100644 --- a/src/base/http/requestparser.h +++ b/src/base/http/requestparser.h @@ -60,7 +60,7 @@ namespace Http RequestParser(); ParseResult doParse(const QByteArray &data); - bool parseStartLines(const QString &data); + bool parseStartLines(QStringView data); bool parseRequestLine(const QString &line); bool parsePostMessage(const QByteArray &data); diff --git a/src/base/rss/rss_autodownloadrule.cpp b/src/base/rss/rss_autodownloadrule.cpp index 3c701ba91..ecc6b08fd 100644 --- a/src/base/rss/rss_autodownloadrule.cpp +++ b/src/base/rss/rss_autodownloadrule.cpp @@ -325,7 +325,7 @@ bool AutoDownloadRule::matchesEpisodeFilterExpression(const QString &articleTitl if (episode.endsWith('-')) { // Infinite range - const int episodeOurs {episode.leftRef(episode.size() - 1).toInt()}; + const int episodeOurs {QStringView(episode).left(episode.size() - 1).toInt()}; if (((seasonTheirs == seasonOurs) && (episodeTheirs >= episodeOurs)) || (seasonTheirs > seasonOurs)) return true; } diff --git a/src/base/search/searchdownloadhandler.cpp b/src/base/search/searchdownloadhandler.cpp index 8fd823c0d..2d781ff7a 100644 --- a/src/base/search/searchdownloadhandler.cpp +++ b/src/base/search/searchdownloadhandler.cpp @@ -59,7 +59,7 @@ void SearchDownloadHandler::downloadProcessFinished(int exitcode) if ((exitcode == 0) && (m_downloadProcess->exitStatus() == QProcess::NormalExit)) { const QString line = QString::fromUtf8(m_downloadProcess->readAllStandardOutput()).trimmed(); - const QVector parts = line.splitRef(' '); + const QList parts = QStringView(line).split(u' '); if (parts.size() == 2) path = parts[0].toString(); } diff --git a/src/base/search/searchhandler.cpp b/src/base/search/searchhandler.cpp index 6438f0cc9..7aec0d84d 100644 --- a/src/base/search/searchhandler.cpp +++ b/src/base/search/searchhandler.cpp @@ -163,9 +163,9 @@ void SearchHandler::processFailed() // Parse one line of search results list // Line is in the following form: // file url | file name | file size | nb seeds | nb leechers | Search engine url -bool SearchHandler::parseSearchResult(const QString &line, SearchResult &searchResult) +bool SearchHandler::parseSearchResult(const QStringView line, SearchResult &searchResult) { - const QVector parts = line.splitRef('|'); + const QList parts = line.split(u'|'); const int nbFields = parts.size(); if (nbFields < (NB_PLUGIN_COLUMNS - 1)) return false; // -1 because desc_link is optional diff --git a/src/base/search/searchhandler.h b/src/base/search/searchhandler.h index 981dae502..2f42b1bca 100644 --- a/src/base/search/searchhandler.h +++ b/src/base/search/searchhandler.h @@ -78,7 +78,7 @@ private: void readSearchOutput(); void processFailed(); void processFinished(int exitcode); - bool parseSearchResult(const QString &line, SearchResult &searchResult); + bool parseSearchResult(QStringView line, SearchResult &searchResult); const QString m_pattern; const QString m_category; diff --git a/src/base/utils/bytearray.h b/src/base/utils/bytearray.h index 2b49f2082..c3d959b4c 100644 --- a/src/base/utils/bytearray.h +++ b/src/base/utils/bytearray.h @@ -28,14 +28,14 @@ #pragma once -#include +#include #include class QByteArray; namespace Utils::ByteArray { - // Mimic QString::splitRef(sep, behavior) + // Mimic QStringView(in).split(sep, behavior) QVector 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, diff --git a/src/base/utils/compare.cpp b/src/base/utils/compare.cpp index 343ff01f5..536dd147c 100644 --- a/src/base/utils/compare.cpp +++ b/src/base/utils/compare.cpp @@ -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()); diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index e560f9e75..71c334d43 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -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() diff --git a/src/base/utils/string.cpp b/src/base/utils/string.cpp index 46b2c4450..6efc1adb1 100644 --- a/src/base/utils/string.cpp +++ b/src/base/utils/string.cpp @@ -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 Utils::String::parseDouble(const QString &string) return std::nullopt; } -QString Utils::String::join(const QVector &strings, const QString &separator) +QString Utils::String::join(const QList &strings, const QStringView separator) { if (strings.empty()) return {}; diff --git a/src/base/utils/string.h b/src/base/utils/string.h index e7ff9919b..e4f3c303b 100644 --- a/src/base/utils/string.h +++ b/src/base/utils/string.h @@ -37,8 +37,6 @@ #include #include -class QStringRef; - namespace Utils::String { QString wildcardToRegexPattern(const QString &pattern); @@ -61,7 +59,7 @@ namespace Utils::String std::optional parseInt(const QString &string); std::optional parseDouble(const QString &string); - QString join(const QVector &strings, const QString &separator); + QString join(const QList &strings, QStringView separator); QString fromDouble(double n, int precision); diff --git a/src/gui/downloadfromurldialog.cpp b/src/gui/downloadfromurldialog.cpp index 1d85a385d..a3f286ac9 100644 --- a/src/gui/downloadfromurldialog.cpp +++ b/src/gui/downloadfromurldialog.cpp @@ -71,10 +71,10 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent) // Paste clipboard if there is an URL in it const QString clipboardText = qApp->clipboard()->text(); - const QVector clipboardList = clipboardText.splitRef('\n'); + const QList clipboardList = QStringView(clipboardText).split(u'\n'); QSet uniqueURLs; - for (QStringRef strRef : clipboardList) + for (QStringView strRef : clipboardList) { strRef = strRef.trimmed(); if (strRef.isEmpty()) continue; @@ -103,10 +103,10 @@ DownloadFromURLDialog::~DownloadFromURLDialog() void DownloadFromURLDialog::downloadButtonClicked() { const QString plainText = m_ui->textUrls->toPlainText(); - const QVector urls = plainText.splitRef('\n'); + const QList urls = QStringView(plainText).split(u'\n'); QSet uniqueURLs; - for (QStringRef url : urls) + for (QStringView url : urls) { url = url.trimmed(); if (url.isEmpty()) continue; diff --git a/src/gui/fspathedit_p.cpp b/src/gui/fspathedit_p.cpp index 1cc63c384..f2c8c294a 100644 --- a/src/gui/fspathedit_p.cpp +++ b/src/gui/fspathedit_p.cpp @@ -107,30 +107,32 @@ QValidator::State Private::FileSystemPathValidator::validate(QString &input, int // we test path components from beginning to the one with cursor location in strict mode // and the one with cursor and beyond in non-strict mode - QVector components = input.splitRef(QDir::separator(), Qt::KeepEmptyParts); + QList components = QStringView(input).split(QDir::separator(), Qt::KeepEmptyParts); // find index of the component that contains pos int componentWithCursorIndex = 0; + int componentWithCursorPosition = 0; int pathLength = 0; // components.size() - 1 because when path ends with QDir::separator(), we will not see the last // character in the components array, yet everything past the one before the last delimiter // belongs to the last component - for (; (componentWithCursorIndex < components.size() - 1) && (pathLength < pos); ++componentWithCursorIndex) + for (; (componentWithCursorIndex < (components.size() - 1)) && (pathLength < pos); ++componentWithCursorIndex) { - pathLength = components[componentWithCursorIndex].position() + components[componentWithCursorIndex].size(); + pathLength = componentWithCursorPosition + components[componentWithCursorIndex].size(); + componentWithCursorPosition += components[componentWithCursorIndex].size() + 1; } Q_ASSERT(componentWithCursorIndex < components.size()); m_lastValidationState = QValidator::Acceptable; if (componentWithCursorIndex > 0) - m_lastValidationState = validate(input, components, m_strictMode, 0, componentWithCursorIndex - 1); + m_lastValidationState = validate(components, m_strictMode, 0, componentWithCursorIndex - 1); if ((m_lastValidationState == QValidator::Acceptable) && (componentWithCursorIndex < components.size())) - m_lastValidationState = validate(input, components, false, componentWithCursorIndex, components.size() - 1); + m_lastValidationState = validate(components, false, componentWithCursorIndex, components.size() - 1); return m_lastValidationState; } -QValidator::State Private::FileSystemPathValidator::validate(const QString &path, const QVector &pathComponents, bool strict, +QValidator::State Private::FileSystemPathValidator::validate(const QList &pathComponents, bool strict, int firstComponentToTest, int lastComponentToTest) const { Q_ASSERT(firstComponentToTest >= 0); @@ -141,12 +143,13 @@ QValidator::State Private::FileSystemPathValidator::validate(const QString &path if (pathComponents.empty()) return strict ? QValidator::Invalid : QValidator::Intermediate; - for (int i = firstComponentToTest; i < lastComponentToTest; ++i) + for (int i = firstComponentToTest; i <= lastComponentToTest; ++i) { - if (pathComponents[i].isEmpty()) continue; + const bool isFinalPath = (i == (pathComponents.size() - 1)); + const QStringView componentPath = pathComponents[i]; + if (componentPath.isEmpty()) continue; - QStringRef componentPath(&path, 0, pathComponents[i].position() + pathComponents[i].size()); - m_lastTestResult = testPath(componentPath, false); + m_lastTestResult = testPath(pathComponents[i], isFinalPath); if (m_lastTestResult != TestResult::OK) { m_lastTestedPath = componentPath.toString(); @@ -154,20 +157,11 @@ QValidator::State Private::FileSystemPathValidator::validate(const QString &path } } - const bool finalPath = (lastComponentToTest == (pathComponents.size() - 1)); - QStringRef componentPath(&path, 0, pathComponents[lastComponentToTest].position() - + pathComponents[lastComponentToTest].size()); - m_lastTestResult = testPath(componentPath, finalPath); - if (m_lastTestResult != TestResult::OK) - { - m_lastTestedPath = componentPath.toString(); - return strict ? QValidator::Invalid : QValidator::Intermediate; - } return QValidator::Acceptable; } Private::FileSystemPathValidator::TestResult -Private::FileSystemPathValidator::testPath(const QStringRef &path, bool pathIsComplete) const +Private::FileSystemPathValidator::testPath(const QStringView path, bool pathIsComplete) const { QFileInfo fi(path.toString()); if (m_existingOnly && !fi.exists()) diff --git a/src/gui/fspathedit_p.h b/src/gui/fspathedit_p.h index a99384fa9..8f443b4d2 100644 --- a/src/gui/fspathedit_p.h +++ b/src/gui/fspathedit_p.h @@ -39,7 +39,6 @@ class QCompleter; class QContextMenuEvent; class QFileSystemModel; class QKeyEvent; -class QStringRef; namespace Private { @@ -82,10 +81,10 @@ namespace Private QString lastTestedPath() const; private: - QValidator::State validate(const QString &path, const QVector &pathComponents, bool strict, + QValidator::State validate(const QList &pathComponents, bool strict, int firstComponentToTest, int lastComponentToTest) const; - TestResult testPath(const QStringRef &path, bool pathIsComplete) const; + TestResult testPath(QStringView path, bool pathIsComplete) const; bool m_strictMode; bool m_existingOnly; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 6210f3fb6..15a7ed5b6 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -2184,8 +2184,9 @@ void MainWindow::pythonDownloadFinished(const Net::DownloadResult &result) QProcess installer; qDebug("Launching Python installer in passive mode..."); - QFile::rename(result.filePath, result.filePath + ".exe"); - installer.start('"' + Utils::Fs::toNativePath(result.filePath) + ".exe\" /passive"); + const QString exePath = result.filePath + QLatin1String(".exe"); + QFile::rename(result.filePath, exePath); + installer.start(Utils::Fs::toNativePath(exePath), {"/passive"}); // Wait for setup to complete installer.waitForFinished(10 * 60 * 1000); @@ -2195,7 +2196,7 @@ void MainWindow::pythonDownloadFinished(const Net::DownloadResult &result) qDebug("Setup should be complete!"); // Delete temp file - Utils::Fs::forceRemove(result.filePath + ".exe"); + Utils::Fs::forceRemove(exePath); // Reload search engine if (Utils::ForeignApps::pythonInfo().isSupportedVersion()) diff --git a/src/gui/properties/trackersadditiondialog.cpp b/src/gui/properties/trackersadditiondialog.cpp index f0f904e54..f9f4557b5 100644 --- a/src/gui/properties/trackersadditiondialog.cpp +++ b/src/gui/properties/trackersadditiondialog.cpp @@ -59,7 +59,7 @@ QStringList TrackersAdditionDialog::newTrackers() const const QString plainText = m_ui->textEditTrackersList->toPlainText(); QStringList cleanTrackers; - for (QStringRef url : asConst(plainText.splitRef('\n'))) + for (QStringView url : asConst(QStringView(plainText).split(u'\n'))) { url = url.trimmed(); if (!url.isEmpty()) diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index c26f2c9bd..ae62ea5f7 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -503,16 +503,16 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info) const QString path = Utils::Fs::toUniformPath(info.filePath(i)); // Iterate of parts of the path to create necessary folders - QVector pathFolders = path.splitRef('/', Qt::SkipEmptyParts); + QList pathFolders = QStringView(path).split(u'/', Qt::SkipEmptyParts); pathFolders.removeLast(); - for (const QStringRef &pathPartRef : asConst(pathFolders)) + for (const QStringView pathPart : asConst(pathFolders)) { - const QString pathPart = pathPartRef.toString(); - TorrentContentModelFolder *newParent = currentParent->childFolderWithName(pathPart); + const QString folderPath = pathPart.toString(); + TorrentContentModelFolder *newParent = currentParent->childFolderWithName(folderPath); if (!newParent) { - newParent = new TorrentContentModelFolder(pathPart, currentParent); + newParent = new TorrentContentModelFolder(folderPath, currentParent); currentParent->appendChild(newParent); } currentParent = newParent; diff --git a/src/gui/trackerentriesdialog.cpp b/src/gui/trackerentriesdialog.cpp index 46bb7fe37..a685449a4 100644 --- a/src/gui/trackerentriesdialog.cpp +++ b/src/gui/trackerentriesdialog.cpp @@ -81,13 +81,13 @@ void TrackerEntriesDialog::setTrackers(const QVector & QVector TrackerEntriesDialog::trackers() const { const QString plainText = m_ui->plainTextEdit->toPlainText(); - const QVector lines = plainText.splitRef('\n'); + const QList lines = QStringView(plainText).split(u'\n'); QVector entries; entries.reserve(lines.size()); int tier = 0; - for (QStringRef line : lines) + for (QStringView line : lines) { line = line.trimmed(); diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index d71531ce4..f471da42e 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -72,11 +72,11 @@ const QString PRIVATE_FOLDER {QStringLiteral("/private")}; namespace { - QStringMap parseCookie(const QString &cookieStr) + QStringMap parseCookie(const QStringView cookieStr) { // [rfc6265] 4.2.1. Syntax QStringMap ret; - const QVector cookies = cookieStr.splitRef(';', Qt::SkipEmptyParts); + const QList cookies = cookieStr.split(u';', Qt::SkipEmptyParts); for (const auto &cookie : cookies) { @@ -386,10 +386,10 @@ void WebApplication::configure() if (pref->isWebUICustomHTTPHeadersEnabled()) { - const QString customHeaders = pref->getWebUICustomHTTPHeaders().trimmed(); - const QVector customHeaderLines = customHeaders.splitRef('\n', Qt::SkipEmptyParts); + const QString customHeaders = pref->getWebUICustomHTTPHeaders(); + const QList customHeaderLines = QStringView(customHeaders).trimmed().split(u'\n', Qt::SkipEmptyParts); - for (const QStringRef &line : customHeaderLines) + for (const QStringView line : customHeaderLines) { const int idx = line.indexOf(':'); if (idx < 0)