summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-05-27 12:15:19 +0200
committerLars Knoll <lars.knoll@qt.io>2020-06-12 15:51:11 +0200
commit413a9f9bde60af2633c858435436891c8511385b (patch)
tree0161904d587c6da62da52706c4cc9f3ad779433f
parentd6b74761342bd3cc317ba5cfbca138be087fea2e (diff)
Port remaining usages of QStringRef in QtCore to QStringView
Task-number: QTBUG-84319 Change-Id: If77bc94c18e8d522b4577050091cd7d7aa941311 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/io/qloggingregistry.cpp2
-rw-r--r--src/corelib/io/qresource.cpp2
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp4
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp2
-rw-r--r--src/corelib/kernel/qtranslator.cpp4
-rw-r--r--src/corelib/plugin/qlibrary.cpp6
-rw-r--r--src/corelib/plugin/qpluginloader.cpp4
-rw-r--r--src/corelib/tools/qcommandlineparser.cpp2
-rw-r--r--src/corelib/tools/qhash.cpp12
-rw-r--r--src/corelib/tools/qhashfunctions.h8
10 files changed, 18 insertions, 28 deletions
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp
index cacebfbda6..d40f312fc4 100644
--- a/src/corelib/io/qloggingregistry.cpp
+++ b/src/corelib/io/qloggingregistry.cpp
@@ -190,7 +190,7 @@ void QLoggingRule::parse(QStringView pattern)
void QLoggingSettingsParser::setContent(const QString &content)
{
_rules.clear();
- const auto lines = content.splitRef(QLatin1Char('\n'));
+ const auto lines = QStringView{content}.split(QLatin1Char('\n'));
for (const auto &line : lines)
parseNextLine(line);
}
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index dfaae20c34..9324261939 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -388,7 +388,7 @@ QResourcePrivate::ensureInitialized() const
if(!that->absoluteFilePath.startsWith(QLatin1Char(':')))
that->absoluteFilePath.prepend(QLatin1Char(':'));
- QStringRef path(&fileName);
+ QStringView path(fileName);
if(path.startsWith(QLatin1Char(':')))
path = path.mid(1);
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index ec37ce7d76..ca2a2689f1 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -283,10 +283,10 @@ static QStringList xdgDataDirs()
dirs.append(QString::fromLatin1("/usr/local/share"));
dirs.append(QString::fromLatin1("/usr/share"));
} else {
- const auto parts = xdgDataDirsEnv.splitRef(QLatin1Char(':'), Qt::SkipEmptyParts);
+ const auto parts = QStringView{xdgDataDirsEnv}.split(QLatin1Char(':'), Qt::SkipEmptyParts);
// Normalize paths, skip relative paths
- for (const QStringRef &dir : parts) {
+ for (const auto &dir : parts) {
if (dir.startsWith(QLatin1Char('/')))
dirs.push_back(QDir::cleanPath(dir.toString()));
}
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index 698c4ddf41..e38f495213 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -766,7 +766,7 @@ static QString decodeFsEncString(const QString &str)
if (str.at(i) == QLatin1Char('\\') &&
str.at(i+1) == QLatin1Char('x')) {
bool bOk;
- const int code = str.midRef(i+2, 2).toInt(&bOk, 16);
+ const int code = QStringView{str}.mid(i+2, 2).toInt(&bOk, 16);
// only decode characters between 0x20 and 0x7f but not
// the backslash to prevent collisions
if (bOk && code >= 0x20 && code < 0x80 && code != '\\') {
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index 844df2275d..d9c10151e8 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -490,7 +490,7 @@ bool QTranslator::load(const QString & filename, const QString & directory,
}
const QString suffixOrDotQM = suffix.isNull() ? dotQmLiteral() : suffix;
- QStringRef fname(&filename);
+ QStringView fname(filename);
QString realname;
const QString delims = search_delimiters.isNull() ? QStringLiteral("_.") : search_delimiters;
@@ -680,7 +680,7 @@ static QString find_translation(const QLocale & locale,
// start guessing
for (const QString &fuzzyLocale : qAsConst(fuzzyLocales)) {
- QStringRef localeName(&fuzzyLocale);
+ QStringView localeName(fuzzyLocale);
for (;;) {
int rightmost = localeName.lastIndexOf(QLatin1Char('_'));
// no truncations? fail
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index e512ff2c32..b66eb3e993 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -667,7 +667,7 @@ bool QLibrary::isLibrary(const QString &fileName)
QString completeSuffix = QFileInfo(fileName).completeSuffix();
if (completeSuffix.isEmpty())
return false;
- const QVector<QStringRef> suffixes = completeSuffix.splitRef(QLatin1Char('.'));
+ const auto suffixes = QStringView{completeSuffix}.split(QLatin1Char('.'));
QStringList validSuffixList;
# if defined(Q_OS_HPUX)
@@ -702,12 +702,12 @@ bool QLibrary::isLibrary(const QString &fileName)
int suffix;
int suffixPos = -1;
for (suffix = 0; suffix < validSuffixList.count() && suffixPos == -1; ++suffix)
- suffixPos = suffixes.indexOf(QStringRef(&validSuffixList.at(suffix)));
+ suffixPos = suffixes.indexOf(validSuffixList.at(suffix));
bool valid = suffixPos != -1;
for (int i = suffixPos + 1; i < suffixes.count() && valid; ++i)
if (i != suffixPos)
- suffixes.at(i).toInt(&valid);
+ (void)suffixes.at(i).toInt(&valid);
return valid;
#endif
}
diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp
index 0a63b93762..2ae6913868 100644
--- a/src/corelib/plugin/qpluginloader.cpp
+++ b/src/corelib/plugin/qpluginloader.cpp
@@ -293,8 +293,8 @@ static QString locatePlugin(const QString& fileName)
// Split up "subdir/filename"
const int slash = fileName.lastIndexOf(QLatin1Char('/'));
- const QStringRef baseName = fileName.midRef(slash + 1);
- const QStringRef basePath = isAbsolute ? QStringRef() : fileName.leftRef(slash + 1); // keep the '/'
+ const auto baseName = QStringView{fileName}.mid(slash + 1);
+ const auto basePath = isAbsolute ? QStringView() : QStringView{fileName}.left(slash + 1); // keep the '/'
const bool debug = qt_debug_component();
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp
index ed4171fe4d..9dec2e1474 100644
--- a/src/corelib/tools/qcommandlineparser.cpp
+++ b/src/corelib/tools/qcommandlineparser.cpp
@@ -1103,7 +1103,7 @@ static QString wrapText(const QString &names, int optionNameMaxWidth, const QStr
const int numChars = breakAt - lineStart;
//qDebug() << "breakAt=" << description.at(breakAt) << "breakAtSpace=" << breakAtSpace << lineStart << "to" << breakAt << description.mid(lineStart, numChars);
text += indentation + nextNameSection().leftJustified(optionNameMaxWidth) + QLatin1Char(' ');
- text += description.midRef(lineStart, numChars) + nl;
+ text += QStringView{description}.mid(lineStart, numChars) + nl;
x = 0;
lastBreakable = -1;
lineStart = nextLineStart;
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index b1ebd29f09..f52d46a9e8 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -400,18 +400,6 @@ size_t qHash(const QByteArray &key, size_t seed) noexcept
return qHashBits(key.constData(), size_t(key.size()), seed);
}
-#if QT_STRINGVIEW_LEVEL < 2
-size_t qHash(const QString &key, size_t seed) noexcept
-{
- return qHashBits(key.unicode(), size_t(key.size())*sizeof(QChar), seed);
-}
-
-size_t qHash(const QStringRef &key, size_t seed) noexcept
-{
- return qHashBits(key.unicode(), size_t(key.size())*sizeof(QChar), seed);
-}
-#endif
-
size_t qHash(QStringView key, size_t seed) noexcept
{
return qHashBits(key.data(), key.size()*sizeof(QChar), seed);
diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h
index 38e799e78b..b48a665383 100644
--- a/src/corelib/tools/qhashfunctions.h
+++ b/src/corelib/tools/qhashfunctions.h
@@ -155,11 +155,13 @@ Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(std::nullptr_t, size_t seed
// (some) Qt types
Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(const QChar key, size_t seed = 0) noexcept { return qHash(key.unicode(), seed); }
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray &key, size_t seed = 0) noexcept;
+Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QStringView key, size_t seed = 0) noexcept;
#if QT_STRINGVIEW_LEVEL < 2
-Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QString &key, size_t seed = 0) noexcept;
-Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QStringRef &key, size_t seed = 0) noexcept;
+inline Q_DECL_PURE_FUNCTION size_t qHash(const QString &key, size_t seed = 0) noexcept
+{ return qHash(QStringView{key}, seed); }
+inline Q_DECL_PURE_FUNCTION size_t qHash(const QStringRef &key, size_t seed = 0) noexcept
+{ return qHash(QStringView{key}, seed); }
#endif
-Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QStringView key, size_t seed = 0) noexcept;
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QBitArray &key, size_t seed = 0) noexcept;
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QLatin1String key, size_t seed = 0) noexcept;
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) noexcept;