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/kernel | |
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/kernel')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 20 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreapplication_win.cpp | 52 | ||||
-rw-r--r-- | src/corelib/kernel/qjniobject.cpp | 4 | ||||
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 6 | ||||
-rw-r--r-- | src/corelib/kernel/qmimedata.cpp | 12 | ||||
-rw-r--r-- | src/corelib/kernel/qsharedmemory.cpp | 24 | ||||
-rw-r--r-- | src/corelib/kernel/qsharedmemory_posix.cpp | 18 | ||||
-rw-r--r-- | src/corelib/kernel/qsharedmemory_systemv.cpp | 24 | ||||
-rw-r--r-- | src/corelib/kernel/qsharedmemory_win.cpp | 14 | ||||
-rw-r--r-- | src/corelib/kernel/qsystemerror.cpp | 8 | ||||
-rw-r--r-- | src/corelib/kernel/qsystemsemaphore_posix.cpp | 16 | ||||
-rw-r--r-- | src/corelib/kernel/qsystemsemaphore_systemv.cpp | 18 | ||||
-rw-r--r-- | src/corelib/kernel/qsystemsemaphore_win.cpp | 8 | ||||
-rw-r--r-- | src/corelib/kernel/qtranslator.cpp | 14 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 6 |
15 files changed, 136 insertions, 108 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index fa0c2486cc..e41c1b6df7 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -138,6 +138,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #if defined(Q_OS_WIN) || defined(Q_OS_MAC) extern QString qAppFileName(); #endif @@ -573,7 +575,7 @@ void QCoreApplicationPrivate::appendApplicationPathToLibraryPaths() if (!app_libpaths) coreappdata()->app_libpaths.reset(app_libpaths = new QStringList); QString app_location = QCoreApplication::applicationFilePath(); - app_location.truncate(app_location.lastIndexOf(QLatin1Char('/'))); + app_location.truncate(app_location.lastIndexOf(u'/')); app_location = QDir(app_location).canonicalPath(); if (QFile::exists(app_location) && !app_libpaths->contains(app_location)) app_libpaths->append(app_location); @@ -2181,20 +2183,20 @@ static void replacePercentN(QString *result, int n) if (n >= 0) { int percentPos = 0; int len = 0; - while ((percentPos = result->indexOf(QLatin1Char('%'), percentPos + len)) != -1) { + while ((percentPos = result->indexOf(u'%', percentPos + len)) != -1) { len = 1; if (percentPos + len == result->length()) break; QString fmt; - if (result->at(percentPos + len) == QLatin1Char('L')) { + if (result->at(percentPos + len) == u'L') { ++len; if (percentPos + len == result->length()) break; - fmt = QLatin1String("%L1"); + fmt = "%L1"_L1; } else { - fmt = QLatin1String("%1"); + fmt = "%1"_L1; } - if (result->at(percentPos + len) == QLatin1Char('n')) { + if (result->at(percentPos + len) == u'n') { fmt = fmt.arg(n); ++len; result->replace(percentPos, len, fmt); @@ -2290,7 +2292,7 @@ QString QCoreApplication::translate(const char *context, const char *sourceText, Q_UNUSED(disambiguation); QString ret = QString::fromUtf8(sourceText); if (n >= 0) - ret.replace(QLatin1String("%n"), QString::number(n)); + ret.replace("%n"_L1, QString::number(n)); return ret; } @@ -2406,13 +2408,13 @@ QString QCoreApplication::applicationFilePath() if (absPath.isEmpty() && !arguments().isEmpty()) { QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit()); - if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) { + if (!argv0.isEmpty() && argv0.at(0) == u'/') { /* If argv0 starts with a slash, it is already an absolute file path. */ absPath = argv0; - } else if (argv0.contains(QLatin1Char('/'))) { + } else if (argv0.contains(u'/')) { /* If argv0 contains one or more slashes, it is a file path relative to the current directory. diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 87d8af90bb..03559d90ae 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -55,6 +55,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_CORE_EXPORT QString qAppFileName() // get application file name { /* @@ -172,7 +174,7 @@ static QString flagsValue(const QWinMessageMapping<IntType> *haystack, for (auto p = haystack, end = haystack + haystackSize; p < end; ++p) { if ((p->value & value) == p->value) { if (!result.isEmpty()) - result += QLatin1String(" | "); + result += " | "_L1; result += QLatin1String(p->name); } } @@ -664,8 +666,8 @@ QString decodeMSG(const MSG& msg) // decoded message, since some of the common messages are quite long, and // we don't want the decoded information to vary in output position if (message.size() < 20) - message.prepend(QString(20 - message.size(), QLatin1Char(' '))); - message += QLatin1String(": "); + message.prepend(QString(20 - message.size(), u' ')); + message += ": "_L1; const QString hwndS = QString::asprintf("(%p)", reinterpret_cast<void *>(msg.hwnd)); const QString wParamS = QString::asprintf("(%p)", reinterpret_cast<void *>(wParam)); @@ -676,10 +678,10 @@ QString decodeMSG(const MSG& msg) case WM_ACTIVATE: if (const char *a = activateParameter(uint(wParam))) parameters += QLatin1String(a); - parameters += QLatin1String(" Hwnd ") + hwndS; + parameters += " Hwnd "_L1 + hwndS; break; case WM_CAPTURECHANGED: - parameters = QLatin1String("Hwnd gaining capture ") + hwndS; + parameters = "Hwnd gaining capture "_L1 + hwndS; break; case WM_CREATE: { @@ -704,7 +706,7 @@ QString decodeMSG(const MSG& msg) } break; case WM_DESTROY: - parameters = QLatin1String("Destroy hwnd ") + hwndS; + parameters = "Destroy hwnd "_L1 + hwndS; break; case 0x02E0u: { // WM_DPICHANGED auto rect = reinterpret_cast<const RECT *>(lParam); @@ -715,20 +717,20 @@ QString decodeMSG(const MSG& msg) break; case WM_IME_NOTIFY: { - parameters = QLatin1String("Command("); + parameters = "Command("_L1; if (const char *c = imeCommand(uint(wParam))) parameters += QLatin1String(c); - parameters += QLatin1String(" : ") + lParamS; + parameters += " : "_L1 + lParamS; } break; case WM_IME_SETCONTEXT: - parameters = QLatin1String("Input context(") - + QLatin1String(wParam == TRUE ? "Active" : "Inactive") - + QLatin1String(") Show flags(") - + imeShowFlags(DWORD(lParam)) + QLatin1Char(')'); + parameters = "Input context("_L1 + + (wParam ? "Active"_L1 : "Inactive"_L1) + + ") Show flags("_L1 + + imeShowFlags(DWORD(lParam)) + u')'; break; case WM_KILLFOCUS: - parameters = QLatin1String("Hwnd gaining keyboard focus ") + wParamS; + parameters = "Hwnd gaining keyboard focus "_L1 + wParamS; break; case WM_CHAR: case WM_IME_CHAR: @@ -751,7 +753,7 @@ QString decodeMSG(const MSG& msg) parameters = QStringLiteral("Keyboard layout changed"); break; case WM_NCACTIVATE: - parameters = (msg.wParam? QLatin1String("Active Titlebar") : QLatin1String("Inactive Titlebar")); + parameters = (msg.wParam? "Active Titlebar"_L1 : "Inactive Titlebar"_L1); break; case WM_MOUSEACTIVATE: { @@ -778,14 +780,14 @@ QString decodeMSG(const MSG& msg) case WM_MOUSEMOVE: parameters = QString::asprintf("x,y(%4d,%4d) Virtual Keys(", GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)) - + virtualKeys(uint(wParam)) + QLatin1Char(')'); + + virtualKeys(uint(wParam)) + u')'; break; case WM_MOVE: parameters = QString::asprintf("x,y(%4d,%4d)", LOWORD(lParam), HIWORD(lParam)); break; case WM_ERASEBKGND: case WM_PAINT: - parameters = QLatin1String("hdc") + wParamS; + parameters = "hdc"_L1 + wParamS; break; case WM_QUERYNEWPALETTE: break; // lParam & wParam are unused @@ -793,22 +795,22 @@ QString decodeMSG(const MSG& msg) parameters = QString::asprintf("HitTestCode(0x%x) MouseMsg(", LOWORD(lParam)); if (const char *mouseMsg = findWMstr(HIWORD(lParam))) parameters += QLatin1String(mouseMsg); - parameters += QLatin1Char(')'); + parameters += u')'; break; case WM_SETFOCUS: - parameters = QLatin1String("Lost Focus ") + wParamS; + parameters = "Lost Focus "_L1 + wParamS; break; case WM_SETTEXT: - parameters = QLatin1String("Set Text (") + parameters = "Set Text ("_L1 + QString::fromWCharArray(reinterpret_cast<const wchar_t *>(lParam)) - + QLatin1Char(')'); + + u')'; break; case WM_SIZE: parameters = QString::asprintf("w,h(%4d,%4d) showmode(", LOWORD(lParam), HIWORD(lParam)); if (const char *showMode = wmSizeParam(uint(wParam))) parameters += QLatin1String(showMode); - parameters += QLatin1Char(')'); + parameters += u')'; break; case WM_WINDOWPOSCHANGED: { @@ -823,20 +825,20 @@ QString decodeMSG(const MSG& msg) parameters += QLatin1String(h); else parameters += QString::number(insertAfter, 16); - parameters += QLatin1Char(')'); + parameters += u')'; } break; case WM_QUERYENDSESSION: - parameters = QLatin1String("End session: "); + parameters = "End session: "_L1; if (const char *logoffOption = sessionMgrLogOffOption(uint(wParam))) parameters += QLatin1String(logoffOption); break; default: - parameters = QLatin1String("wParam") + wParamS + QLatin1String(" lParam") + lParamS; + parameters = "wParam"_L1 + wParamS + " lParam"_L1 + lParamS; break; } - return message + QLatin1String("hwnd") + hwndS + QLatin1Char(' ') + parameters; + return message + "hwnd"_L1 + hwndS + u' ' + parameters; } QDebug operator<<(QDebug dbg, const MSG &msg) diff --git a/src/corelib/kernel/qjniobject.cpp b/src/corelib/kernel/qjniobject.cpp index dfb0dbd36d..1057f5fb59 100644 --- a/src/corelib/kernel/qjniobject.cpp +++ b/src/corelib/kernel/qjniobject.cpp @@ -47,6 +47,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QJniObject \inmodule QtCore @@ -317,7 +319,7 @@ public: static inline QLatin1String keyBase() { - return QLatin1String("%1%2:%3"); + return "%1%2:%3"_L1; } static QString qt_convertJString(jstring string) diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 274f8d104b..b55b630b04 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -66,6 +66,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QMetaObject \inmodule QtCore @@ -2837,7 +2839,7 @@ static auto parse_scope(QLatin1String qualifiedKey) noexcept std::optional<QLatin1String> scope; QLatin1String key; }; - const auto scopePos = qualifiedKey.lastIndexOf(QLatin1String("::")); + const auto scopePos = qualifiedKey.lastIndexOf("::"_L1); if (scopePos < 0) return R{std::nullopt, qualifiedKey}; else @@ -2871,7 +2873,7 @@ int QMetaEnum::keysToValue(const char *keys, bool *ok) const auto className = [&] { return stringDataView(mobj, priv(mobj->d.data)->className); }; int value = 0; - for (const QLatin1String &untrimmed : qTokenize(QLatin1String{keys}, QLatin1Char{'|'})) { + for (const QLatin1String &untrimmed : qTokenize(QLatin1String{keys}, u'|')) { const auto parsed = parse_scope(untrimmed.trimmed()); if (parsed.scope && *parsed.scope != className()) return -1; // wrong type name in qualified name diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp index 6a0a4d6ed1..7d00ea1061 100644 --- a/src/corelib/kernel/qmimedata.cpp +++ b/src/corelib/kernel/qmimedata.cpp @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static inline QString textUriListLiteral() { return QStringLiteral("text/uri-list"); } static inline QString textHtmlLiteral() { return QStringLiteral("text/html"); } static inline QString textPlainLiteral() { return QStringLiteral("text/plain"); } @@ -118,7 +120,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QMetaType ty QVariant data = q->retrieveData(format, type); // Text data requested: fallback to URL data if available - if (format == QLatin1String("text/plain") && !data.isValid()) { + if (format == "text/plain"_L1 && !data.isValid()) { data = retrieveTypedData(textUriListLiteral(), QMetaType(QMetaType::QVariantList)); if (data.metaType().id() == QMetaType::QUrl) { data = QVariant(data.toUrl().toDisplayString()); @@ -128,7 +130,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QMetaType ty const QList<QVariant> list = data.toList(); for (int i = 0; i < list.size(); ++i) { if (list.at(i).metaType().id() == QMetaType::QUrl) { - text += list.at(i).toUrl().toDisplayString() + QLatin1Char('\n'); + text += list.at(i).toUrl().toDisplayString() + u'\n'; ++numUrls; } } @@ -158,7 +160,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QMetaType ty switch (typeId) { case QMetaType::QString: { const QByteArray ba = data.toByteArray(); - if (format == QLatin1String("text/html")) { + if (format == "text/html"_L1) { auto encoding = QStringConverter::encodingForHtml(ba); if (encoding) { QStringDecoder toUtf16(*encoding); @@ -176,7 +178,7 @@ QT_WARNING_POP return newData; } case QMetaType::QVariantList: { - if (format != QLatin1String("text/uri-list")) + if (format != "text/uri-list"_L1) break; Q_FALLTHROUGH(); } @@ -594,7 +596,7 @@ void QMimeData::setData(const QString &mimeType, const QByteArray &data) { Q_D(QMimeData); - if (mimeType == QLatin1String("text/uri-list")) { + if (mimeType == "text/uri-list"_L1) { QByteArray ba = data; if (ba.endsWith('\0')) ba.chop(1); diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index 3dbbe75fc4..ba8bf5eca3 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #if !(defined(QT_NO_SHAREDMEMORY) && defined(QT_NO_SYSTEMSEMAPHORE)) /*! \internal @@ -90,14 +92,14 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, // so we can't use the logic below of combining the prefix, key, and a hash, // to ensure a unique and valid name. Instead we use the first part of the // hash, which should still long enough to avoid collisions in practice. - return QLatin1Char('/') + hex.left(SHM_NAME_MAX - 1); + return u'/' + hex.left(SHM_NAME_MAX - 1); } #endif QString result = prefix; for (QChar ch : key) { - if ((ch >= QLatin1Char('a') && ch <= QLatin1Char('z')) || - (ch >= QLatin1Char('A') && ch <= QLatin1Char('Z'))) + if ((ch >= u'a' && ch <= u'z') || + (ch >= u'A' && ch <= u'Z')) result += ch; } result.append(QLatin1String(hex)); @@ -105,9 +107,9 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, #ifdef Q_OS_WIN return result; #elif defined(QT_POSIX_IPC) - return QLatin1Char('/') + result; + return u'/' + result; #else - return QDir::tempPath() + QLatin1Char('/') + result; + return QDir::tempPath() + u'/' + result; #endif } #endif // QT_NO_SHAREDMEMORY && QT_NO_SHAREDMEMORY @@ -321,7 +323,7 @@ bool QSharedMemoryPrivate::initKey() systemSemaphore.setKey(QString(), 1); systemSemaphore.setKey(key, 1); if (systemSemaphore.error() != QSystemSemaphore::NoError) { - QString function = QLatin1String("QSharedMemoryPrivate::initKey"); + QString function = "QSharedMemoryPrivate::initKey"_L1; errorString = QSharedMemory::tr("%1: unable to set key on lock").arg(function); switch(systemSemaphore.error()) { case QSystemSemaphore::PermissionDenied: @@ -412,7 +414,7 @@ bool QSharedMemory::create(qsizetype size, AccessMode mode) #endif #endif - QString function = QLatin1String("QSharedMemory::create"); + QString function = "QSharedMemory::create"_L1; #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); if (!d->key.isNull() && !d->tryLocker(&lock, function)) @@ -479,7 +481,7 @@ bool QSharedMemory::attach(AccessMode mode) return false; #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::attach"))) + if (!d->key.isNull() && !d->tryLocker(&lock, "QSharedMemory::attach"_L1)) return false; #endif @@ -519,7 +521,7 @@ bool QSharedMemory::detach() #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::detach"))) + if (!d->key.isNull() && !d->tryLocker(&lock, "QSharedMemory::detach"_L1)) return false; #endif @@ -588,7 +590,7 @@ bool QSharedMemory::lock() d->lockedByMe = true; return true; } - QString function = QLatin1String("QSharedMemory::lock"); + const auto function = "QSharedMemory::lock"_L1; d->errorString = QSharedMemory::tr("%1: unable to lock").arg(function); d->error = QSharedMemory::LockError; return false; @@ -610,7 +612,7 @@ bool QSharedMemory::unlock() d->lockedByMe = false; if (d->systemSemaphore.release()) return true; - QString function = QLatin1String("QSharedMemory::unlock"); + const auto function = "QSharedMemory::unlock"_L1; d->errorString = QSharedMemory::tr("%1: unable to unlock").arg(function); d->error = QSharedMemory::LockError; return false; diff --git a/src/corelib/kernel/qsharedmemory_posix.cpp b/src/corelib/kernel/qsharedmemory_posix.cpp index 9406e200be..713339d345 100644 --- a/src/corelib/kernel/qsharedmemory_posix.cpp +++ b/src/corelib/kernel/qsharedmemory_posix.cpp @@ -61,12 +61,14 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + int QSharedMemoryPrivate::handle() { // don't allow making handles on empty keys const QString safeKey = makePlatformSafeKey(key); if (safeKey.isEmpty()) { - errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle")); + errorString = QSharedMemory::tr("%1: key is empty").arg("QSharedMemory::handle"_L1); error = QSharedMemory::KeyError; return 0; } @@ -100,7 +102,7 @@ bool QSharedMemoryPrivate::create(qsizetype size) #endif if (fd == -1) { const int errorNumber = errno; - const QLatin1String function("QSharedMemory::attach (shm_open)"); + const auto function = "QSharedMemory::attach (shm_open)"_L1; switch (errorNumber) { case EINVAL: errorString = QSharedMemory::tr("%1: bad name").arg(function); @@ -116,7 +118,7 @@ bool QSharedMemoryPrivate::create(qsizetype size) int ret; EINTR_LOOP(ret, QT_FTRUNCATE(fd, size)); if (ret == -1) { - setErrorString(QLatin1String("QSharedMemory::create (ftruncate)")); + setErrorString("QSharedMemory::create (ftruncate)"_L1); qt_safe_close(fd); return false; } @@ -143,7 +145,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) #endif if (hand == -1) { const int errorNumber = errno; - const QLatin1String function("QSharedMemory::attach (shm_open)"); + const auto function = "QSharedMemory::attach (shm_open)"_L1; switch (errorNumber) { case EINVAL: errorString = QSharedMemory::tr("%1: bad name").arg(function); @@ -159,7 +161,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) // grab the size QT_STATBUF st; if (QT_FSTAT(hand, &st) == -1) { - setErrorString(QLatin1String("QSharedMemory::attach (fstat)")); + setErrorString("QSharedMemory::attach (fstat)"_L1); cleanHandle(); return false; } @@ -169,7 +171,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) const int mprot = (mode == QSharedMemory::ReadOnly ? PROT_READ : PROT_READ | PROT_WRITE); memory = QT_MMAP(0, size_t(size), mprot, MAP_SHARED, hand, 0); if (memory == MAP_FAILED || !memory) { - setErrorString(QLatin1String("QSharedMemory::attach (mmap)")); + setErrorString("QSharedMemory::attach (mmap)"_L1); cleanHandle(); memory = 0; size = 0; @@ -190,7 +192,7 @@ bool QSharedMemoryPrivate::detach() { // detach from the memory segment if (::munmap(memory, size_t(size)) == -1) { - setErrorString(QLatin1String("QSharedMemory::detach (munmap)")); + setErrorString("QSharedMemory::detach (munmap)"_L1); return false; } memory = 0; @@ -216,7 +218,7 @@ bool QSharedMemoryPrivate::detach() if (shm_nattch == 0) { const QByteArray shmName = QFile::encodeName(makePlatformSafeKey(key)); if (::shm_unlink(shmName.constData()) == -1 && errno != ENOENT) - setErrorString(QLatin1String("QSharedMemory::detach (shm_unlink)")); + setErrorString("QSharedMemory::detach (shm_unlink)"_L1); } #else // On non-QNX systems (tested Linux and Haiku), the st_nlink field is always 1, diff --git a/src/corelib/kernel/qsharedmemory_systemv.cpp b/src/corelib/kernel/qsharedmemory_systemv.cpp index 65ad23b9f6..04bc700fdf 100644 --- a/src/corelib/kernel/qsharedmemory_systemv.cpp +++ b/src/corelib/kernel/qsharedmemory_systemv.cpp @@ -63,6 +63,8 @@ #ifndef QT_NO_SHAREDMEMORY QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \internal @@ -76,21 +78,21 @@ key_t QSharedMemoryPrivate::handle() // don't allow making handles on empty keys if (nativeKey.isEmpty()) { - errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle:")); + errorString = QSharedMemory::tr("%1: key is empty").arg("QSharedMemory::handle:"_L1); error = QSharedMemory::KeyError; return 0; } // ftok requires that an actual file exists somewhere if (!QFile::exists(nativeKey)) { - errorString = QSharedMemory::tr("%1: UNIX key file doesn't exist").arg(QLatin1String("QSharedMemory::handle:")); + errorString = QSharedMemory::tr("%1: UNIX key file doesn't exist").arg("QSharedMemory::handle:"_L1); error = QSharedMemory::NotFound; return 0; } unix_key = ftok(QFile::encodeName(nativeKey).constData(), 'Q'); if (-1 == unix_key) { - errorString = QSharedMemory::tr("%1: ftok failed").arg(QLatin1String("QSharedMemory::handle:")); + errorString = QSharedMemory::tr("%1: ftok failed").arg("QSharedMemory::handle:"_L1); error = QSharedMemory::KeyError; unix_key = 0; } @@ -138,7 +140,7 @@ bool QSharedMemoryPrivate::create(qsizetype size) bool createdFile = false; int built = createUnixKeyFile(nativeKey); if (built == -1) { - errorString = QSharedMemory::tr("%1: unable to make key").arg(QLatin1String("QSharedMemory::handle:")); + errorString = QSharedMemory::tr("%1: unable to make key").arg("QSharedMemory::handle:"_L1); error = QSharedMemory::KeyError; return false; } @@ -155,10 +157,10 @@ bool QSharedMemoryPrivate::create(qsizetype size) // create if (-1 == shmget(unix_key, size_t(size), 0600 | IPC_CREAT | IPC_EXCL)) { - const QLatin1String function("QSharedMemory::create"); + const auto function = "QSharedMemory::create"_L1; switch (errno) { case EINVAL: - errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg(QLatin1String("QSharedMemory::handle")); + errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg("QSharedMemory::handle"_L1); error = QSharedMemory::InvalidSize; break; default: @@ -177,7 +179,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) // grab the shared memory segment id int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0400 : 0600)); if (-1 == id) { - setErrorString(QLatin1String("QSharedMemory::attach (shmget)")); + setErrorString("QSharedMemory::attach (shmget)"_L1); return false; } @@ -185,7 +187,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) memory = shmat(id, nullptr, (mode == QSharedMemory::ReadOnly ? SHM_RDONLY : 0)); if ((void *)-1 == memory) { memory = nullptr; - setErrorString(QLatin1String("QSharedMemory::attach (shmat)")); + setErrorString("QSharedMemory::attach (shmat)"_L1); return false; } @@ -194,7 +196,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) if (!shmctl(id, IPC_STAT, &shmid_ds)) { size = (qsizetype)shmid_ds.shm_segsz; } else { - setErrorString(QLatin1String("QSharedMemory::attach (shmctl)")); + setErrorString("QSharedMemory::attach (shmctl)"_L1); return false; } @@ -205,7 +207,7 @@ bool QSharedMemoryPrivate::detach() { // detach from the memory segment if (-1 == shmdt(memory)) { - const QLatin1String function("QSharedMemory::detach"); + const auto function = "QSharedMemory::detach"_L1; switch (errno) { case EINVAL: errorString = QSharedMemory::tr("%1: not attached").arg(function); @@ -236,7 +238,7 @@ bool QSharedMemoryPrivate::detach() if (shmid_ds.shm_nattch == 0) { // mark for removal if (-1 == shmctl(id, IPC_RMID, &shmid_ds)) { - setErrorString(QLatin1String("QSharedMemory::remove")); + setErrorString("QSharedMemory::remove"_L1); switch (errno) { case EINVAL: return true; diff --git a/src/corelib/kernel/qsharedmemory_win.cpp b/src/corelib/kernel/qsharedmemory_win.cpp index 30ae5fb275..920f60b286 100644 --- a/src/corelib/kernel/qsharedmemory_win.cpp +++ b/src/corelib/kernel/qsharedmemory_win.cpp @@ -45,6 +45,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifndef QT_NO_SHAREDMEMORY QSharedMemoryPrivate::QSharedMemoryPrivate() : @@ -95,7 +97,7 @@ void QSharedMemoryPrivate::setErrorString(QLatin1String function) HANDLE QSharedMemoryPrivate::handle() { if (!hand) { - const QLatin1String function("QSharedMemory::handle"); + const auto function = "QSharedMemory::handle"_L1; if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: unable to make key").arg(function); @@ -115,7 +117,7 @@ bool QSharedMemoryPrivate::cleanHandle() { if (hand != 0 && !CloseHandle(hand)) { hand = 0; - setErrorString(QLatin1String("QSharedMemory::cleanHandle")); + setErrorString("QSharedMemory::cleanHandle"_L1); return false; } hand = 0; @@ -124,7 +126,7 @@ bool QSharedMemoryPrivate::cleanHandle() bool QSharedMemoryPrivate::create(qsizetype size) { - const QLatin1String function("QSharedMemory::create"); + const auto function = "QSharedMemory::create"_L1; if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: key error").arg(function); @@ -152,7 +154,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) int permissions = (mode == QSharedMemory::ReadOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS); memory = (void *)MapViewOfFile(handle(), permissions, 0, 0, 0); if (0 == memory) { - setErrorString(QLatin1String("QSharedMemory::attach")); + setErrorString("QSharedMemory::attach"_L1); cleanHandle(); return false; } @@ -163,7 +165,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) // Windows doesn't set an error code on this one, // it should only be a kernel memory error. error = QSharedMemory::UnknownError; - errorString = QSharedMemory::tr("%1: size query failed").arg(QLatin1String("QSharedMemory::attach: ")); + errorString = QSharedMemory::tr("%1: size query failed").arg("QSharedMemory::attach: "_L1); return false; } size = qsizetype(info.RegionSize); @@ -175,7 +177,7 @@ bool QSharedMemoryPrivate::detach() { // umap memory if (!UnmapViewOfFile(memory)) { - setErrorString(QLatin1String("QSharedMemory::detach")); + setErrorString("QSharedMemory::detach"_L1); return false; } memory = 0; diff --git a/src/corelib/kernel/qsystemerror.cpp b/src/corelib/kernel/qsystemerror.cpp index 4be4874cf1..1aea501416 100644 --- a/src/corelib/kernel/qsystemerror.cpp +++ b/src/corelib/kernel/qsystemerror.cpp @@ -52,6 +52,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #if !defined(Q_OS_WIN) && QT_CONFIG(thread) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \ defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L namespace { @@ -92,11 +94,11 @@ static QString windowsErrorString(int errorCode) if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND) ret = QString::fromLatin1("The specified module could not be found."); - if (ret.endsWith(QLatin1String("\r\n"))) + if (ret.endsWith("\r\n"_L1)) ret.chop(2); if (ret.isEmpty()) ret = QString::fromLatin1("Unknown error 0x%1.") - .arg(unsigned(errorCode), 8, 16, QLatin1Char('0')); + .arg(unsigned(errorCode), 8, 16, '0'_L1); return ret; } #endif @@ -152,7 +154,7 @@ QString QSystemError::string(ErrorScope errorScope, int errorCode) qWarning("invalid error scope"); Q_FALLTHROUGH(); case NoError: - return QLatin1String("No error"); + return u"No error"_qs; } } diff --git a/src/corelib/kernel/qsystemsemaphore_posix.cpp b/src/corelib/kernel/qsystemsemaphore_posix.cpp index 567e154e0d..330801a36e 100644 --- a/src/corelib/kernel/qsystemsemaphore_posix.cpp +++ b/src/corelib/kernel/qsystemsemaphore_posix.cpp @@ -64,13 +64,15 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + bool QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) { if (semaphore != SEM_FAILED) return true; // we already have a semaphore if (fileName.isEmpty()) { - errorString = QSystemSemaphore::tr("%1: key is empty").arg(QLatin1String("QSystemSemaphore::handle")); + errorString = QSystemSemaphore::tr("%1: key is empty").arg("QSystemSemaphore::handle"_L1); error = QSystemSemaphore::KeyError; return false; } @@ -86,7 +88,7 @@ bool QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) if (semaphore == SEM_FAILED && errno == EEXIST) { if (mode == QSystemSemaphore::Create) { if (::sem_unlink(semName.constData()) == -1 && errno != ENOENT) { - setErrorString(QLatin1String("QSystemSemaphore::handle (sem_unlink)")); + setErrorString("QSystemSemaphore::handle (sem_unlink)"_L1); return false; } // Race condition: the semaphore might be recreated before @@ -104,7 +106,7 @@ bool QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) } if (semaphore == SEM_FAILED) { - setErrorString(QLatin1String("QSystemSemaphore::handle")); + setErrorString("QSystemSemaphore::handle"_L1); return false; } @@ -117,7 +119,7 @@ void QSystemSemaphorePrivate::cleanHandle() { if (semaphore != SEM_FAILED) { if (::sem_close(semaphore) == -1) { - setErrorString(QLatin1String("QSystemSemaphore::cleanHandle (sem_close)")); + setErrorString("QSystemSemaphore::cleanHandle (sem_close)"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::cleanHandle sem_close failed."); #endif @@ -127,7 +129,7 @@ void QSystemSemaphorePrivate::cleanHandle() if (createdSemaphore) { if (::sem_unlink(QFile::encodeName(fileName).constData()) == -1 && errno != ENOENT) { - setErrorString(QLatin1String("QSystemSemaphore::cleanHandle (sem_unlink)")); + setErrorString("QSystemSemaphore::cleanHandle (sem_unlink)"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::cleanHandle sem_unlink failed."); #endif @@ -145,7 +147,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count) int cnt = count; do { if (::sem_post(semaphore) == -1) { - setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore (sem_post)")); + setErrorString("QSystemSemaphore::modifySemaphore (sem_post)"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::modify sem_post failed %d %d", count, errno); #endif @@ -167,7 +169,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count) semaphore = SEM_FAILED; return modifySemaphore(count); } - setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore (sem_wait)")); + setErrorString("QSystemSemaphore::modifySemaphore (sem_wait)"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::modify sem_wait failed %d %d", count, errno); #endif diff --git a/src/corelib/kernel/qsystemsemaphore_systemv.cpp b/src/corelib/kernel/qsystemsemaphore_systemv.cpp index 1c9fc1f2f7..4d577d11df 100644 --- a/src/corelib/kernel/qsystemsemaphore_systemv.cpp +++ b/src/corelib/kernel/qsystemsemaphore_systemv.cpp @@ -68,6 +68,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \internal @@ -79,7 +81,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) if (qt_apple_isSandboxed()) { errorString = QSystemSemaphore::tr("%1: System V semaphores are not available " \ "for sandboxed applications. Please build Qt with -feature-ipc_posix") - .arg(QLatin1String("QSystemSemaphore::handle:")); + .arg("QSystemSemaphore::handle:"_L1); error = QSystemSemaphore::PermissionDenied; return -1; } @@ -87,7 +89,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) if (key.isEmpty()){ errorString = QSystemSemaphore::tr("%1: key is empty") - .arg(QLatin1String("QSystemSemaphore::handle:")); + .arg("QSystemSemaphore::handle:"_L1); error = QSystemSemaphore::KeyError; return -1; } @@ -100,7 +102,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) int built = QSharedMemoryPrivate::createUnixKeyFile(fileName); if (-1 == built) { errorString = QSystemSemaphore::tr("%1: unable to make key") - .arg(QLatin1String("QSystemSemaphore::handle:")); + .arg("QSystemSemaphore::handle:"_L1); error = QSystemSemaphore::KeyError; return -1; } @@ -112,7 +114,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) #endif if (-1 == unix_key) { errorString = QSystemSemaphore::tr("%1: ftok failed") - .arg(QLatin1String("QSystemSemaphore::handle:")); + .arg("QSystemSemaphore::handle:"_L1); error = QSystemSemaphore::KeyError; return -1; } @@ -123,7 +125,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) if (errno == EEXIST) semaphore = semget(unix_key, 1, 0600 | IPC_CREAT); if (-1 == semaphore) { - setErrorString(QLatin1String("QSystemSemaphore::handle")); + setErrorString("QSystemSemaphore::handle"_L1); cleanHandle(); return -1; } @@ -143,7 +145,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) qt_semun init_op; init_op.val = initialValue; if (-1 == semctl(semaphore, 0, SETVAL, init_op)) { - setErrorString(QLatin1String("QSystemSemaphore::handle")); + setErrorString("QSystemSemaphore::handle"_L1); cleanHandle(); return -1; } @@ -170,7 +172,7 @@ void QSystemSemaphorePrivate::cleanHandle() if (createdSemaphore) { if (-1 != semaphore) { if (-1 == semctl(semaphore, 0, IPC_RMID, 0)) { - setErrorString(QLatin1String("QSystemSemaphore::cleanHandle")); + setErrorString("QSystemSemaphore::cleanHandle"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::cleanHandle semctl failed."); #endif @@ -204,7 +206,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count) handle(); return modifySemaphore(count); } - setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore")); + setErrorString("QSystemSemaphore::modifySemaphore"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::modify failed %d %d %d %d %d", count, int(semctl(semaphore, 0, GETVAL)), int(errno), int(EIDRM), int(EINVAL); diff --git a/src/corelib/kernel/qsystemsemaphore_win.cpp b/src/corelib/kernel/qsystemsemaphore_win.cpp index d19476db4a..96d3ba0679 100644 --- a/src/corelib/kernel/qsystemsemaphore_win.cpp +++ b/src/corelib/kernel/qsystemsemaphore_win.cpp @@ -45,6 +45,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifndef QT_NO_SYSTEMSEMAPHORE QSystemSemaphorePrivate::QSystemSemaphorePrivate() : @@ -88,7 +90,7 @@ HANDLE QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode) semaphore = CreateSemaphore(0, initialValue, MAXLONG, reinterpret_cast<const wchar_t*>(fileName.utf16())); if (semaphore == NULL) - setErrorString(QLatin1String("QSystemSemaphore::handle")); + setErrorString("QSystemSemaphore::handle"_L1); } return semaphore; @@ -111,7 +113,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count) if (count > 0) { if (0 == ReleaseSemaphore(semaphore, count, 0)) { - setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore")); + setErrorString("QSystemSemaphore::modifySemaphore"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::modifySemaphore ReleaseSemaphore failed"); #endif @@ -119,7 +121,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count) } } else { if (WAIT_OBJECT_0 != WaitForSingleObjectEx(semaphore, INFINITE, FALSE)) { - setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore")); + setErrorString("QSystemSemaphore::modifySemaphore"_L1); #if defined QSYSTEMSEMAPHORE_DEBUG qDebug("QSystemSemaphore::modifySemaphore WaitForSingleObject failed"); #endif diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 1d0c613c17..9f0ce2a825 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -485,8 +485,8 @@ bool QTranslator::load(const QString & filename, const QString & directory, QString prefix; if (QFileInfo(filename).isRelative()) { prefix = directory; - if (prefix.length() && !prefix.endsWith(QLatin1Char('/'))) - prefix += QLatin1Char('/'); + if (prefix.length() && !prefix.endsWith(u'/')) + prefix += u'/'; } const QString suffixOrDotQM = suffix.isNull() ? dotQmLiteral() : suffix; @@ -530,7 +530,7 @@ bool QTranslatorPrivate::do_load(const QString &realname, const QString &directo QTranslatorPrivate *d = this; bool ok = false; - if (realname.startsWith(QLatin1Char(':'))) { + if (realname.startsWith(u':')) { // If the translation is in a non-compressed resource file, the data is already in // memory, so no need to use QFile to copy it again. Q_ASSERT(!d->resource); @@ -645,8 +645,8 @@ static QString find_translation(const QLocale & locale, QString path; if (QFileInfo(filename).isRelative()) { path = directory; - if (!path.isEmpty() && !path.endsWith(QLatin1Char('/'))) - path += QLatin1Char('/'); + if (!path.isEmpty() && !path.endsWith(u'/')) + path += u'/'; } const QString suffixOrDotQM = suffix.isNull() ? dotQmLiteral() : suffix; @@ -667,7 +667,7 @@ static QString find_translation(const QLocale & locale, #endif for (QString localeName : qAsConst(languages)) { - localeName.replace(QLatin1Char('-'), QLatin1Char('_')); + localeName.replace(u'-', u'_'); // try the complete locale name first and progressively truncate from // the end until a matching language tag is found (with or without suffix) @@ -682,7 +682,7 @@ static QString find_translation(const QLocale & locale, realname.truncate(realNameBaseSize); - int rightmost = localeName.lastIndexOf(QLatin1Char('_')); + int rightmost = localeName.lastIndexOf(u'_'); if (rightmost <= 0) break; // no truncations anymore, break localeName.truncate(rightmost); diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 13c90f2578..72dce5e32f 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -90,6 +90,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace { // anonymous used to hide QVariant handlers /*! @@ -154,11 +156,11 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok, bool all if (*ok) return l; if (allowStringToBool) { - if (s == QLatin1String("false") || s == QLatin1String("0")) { + if (s == "false"_L1 || s == "0"_L1) { *ok = true; return 0; } - if (s == QLatin1String("true") || s == QLatin1String("1")) { + if (s == "true"_L1 || s == "1"_L1) { *ok = true; return 1; } |