diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-09 16:34:49 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-25 19:16:29 +0100 |
commit | 753a08ae0e1204b148cf3935f87349eefe75d338 (patch) | |
tree | 193ff5b6a131bba519336c31727d708ddab43032 /src/corelib/plugin | |
parent | 1fefff6d1f99dbcf1a453424753ad5562fb675ef (diff) |
QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where applicable
As a drive-by, did also minor refactorings/improvements.
Task-number: QTBUG-98434
Change-Id: I81964176ae2f07ea63674c96f47f9c6aa046854f
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r-- | src/corelib/plugin/qcoffpeparser.cpp | 9 | ||||
-rw-r--r-- | src/corelib/plugin/qelfparser_p.cpp | 4 | ||||
-rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 16 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary.cpp | 24 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary_unix.cpp | 42 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary_win.cpp | 8 | ||||
-rw-r--r-- | src/corelib/plugin/qmachparser.cpp | 5 | ||||
-rw-r--r-- | src/corelib/plugin/qpluginloader.cpp | 8 | ||||
-rw-r--r-- | src/corelib/plugin/qsystemlibrary.cpp | 10 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 2 |
10 files changed, 73 insertions, 55 deletions
diff --git a/src/corelib/plugin/qcoffpeparser.cpp b/src/corelib/plugin/qcoffpeparser.cpp index 15d1f64426..1ebca08c32 100644 --- a/src/corelib/plugin/qcoffpeparser.cpp +++ b/src/corelib/plugin/qcoffpeparser.cpp @@ -49,14 +49,15 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // Whether we include some extra validity checks // (checks to ensure we don't read out-of-bounds are always included) static constexpr bool IncludeValidityChecks = true; -static constexpr char rawSectionName[] = ".qtmetadata"; -static constexpr QLatin1String metadataSectionName(rawSectionName, sizeof(rawSectionName) - 1); +static constexpr inline auto metadataSectionName() noexcept { return ".qtmetadata"_L1; } static constexpr QLatin1String truncatedSectionName = - metadataSectionName.left(sizeof(IMAGE_SECTION_HEADER::Name)); + metadataSectionName().left(sizeof(IMAGE_SECTION_HEADER::Name)); #ifdef QT_BUILD_INTERNAL # define QCOFFPEPARSER_DEBUG @@ -389,7 +390,7 @@ QLibraryScanResult QCoffPeParser::parse(QByteArrayView data, QString *errMsg) continue; // if we do have a string table, the name may be complete - if (sectionName != truncatedSectionName && sectionName != metadataSectionName) + if (sectionName != truncatedSectionName && sectionName != metadataSectionName()) continue; peDebug << "found .qtmetadata section"; diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp index c6ccda92fb..f51b6915bc 100644 --- a/src/corelib/plugin/qelfparser_p.cpp +++ b/src/corelib/plugin/qelfparser_p.cpp @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // ### Qt7: propagate the constant and eliminate dead code static constexpr bool ElfNotesAreMandatory = QT_VERSION >= QT_VERSION_CHECK(7,0,0); @@ -717,7 +719,7 @@ static QLibraryScanResult scanSections(QByteArrayView data, const ErrorMaker &er return error(QLibrary::tr("section contents extend past the end of the file")); } - if (name != QLatin1String(".qtmetadata")) + if (name != ".qtmetadata"_L1) continue; qEDebug << "found .qtmetadata section"; if (shdr->sh_size < sizeof(QPluginMetaData::MagicHeader)) diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index 8fa510aaea..97cc04e645 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -70,6 +70,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + bool QPluginParsedMetaData::parse(QByteArrayView raw) { QPluginMetaData::Header header; @@ -187,14 +189,14 @@ inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path) #if defined(Q_OS_WIN) QStringList(QStringLiteral("*.dll")), #elif defined(Q_OS_ANDROID) - QStringList(QLatin1String("libplugins_%1_*.so").arg(suffix)), + QStringList("libplugins_%1_*.so"_L1.arg(suffix)), #endif QDir::Files); while (plugins.hasNext()) { QString fileName = plugins.next(); #ifdef Q_OS_MAC - const bool isDebugPlugin = fileName.endsWith(QLatin1String("_debug.dylib")); + const bool isDebugPlugin = fileName.endsWith("_debug.dylib"_L1); const bool isDebugLibrary = #ifdef QT_DEBUG true; @@ -207,7 +209,7 @@ inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path) if (isDebugPlugin != isDebugLibrary) continue; #elif defined(Q_PROCESSOR_X86) - if (fileName.endsWith(QLatin1String(".avx2")) || fileName.endsWith(QLatin1String(".avx512"))) { + if (fileName.endsWith(".avx2"_L1) || fileName.endsWith(".avx512"_L1)) { // ignore AVX2-optimized file, we'll do a bait-and-switch to it later continue; } @@ -232,7 +234,7 @@ inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path) QCborMap object = library->metaData.value(QtPluginMetaDataKeys::MetaData).toMap(); metaDataOk = true; - const QCborArray k = object.value(QLatin1String("Keys")).toArray(); + const QCborArray k = object.value("Keys"_L1).toArray(); for (QCborValueConstRef v : k) keys += cs ? v.toString() : v.toString().toLower(); } @@ -332,7 +334,7 @@ QFactoryLoader::QFactoryLoader(const char *iid, d->cs = cs; d->suffix = suffix; # ifdef Q_OS_ANDROID - if (!d->suffix.isEmpty() && d->suffix.at(0) == QLatin1Char('/')) + if (!d->suffix.isEmpty() && d->suffix.at(0) == u'/') d->suffix.remove(0, 1); # endif @@ -434,7 +436,7 @@ QMultiMap<int, QString> QFactoryLoader::keyMap() const const QList<QPluginParsedMetaData> metaDataList = metaData(); for (int i = 0; i < metaDataList.size(); ++i) { const QCborMap metaData = metaDataList.at(i).value(QtPluginMetaDataKeys::MetaData).toMap(); - const QCborArray keys = metaData.value(QLatin1String("Keys")).toArray(); + const QCborArray keys = metaData.value("Keys"_L1).toArray(); for (QCborValueConstRef key : keys) result.insert(i, key.toString()); } @@ -446,7 +448,7 @@ int QFactoryLoader::indexOf(const QString &needle) const const QList<QPluginParsedMetaData> metaDataList = metaData(); for (int i = 0; i < metaDataList.size(); ++i) { const QCborMap metaData = metaDataList.at(i).value(QtPluginMetaDataKeys::MetaData).toMap(); - const QCborArray keys = metaData.value(QLatin1String("Keys")).toArray(); + const QCborArray keys = metaData.value("Keys"_L1).toArray(); for (QCborValueConstRef key : keys) { if (key.toString().compare(needle, Qt::CaseInsensitive) == 0) return i; diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index fbeddf0bb0..1fdc05afeb 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -68,6 +68,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // On Unix systema and on Windows with MinGW, we can mix and match debug and // release plugins without problems. (unless compiled in debug-and-release mode // - why?) @@ -628,11 +630,11 @@ QtPluginInstanceFunction QLibraryPrivate::loadPlugin() bool QLibrary::isLibrary(const QString &fileName) { #if defined(Q_OS_WIN) - return fileName.endsWith(QLatin1String(".dll"), Qt::CaseInsensitive); + return fileName.endsWith(".dll"_L1, Qt::CaseInsensitive); #else // Generic Unix # if defined(Q_OS_DARWIN) // On Apple platforms, dylib look like libmylib.1.0.0.dylib - if (fileName.endsWith(QLatin1String(".dylib"))) + if (fileName.endsWith(".dylib"_L1)) return true; # endif QString completeSuffix = QFileInfo(fileName).completeSuffix(); @@ -647,18 +649,18 @@ bool QLibrary::isLibrary(const QString &fileName) "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit), the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." */ - QLatin1String("sl"), + "sl"_L1, # if defined __ia64 - QLatin1String("so"), + "so"_L1, # endif # elif defined(Q_OS_AIX) - QLatin1String("a"), - QLatin1String("so"), + "a"_L1, + "so"_L1, # elif defined(Q_OS_DARWIN) - QLatin1String("so"), - QLatin1String("bundle"), + "so"_L1, + "bundle"_L1, # elif defined(Q_OS_UNIX) - QLatin1String("so"), + "so"_L1, # endif }; // candidates @@ -741,7 +743,7 @@ void QLibraryPrivate::updatePluginState() bool success = false; #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) - if (fileName.endsWith(QLatin1String(".debug"))) { + if (fileName.endsWith(".debug"_L1)) { // refuse to load a file that ends in .debug // these are the debug symbols from the libraries // the problem is that they are valid shared library files @@ -789,7 +791,7 @@ void QLibraryPrivate::updatePluginState() QString::number((qt_version & 0xff0000) >> 16), QString::number((qt_version & 0xff00) >> 8), QString::number(qt_version & 0xff), - debug ? QLatin1String("debug") : QLatin1String("release")); + debug ? "debug"_L1 : "release"_L1); } else if (PluginMustMatchQtDebug && debug != QtBuildIsDebug) { //don't issue a qWarning since we will hopefully find a non-debug? --Sam errorString = QLibrary::tr("The plugin '%1' uses incompatible Qt library." diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index 17248c8b3f..1fcc22c8cc 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -59,10 +59,12 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static QString qdlerror() { const char *err = dlerror(); - return err ? QLatin1Char('(') + QString::fromLocal8Bit(err) + QLatin1Char(')') : QString(); + return err ? u'(' + QString::fromLocal8Bit(err) + u')' : QString(); } QStringList QLibraryPrivate::suffixes_sys(const QString &fullVersion) @@ -82,25 +84,25 @@ QStringList QLibraryPrivate::suffixes_sys(const QString &fullVersion) // .so is preferred. # if defined(__ia64) if (!fullVersion.isEmpty()) { - suffixes << QLatin1String(".so.%1").arg(fullVersion); + suffixes << ".so.%1"_L1.arg(fullVersion); } else { - suffixes << QLatin1String(".so"); + suffixes << ".so"_L1; } # endif if (!fullVersion.isEmpty()) { - suffixes << QLatin1String(".sl.%1").arg(fullVersion); - suffixes << QLatin1String(".%1").arg(fullVersion); + suffixes << ".sl.%1"_L1.arg(fullVersion); + suffixes << ".%1"_L1.arg(fullVersion); } else { - suffixes << QLatin1String(".sl"); + suffixes << ".sl"_L1; } #elif defined(Q_OS_AIX) suffixes << ".a"; #else if (!fullVersion.isEmpty()) { - suffixes << QLatin1String(".so.%1").arg(fullVersion); + suffixes << ".so.%1"_L1.arg(fullVersion); } else { - suffixes << QLatin1String(".so"); + suffixes << ".so"_L1; # ifdef Q_OS_ANDROID suffixes << QStringLiteral(LIBS_SUFFIX); # endif @@ -108,10 +110,10 @@ QStringList QLibraryPrivate::suffixes_sys(const QString &fullVersion) #endif # ifdef Q_OS_MAC if (!fullVersion.isEmpty()) { - suffixes << QLatin1String(".%1.bundle").arg(fullVersion); - suffixes << QLatin1String(".%1.dylib").arg(fullVersion); + suffixes << ".%1.bundle"_L1.arg(fullVersion); + suffixes << ".%1.dylib"_L1.arg(fullVersion); } else { - suffixes << QLatin1String(".bundle") << QLatin1String(".dylib"); + suffixes << ".bundle"_L1 << ".dylib"_L1; } #endif return suffixes; @@ -119,7 +121,7 @@ QStringList QLibraryPrivate::suffixes_sys(const QString &fullVersion) QStringList QLibraryPrivate::prefixes_sys() { - return QStringList() << QLatin1String("lib"); + return QStringList() << "lib"_L1; } bool QLibraryPrivate::load_sys() @@ -130,10 +132,10 @@ bool QLibraryPrivate::load_sys() QString path = fsEntry.path(); QString name = fsEntry.fileName(); - if (path == QLatin1String(".") && !fileName.startsWith(path)) + if (path == "."_L1 && !fileName.startsWith(path)) path.clear(); else - path += QLatin1Char('/'); + path += u'/'; QStringList suffixes; QStringList prefixes; @@ -207,10 +209,10 @@ bool QLibraryPrivate::load_sys() }; if (pluginState == IsAPlugin) { // add ".avx2" to each suffix in the list - transform(suffixes, [](QString *s) { s->append(QLatin1String(".avx2")); }); + transform(suffixes, [](QString *s) { s->append(".avx2"_L1); }); } else { // prepend "haswell/" to each prefix in the list - transform(prefixes, [](QString *s) { s->prepend(QLatin1String("haswell/")); }); + transform(prefixes, [](QString *s) { s->prepend("haswell/"_L1); }); } } #endif @@ -222,13 +224,13 @@ bool QLibraryPrivate::load_sys() for (int suffix = 0; retry && !hnd && suffix < suffixes.size(); suffix++) { if (!prefixes.at(prefix).isEmpty() && name.startsWith(prefixes.at(prefix))) continue; - if (path.isEmpty() && prefixes.at(prefix).contains(QLatin1Char('/'))) + if (path.isEmpty() && prefixes.at(prefix).contains(u'/')) continue; if (!suffixes.at(suffix).isEmpty() && name.endsWith(suffixes.at(suffix))) continue; if (loadHints & QLibrary::LoadArchiveMemberHint) { attempt = name; - int lparen = attempt.indexOf(QLatin1Char('(')); + int lparen = attempt.indexOf(u'('); if (lparen == -1) lparen = attempt.size(); attempt = path + prefixes.at(prefix) + attempt.insert(lparen, suffixes.at(suffix)); @@ -240,7 +242,7 @@ bool QLibraryPrivate::load_sys() #ifdef Q_OS_ANDROID if (!hnd) { auto attemptFromBundle = attempt; - hnd = dlopen(QFile::encodeName(attemptFromBundle.replace(QLatin1Char('/'), QLatin1Char('_'))), dlFlags); + hnd = dlopen(QFile::encodeName(attemptFromBundle.replace(u'/', u'_')), dlFlags); } if (hnd) { using JniOnLoadPtr = jint (*)(JavaVM *vm, void *reserved); @@ -252,7 +254,7 @@ bool QLibraryPrivate::load_sys() } #endif - if (!hnd && fileName.startsWith(QLatin1Char('/')) && QFile::exists(attempt)) { + if (!hnd && fileName.startsWith(u'/') && QFile::exists(attempt)) { // We only want to continue if dlopen failed due to that the shared library did not exist. // However, we are only able to apply this check for absolute filenames (since they are // not influenced by the content of LD_LIBRARY_PATH, /etc/ld.so.cache, DT_RPATH etc...) diff --git a/src/corelib/plugin/qlibrary_win.cpp b/src/corelib/plugin/qlibrary_win.cpp index eab7255a7a..9e3a90002d 100644 --- a/src/corelib/plugin/qlibrary_win.cpp +++ b/src/corelib/plugin/qlibrary_win.cpp @@ -49,6 +49,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + extern QString qt_error_string(int code); QStringList QLibraryPrivate::suffixes_sys(const QString& fullVersion) @@ -81,7 +83,7 @@ bool QLibraryPrivate::load_sys() QStringList attempts; if (pluginState != IsAPlugin) - attempts.append(fileName + QLatin1String(".dll")); + attempts.append(fileName + ".dll"_L1); // If the fileName is an absolute path we try that first, otherwise we // use the system-specific suffix first @@ -115,9 +117,9 @@ bool QLibraryPrivate::load_sys() ::GetModuleFileName(hnd, buffer, MAX_PATH); QString moduleFileName = QString::fromWCharArray(buffer); - moduleFileName.remove(0, 1 + moduleFileName.lastIndexOf(QLatin1Char('\\'))); + moduleFileName.remove(0, 1 + moduleFileName.lastIndexOf(u'\\')); const QDir dir(fsEntry.path()); - if (dir.path() == QLatin1String(".")) + if (dir.path() == "."_L1) qualifiedFileName = moduleFileName; else qualifiedFileName = dir.filePath(moduleFileName); diff --git a/src/corelib/plugin/qmachparser.cpp b/src/corelib/plugin/qmachparser.cpp index 310d8e06c3..f8545316fc 100644 --- a/src/corelib/plugin/qmachparser.cpp +++ b/src/corelib/plugin/qmachparser.cpp @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // Whether we include some extra validity checks // (checks to ensure we don't read out-of-bounds are always included) static constexpr bool IncludeValidityChecks = true; @@ -143,7 +145,8 @@ QLibraryScanResult QMachOParser::parse(const char *m_s, ulong fdlen, QString *e // check magic if (header->magic != my_magic) - return notfound(QLibrary::tr("invalid magic %1").arg(qFromBigEndian(header->magic), 8, 16, QLatin1Char('0')), + return notfound(QLibrary::tr("invalid magic %1").arg(qFromBigEndian(header->magic), + 8, 16, '0'_L1), errorString); } diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp index eaca077c90..6dd5150539 100644 --- a/src/corelib/plugin/qpluginloader.cpp +++ b/src/corelib/plugin/qpluginloader.cpp @@ -53,6 +53,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #if QT_CONFIG(library) /*! @@ -269,7 +271,7 @@ static QString locatePlugin(const QString& fileName) suffixes.prepend(QString()); // Split up "subdir/filename" - const int slash = fileName.lastIndexOf(QLatin1Char('/')); + const int slash = fileName.lastIndexOf(u'/'); const auto baseName = QStringView{fileName}.mid(slash + 1); const auto basePath = isAbsolute ? QStringView() : QStringView{fileName}.left(slash + 1); // keep the '/' @@ -286,13 +288,13 @@ static QString locatePlugin(const QString& fileName) #ifdef Q_OS_ANDROID { QString pluginPath = basePath + prefix + baseName + suffix; - const QString fn = path + QLatin1String("/lib") + pluginPath.replace(QLatin1Char('/'), QLatin1Char('_')); + const QString fn = path + "/lib"_L1 + pluginPath.replace(u'/', u'_'); qCDebug(qt_lcDebugPlugins) << "Trying..." << fn; if (QFileInfo(fn).isFile()) return fn; } #endif - const QString fn = path + QLatin1Char('/') + basePath + prefix + baseName + suffix; + const QString fn = path + u'/' + basePath + prefix + baseName + suffix; qCDebug(qt_lcDebugPlugins) << "Trying..." << fn; if (QFileInfo(fn).isFile()) return fn; diff --git a/src/corelib/plugin/qsystemlibrary.cpp b/src/corelib/plugin/qsystemlibrary.cpp index 593b0c3be7..956af50f5c 100644 --- a/src/corelib/plugin/qsystemlibrary.cpp +++ b/src/corelib/plugin/qsystemlibrary.cpp @@ -72,6 +72,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #if !defined(QT_BOOTSTRAPPED) extern QString qAppFileName(); #endif @@ -101,16 +103,16 @@ HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirect if (!onlySystemDirectory) { const QString PATH(QLatin1String(qgetenv("PATH").constData())); - searchOrder << PATH.split(QLatin1Char(';'), Qt::SkipEmptyParts); + searchOrder << PATH.split(u';', Qt::SkipEmptyParts); } QString fileName = QString::fromWCharArray(libraryName); - fileName.append(QLatin1String(".dll")); + fileName.append(".dll"_L1); // Start looking in the order specified for (int i = 0; i < searchOrder.count(); ++i) { QString fullPathAttempt = searchOrder.at(i); - if (!fullPathAttempt.endsWith(QLatin1Char('\\'))) { - fullPathAttempt.append(QLatin1Char('\\')); + if (!fullPathAttempt.endsWith(u'\\')) { + fullPathAttempt.append(u'\\'); } fullPathAttempt.append(fileName); HINSTANCE inst = ::LoadLibrary(reinterpret_cast<const wchar_t *>(fullPathAttempt.utf16())); diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 7f7d537fe4..7d9bd65f8b 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -419,7 +419,7 @@ static QUuid uuidFromString(QStringView text) noexcept static QUuid uuidFromString(QLatin1String text) noexcept { if (Q_UNLIKELY(text.size() < MaxStringUuidLength - 2 - || (text.front() == QLatin1Char('{') && text.size() < MaxStringUuidLength - 1))) { + || (text.front() == '{' && text.size() < MaxStringUuidLength - 1))) { // Too short. Don't call _q_uuidFromHex(); QL1Ss need not be NUL-terminated, // and we don't want to read trailing garbage as potentially valid data. text = QLatin1String(); |