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/text | |
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/text')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 26 | ||||
-rw-r--r-- | src/corelib/text/qlocale_mac.mm | 42 | ||||
-rw-r--r-- | src/corelib/text/qlocale_unix.cpp | 14 | ||||
-rw-r--r-- | src/corelib/text/qlocale_win.cpp | 33 | ||||
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 57 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 46 | ||||
-rw-r--r-- | src/corelib/text/qunicodetools.cpp | 6 |
7 files changed, 118 insertions, 106 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 1811304f51..73a41112a3 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -84,6 +84,8 @@ QT_WARNING_DISABLE_GCC("-Wfree-nonheap-object") // false positive tracking QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifndef QT_NO_SYSTEMLOCALE static QSystemLocale *_systemLocale = nullptr; class QSystemLocaleSingleton: public QSystemLocale @@ -221,7 +223,7 @@ QLatin1String QLocalePrivate::languageToCode(QLocale::Language language, if (language == QLocale::AnyLanguage || language > QLocale::LastLanguage) return QLatin1String(); if (language == QLocale::C) - return QLatin1String("C"); + return "C"_L1; const LanguageCodeEntry &i = languageCodeList[language]; @@ -636,22 +638,22 @@ QString qt_readEscapedFormatString(QStringView format, int *idx) { int &i = *idx; - Q_ASSERT(format.at(i) == QLatin1Char('\'')); + Q_ASSERT(format.at(i) == u'\''); ++i; if (i == format.size()) return QString(); if (format.at(i).unicode() == '\'') { // "''" outside of a quoted string ++i; - return QLatin1String("'"); + return "'"_L1; } QString result; while (i < format.size()) { if (format.at(i).unicode() == '\'') { - if (format.mid(i + 1).startsWith(QLatin1Char('\''))) { + if (format.mid(i + 1).startsWith(u'\'')) { // "''" inside a quoted string - result.append(QLatin1Char('\'')); + result.append(u'\''); i += 2; } else { break; @@ -1357,7 +1359,7 @@ QString QLocale::name() const if (c == AnyTerritory) return d->languageCode(); - return d->languageCode() + QLatin1Char('_') + d->territoryCode(); + return d->languageCode() + u'_' + d->territoryCode(); } static qlonglong toIntegral_helper(const QLocaleData *d, QStringView str, bool *ok, @@ -1550,7 +1552,7 @@ QLocale::Script QLocale::codeToScript(QStringView scriptCode) noexcept QString QLocale::languageToString(Language language) { if (language > QLocale::LastLanguage) - return QLatin1String("Unknown"); + return "Unknown"_L1; return QLatin1String(language_name_list + language_name_index[language]); } @@ -1564,7 +1566,7 @@ QString QLocale::languageToString(Language language) QString QLocale::territoryToString(QLocale::Territory territory) { if (territory > QLocale::LastTerritory) - return QLatin1String("Unknown"); + return "Unknown"_L1; return QLatin1String(territory_name_list + territory_name_index[territory]); } @@ -1592,7 +1594,7 @@ QString QLocale::countryToString(Country country) QString QLocale::scriptToString(QLocale::Script script) { if (script > QLocale::LastScript) - return QLatin1String("Unknown"); + return "Unknown"_L1; return QLatin1String(script_name_list + script_name_index[script]); } @@ -2338,7 +2340,7 @@ QString QLocale::dateTimeFormat(FormatType format) const } } #endif - return dateFormat(format) + QLatin1Char(' ') + timeFormat(format); + return dateFormat(format) + u' ' + timeFormat(format); } #if QT_CONFIG(datestring) @@ -3497,7 +3499,7 @@ QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime & QString text = time.hour() < 12 ? locale.amText() : locale.pmText(); used = true; repeat = 1; - if (format.mid(i + 1).startsWith(QLatin1Char('p'), Qt::CaseInsensitive)) + if (format.mid(i + 1).startsWith(u'p', Qt::CaseInsensitive)) ++repeat; if (c.unicode() == 'A' && (repeat == 1 || format.at(i + 1).unicode() == 'P')) text = std::move(text).toUpper(); @@ -4403,7 +4405,7 @@ QString QLocale::formattedDataSize(qint64 bytes, int precision, DataSizeFormats unit = d->m_data->byteCount().viewData(byte_unit_data); } - return number + QLatin1Char(' ') + unit; + return number + u' ' + unit; } /*! diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm index 7d75db31d0..6ca4045dc2 100644 --- a/src/corelib/text/qlocale_mac.mm +++ b/src/corelib/text/qlocale_mac.mm @@ -52,6 +52,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /****************************************************************************** ** Wrappers for Mac locale system functions */ @@ -293,10 +295,10 @@ static QVariant macToQtFormat(QStringView sys_fmt) while (i < sys_fmt.size()) { if (sys_fmt.at(i).unicode() == '\'') { QString text = qt_readEscapedFormatString(sys_fmt, &i); - if (text == QLatin1String("'")) - result += QLatin1String("''"); + if (text == "'"_L1) + result += "''"_L1; else - result += QLatin1Char('\'') + text + QLatin1Char('\''); + result += u'\'' + text + u'\''; continue; } @@ -322,17 +324,17 @@ static QVariant macToQtFormat(QStringView sys_fmt) case 'u': // Extended Year (1..n): 2 = short year, 1 & 3..n = padded number // Qt only supports long (4) or short (2) year, use long for all others if (repeat == 2) - result += QLatin1String("yy"); + result += "yy"_L1; else - result += QLatin1String("yyyy"); + result += "yyyy"_L1; break; case 'M': // Month (1..5): 4 = long, 3 = short, 1..2 = number, 5 = narrow case 'L': // Standalone Month (1..5): 4 = long, 3 = short, 1..2 = number, 5 = narrow // Qt only supports long, short and number, use short for narrow if (repeat == 5) - result += QLatin1String("MMM"); + result += "MMM"_L1; else - result += QString(repeat, QLatin1Char('M')); + result += QString(repeat, u'M'); break; case 'd': // Day of Month (1..2): 1..2 padded number result += QString(repeat, c); @@ -340,32 +342,32 @@ static QVariant macToQtFormat(QStringView sys_fmt) case 'E': // Day of Week (1..6): 4 = long, 1..3 = short, 5..6 = narrow // Qt only supports long, short and padded number, use short for narrow if (repeat == 4) - result += QLatin1String("dddd"); + result += "dddd"_L1; else - result += QLatin1String("ddd"); + result += "ddd"_L1; break; case 'e': // Local Day of Week (1..6): 4 = long, 3 = short, 5..6 = narrow, 1..2 padded number case 'c': // Standalone Local Day of Week (1..6): 4 = long, 3 = short, 5..6 = narrow, 1..2 padded number // Qt only supports long, short and padded number, use short for narrow if (repeat >= 5) - result += QLatin1String("ddd"); + result += "ddd"_L1; else - result += QString(repeat, QLatin1Char('d')); + result += QString(repeat, 'd'_L1); break; case 'a': // AM/PM (1): 1 = short // Translate to Qt uppercase AM/PM - result += QLatin1String("AP"); + result += "AP"_L1; break; case 'h': // Hour [1..12] (1..2): 1..2 = padded number case 'K': // Hour [0..11] (1..2): 1..2 = padded number case 'j': // Local Hour [12 or 24] (1..2): 1..2 = padded number // Qt h is local hour - result += QString(repeat, QLatin1Char('h')); + result += QString(repeat, 'h'_L1); break; case 'H': // Hour [0..23] (1..2): 1..2 = padded number case 'k': // Hour [1..24] (1..2): 1..2 = padded number // Qt H is 0..23 hour - result += QString(repeat, QLatin1Char('H')); + result += QString(repeat, 'H'_L1); break; case 'm': // Minutes (1..2): 1..2 = padded number case 's': // Seconds (1..2): 1..2 = padded number @@ -374,9 +376,9 @@ static QVariant macToQtFormat(QStringView sys_fmt) case 'S': // Fractional second (1..n): 1..n = truncates to decimal places // Qt uses msecs either unpadded or padded to 3 places if (repeat < 3) - result += QLatin1Char('z'); + result += u'z'; else - result += QLatin1String("zzz"); + result += "zzz"_L1; break; case 'z': // Time Zone (1..4) case 'Z': // Time Zone (1..5) @@ -385,16 +387,14 @@ static QVariant macToQtFormat(QStringView sys_fmt) case 'V': // Time Zone (1..4) case 'X': // Time Zone (1..5) case 'x': // Time Zone (1..5) - result += QLatin1Char('t'); + result += u't'; break; default: // a..z and A..Z are reserved for format codes, so any occurrence of these not // already processed are not known and so unsupported formats to be ignored. // All other chars are allowed as literals. - if (c < QLatin1Char('A') || c > QLatin1Char('z') || - (c > QLatin1Char('Z') && c < QLatin1Char('a'))) { + if (c < u'A' || c > u'z' || (c > u'Z' && c < u'a')) result += QString(repeat, c); - } break; } @@ -433,7 +433,7 @@ static QVariant macMeasurementSystem() { QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent(); CFStringRef system = static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleMeasurementSystem)); - if (QString::fromCFString(system) == QLatin1String("Metric")) { + if (QString::fromCFString(system) == "Metric"_L1) { return QLocale::MetricSystem; } else { return QLocale::ImperialSystem; diff --git a/src/corelib/text/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp index 84afaa377c..13346c5506 100644 --- a/src/corelib/text/qlocale_unix.cpp +++ b/src/corelib/text/qlocale_unix.cpp @@ -47,6 +47,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifndef QT_NO_SYSTEMLOCALE struct QSystemLocaleData { @@ -144,12 +146,12 @@ QLocale QSystemLocale::fallbackLocale() const if (lang.isEmpty()) lang = qEnvironmentVariable("LANG"); // if the locale is the "C" locale, then we can return the language we found here: - if (lang.isEmpty() || lang == QLatin1String("C") || lang == QLatin1String("POSIX")) + if (lang.isEmpty() || lang == "C"_L1 || lang == "POSIX"_L1) return QLocale(lang); // ... otherwise, if the first part of LANGUAGE says more than or // contradicts what we have, use that: - for (const auto &language : qEnvironmentVariable("LANGUAGE").tokenize(QLatin1Char(':'))) { + for (const auto &language : qEnvironmentVariable("LANGUAGE").tokenize(u':')) { if (contradicts(language, lang)) return QLocale(language); break; // We only look at the first entry. @@ -260,9 +262,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const } case MeasurementSystem: { const QString meas_locale = QString::fromLatin1(d->lc_measurement_var); - if (meas_locale.compare(QLatin1String("Metric"), Qt::CaseInsensitive) == 0) + if (meas_locale.compare("Metric"_L1, Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; - if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0) + if (meas_locale.compare("Other"_L1, Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; return QVariant((int)QLocale(meas_locale).measurementSystem()); } @@ -276,7 +278,7 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const if (languages.isEmpty()) lst.append(QString::fromLatin1(d->lc_messages_var)); else - lst = languages.split(QLatin1Char(':')); + lst = languages.split(u':'); // Inadequate for various cases of a language that's written in more // than one script in the same country, e.g. Sindhi in India. @@ -285,7 +287,7 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const QStringView lang, cntry; if (qt_splitLocaleName(lst.at(i), &lang, nullptr, &cntry)) { d->uiLanguages.append( - cntry.size() ? lang % QLatin1Char('-') % cntry : lang.toString()); + cntry.size() ? lang % u'-' % cntry : lang.toString()); } } return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages); diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index 695b363e5f..c5f82b9500 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -69,6 +69,8 @@ namespace winrt::impl QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static QByteArray getWinLocaleName(LCID id = LOCALE_USER_DEFAULT); static QString winIso639LangName(LCID id = LOCALE_USER_DEFAULT); static QString winIso3116CtryName(LCID id = LOCALE_USER_DEFAULT); @@ -351,7 +353,7 @@ QVariant QSystemLocalePrivate::timeFormat(QLocale::FormatType type) QVariant QSystemLocalePrivate::dateTimeFormat(QLocale::FormatType type) { - return QString(dateFormat(type).toString() + QLatin1Char(' ') + timeFormat(type).toString()); + return QString(dateFormat(type).toString() + u' ' + timeFormat(type).toString()); } QVariant QSystemLocalePrivate::dayName(int day, QLocale::FormatType type) @@ -444,7 +446,7 @@ QString QSystemLocalePrivate::yearFix(int year, int fakeYear, QString &&formatte Q_ASSERT(fakeYear >= 1970 && fakeYear <= 2400); const bool matchTwo = year >= 0 && year % 100 == fakeYear % 100; auto yearUsed = fourDigitYear(fakeYear); - QString sign(year < 0 ? 1 : 0, QLatin1Char('-')); + QString sign(year < 0 ? 1 : 0, u'-'); auto trueYear = fourDigitYear(year < 0 ? -year : year); if (formatted.contains(yearUsed)) return std::move(formatted).replace(yearUsed, sign + trueYear); @@ -534,7 +536,8 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type) QVariant QSystemLocalePrivate::toString(const QDateTime &dt, QLocale::FormatType type) { - return QString(toString(dt.date(), type).toString() + QLatin1Char(' ') + toString(dt.time(), type).toString()); + return QString(toString(dt.date(), type).toString() + u' ' + + toString(dt.time(), type).toString()); } QVariant QSystemLocalePrivate::measurementSystem() @@ -665,7 +668,7 @@ QVariant QSystemLocalePrivate::toCurrencyString(const QSystemLocale::CurrencyToS // int(32) == "12,34,56,789.00" == string("3;2;0") // int(320)== "1234,56,789.00" == string("3;2") QString groupingStr = getLocaleInfo(LOCALE_SMONGROUPING).toString(); - format.Grouping = groupingStr.remove(QLatin1Char(';')).toInt(); + format.Grouping = groupingStr.remove(u';').toInt(); if (format.Grouping % 10 == 0) // magic format.Grouping /= 10; else @@ -752,12 +755,12 @@ QString QSystemLocalePrivate::winToQtFormat(QStringView sys_fmt) int i = 0; while (i < sys_fmt.size()) { - if (sys_fmt.at(i).unicode() == QLatin1Char('\'')) { + if (sys_fmt.at(i).unicode() == u'\'') { QString text = qt_readEscapedFormatString(sys_fmt, &i); - if (text == QLatin1String("'")) - result += QLatin1String("''"); + if (text == "'"_L1) + result += "''"_L1; else - result += QLatin1Char('\'') + text + QLatin1Char('\''); + result += u'\'' + text + u'\''; continue; } @@ -773,13 +776,13 @@ QString QSystemLocalePrivate::winToQtFormat(QStringView sys_fmt) repeat = 2; switch (repeat) { case 1: - result += QLatin1String("yy"); // "y" unsupported by Qt, use "yy" + result += "yy"_L1; // "y" unsupported by Qt, use "yy" break; case 5: - result += QLatin1String("yyyy"); // "yyyyy" same as "yyyy" on Windows + result += "yyyy"_L1; // "yyyyy" same as "yyyy" on Windows break; default: - result += QString(repeat, QLatin1Char('y')); + result += QString(repeat, u'y'); break; } break; @@ -790,14 +793,14 @@ QString QSystemLocalePrivate::winToQtFormat(QStringView sys_fmt) case 2: break; // no equivalent of "gg" in Qt default: - result += QLatin1Char('g'); + result += u'g'; break; } break; case 't': if (repeat > 2) repeat = 2; - result += QLatin1String("AP"); // "t" unsupported, use "AP" + result += "AP"_L1; // "t" unsupported, use "AP" break; default: result += QString(repeat, c); @@ -1110,7 +1113,7 @@ static QString winIso639LangName(LCID id) if (ok && *endptr == '\0') { switch (i) { case 0x814: - result = QLatin1String("nn"); // Nynorsk + result = u"nn"_qs; // Nynorsk break; default: break; @@ -1160,7 +1163,7 @@ static QByteArray getWinLocaleName(LCID id) QString resultusage = winIso639LangName(id); QString country = winIso3116CtryName(id); if (!country.isEmpty()) - resultusage += QLatin1Char('_') + country; + resultusage += u'_' + country; return std::move(resultusage).toLatin1(); } diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index c6aa26b619..e90ec6b1e6 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -61,6 +61,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QRegularExpression \inmodule QtCore @@ -1211,8 +1213,8 @@ void QRegularExpressionPrivate::doMatch(QRegularExpressionMatchPrivate *priv, if (usingCrLfNewlines && offset < subjectLength - && subjectUtf16[offset - 1] == QLatin1Char('\r') - && subjectUtf16[offset] == QLatin1Char('\n')) { + && subjectUtf16[offset - 1] == u'\r' + && subjectUtf16[offset] == u'\n') { ++offset; } else if (offset < subjectLength && QChar::isLowSurrogate(subjectUtf16[offset])) { @@ -1595,7 +1597,7 @@ QString QRegularExpression::errorString() const #endif } #ifdef QT_NO_TRANSLATION - return QLatin1String("no error"); + return u"no error"_qs; #else return QCoreApplication::translate("QRegularExpression", "no error"); #endif @@ -1837,14 +1839,13 @@ QString QRegularExpression::escape(QStringView str) // unlike Perl, a literal NUL must be escaped with // "\\0" (backslash + 0) and not "\\\0" (backslash + NUL), // because pcre16_compile uses a NUL-terminated string - result.append(QLatin1Char('\\')); - result.append(QLatin1Char('0')); - } else if ( (current < QLatin1Char('a') || current > QLatin1Char('z')) && - (current < QLatin1Char('A') || current > QLatin1Char('Z')) && - (current < QLatin1Char('0') || current > QLatin1Char('9')) && - current != QLatin1Char('_') ) - { - result.append(QLatin1Char('\\')); + result.append(u'\\'); + result.append(u'0'); + } else if ((current < u'a' || current > u'z') && + (current < u'A' || current > u'Z') && + (current < u'0' || current > u'9') && + current != u'_') { + result.append(u'\\'); result.append(current); if (current.isHighSurrogate() && i < (count - 1)) result.append(str.at(++i)); @@ -1940,13 +1941,13 @@ QString QRegularExpression::wildcardToRegularExpression(QStringView pattern, Wil const QChar *wc = pattern.data(); #ifdef Q_OS_WIN - const QLatin1Char nativePathSeparator('\\'); - const QLatin1String starEscape("[^/\\\\]*"); - const QLatin1String questionMarkEscape("[^/\\\\]"); + const char16_t nativePathSeparator = u'\\'; + const auto starEscape = "[^/\\\\]*"_L1; + const auto questionMarkEscape = "[^/\\\\]"_L1; #else - const QLatin1Char nativePathSeparator('/'); - const QLatin1String starEscape("[^/]*"); - const QLatin1String questionMarkEscape("[^/]"); + const char16_t nativePathSeparator = u'/'; + const auto starEscape = "[^/]*"_L1; + const auto questionMarkEscape = "[^/]"_L1; #endif while (i < wclen) { @@ -1961,7 +1962,7 @@ QString QRegularExpression::wildcardToRegularExpression(QStringView pattern, Wil case '\\': #ifdef Q_OS_WIN case '/': - rx += QLatin1String("[/\\\\]"); + rx += "[/\\\\]"_L1; break; #endif case '$': @@ -1973,29 +1974,29 @@ QString QRegularExpression::wildcardToRegularExpression(QStringView pattern, Wil case '{': case '|': case '}': - rx += QLatin1Char('\\'); + rx += u'\\'; rx += c; break; case '[': rx += c; // Support for the [!abc] or [!a-c] syntax if (i < wclen) { - if (wc[i] == QLatin1Char('!')) { - rx += QLatin1Char('^'); + if (wc[i] == u'!') { + rx += u'^'; ++i; } - if (i < wclen && wc[i] == QLatin1Char(']')) + if (i < wclen && wc[i] == u']') rx += wc[i++]; - while (i < wclen && wc[i] != QLatin1Char(']')) { + while (i < wclen && wc[i] != u']') { // The '/' appearing in a character class invalidates the // regular expression parsing. It also concerns '\\' on // Windows OS types. - if (wc[i] == QLatin1Char('/') || wc[i] == nativePathSeparator) + if (wc[i] == u'/' || wc[i] == nativePathSeparator) return rx; - if (wc[i] == QLatin1Char('\\')) - rx += QLatin1Char('\\'); + if (wc[i] == u'\\') + rx += u'\\'; rx += wc[i++]; } } @@ -2050,9 +2051,9 @@ QRegularExpression QRegularExpression::fromWildcard(QStringView pattern, Qt::Cas QString QRegularExpression::anchoredPattern(QStringView expression) { return QString() - + QLatin1String("\\A(?:") + + "\\A(?:"_L1 + expression - + QLatin1String(")\\z"); + + ")\\z"_L1; } /*! diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index de4df9fff3..644078f779 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -110,6 +110,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + const char16_t QString::_empty = 0; // in qstringmatcher.cpp @@ -4394,7 +4396,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) const QChar *ac = after.unicode(); for (qsizetype i = 0; i < al - 1; i++) { - if (ac[i] == QLatin1Char('\\')) { + if (ac[i] == u'\\') { int no = ac[i + 1].digitValue(); if (no > 0 && no <= numCaptures) { QStringCapture backReference; @@ -6878,11 +6880,11 @@ QString QString::vasprintf(const char *cformat, va_list ap) ++c; if (*c == '\0') { - result.append(QLatin1Char('%')); // a % at the end of the string - treat as non-escape text + result.append(u'%'); // a % at the end of the string - treat as non-escape text break; } if (*c == '%') { - result.append(QLatin1Char('%')); // %% + result.append(u'%'); // %% ++c; continue; } @@ -8327,13 +8329,13 @@ QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) cons unsigned flags = QLocaleData::NoFlags; // ZeroPadded sorts out left-padding when the fill is zero, to the right of sign: - if (fillChar == QLatin1Char('0')) + if (fillChar == u'0') flags = QLocaleData::ZeroPadded; QString arg; if (d.occurrences > d.locale_occurrences) { arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags); - Q_ASSERT(fillChar != QLatin1Char('0') || !qIsFinite(a) + Q_ASSERT(fillChar != u'0' || !qIsFinite(a) || fieldWidth <= arg.length()); } @@ -8343,7 +8345,7 @@ QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) cons if (!(locale.numberOptions() & QLocale::OmitGroupSeparator)) flags |= QLocaleData::GroupDigits; localeArg = locale.d->m_data->longLongToString(a, -1, base, fieldWidth, flags); - Q_ASSERT(fillChar != QLatin1Char('0') || !qIsFinite(a) + Q_ASSERT(fillChar != u'0' || !qIsFinite(a) || fieldWidth <= localeArg.length()); } @@ -8375,13 +8377,13 @@ QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) con unsigned flags = QLocaleData::NoFlags; // ZeroPadded sorts out left-padding when the fill is zero, to the right of sign: - if (fillChar == QLatin1Char('0')) + if (fillChar == u'0') flags = QLocaleData::ZeroPadded; QString arg; if (d.occurrences > d.locale_occurrences) { arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags); - Q_ASSERT(fillChar != QLatin1Char('0') || !qIsFinite(a) + Q_ASSERT(fillChar != u'0' || !qIsFinite(a) || fieldWidth <= arg.length()); } @@ -8391,7 +8393,7 @@ QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) con if (!(locale.numberOptions() & QLocale::OmitGroupSeparator)) flags |= QLocaleData::GroupDigits; localeArg = locale.d->m_data->unsLongLongToString(a, -1, base, fieldWidth, flags); - Q_ASSERT(fillChar != QLatin1Char('0') || !qIsFinite(a) + Q_ASSERT(fillChar != u'0' || !qIsFinite(a) || fieldWidth <= localeArg.length()); } @@ -8475,7 +8477,7 @@ QString QString::arg(double a, int fieldWidth, char format, int precision, QChar unsigned flags = QLocaleData::NoFlags; // ZeroPadded sorts out left-padding when the fill is zero, to the right of sign: - if (fillChar == QLatin1Char('0')) + if (fillChar == u'0') flags |= QLocaleData::ZeroPadded; if (qIsUpper(format)) @@ -8503,7 +8505,7 @@ QString QString::arg(double a, int fieldWidth, char format, int precision, QChar if (d.occurrences > d.locale_occurrences) { arg = QLocaleData::c()->doubleToString(a, precision, form, fieldWidth, flags | QLocaleData::ZeroPadExponent); - Q_ASSERT(fillChar != QLatin1Char('0') || !qIsFinite(a) + Q_ASSERT(fillChar != u'0' || !qIsFinite(a) || fieldWidth <= arg.length()); } @@ -8519,7 +8521,7 @@ QString QString::arg(double a, int fieldWidth, char format, int precision, QChar if (numberOptions & QLocale::IncludeTrailingZeroesAfterDot) flags |= QLocaleData::AddTrailingZeroes; localeArg = locale.d->m_data->doubleToString(a, precision, form, fieldWidth, flags); - Q_ASSERT(fillChar != QLatin1Char('0') || !qIsFinite(a) + Q_ASSERT(fillChar != u'0' || !qIsFinite(a) || fieldWidth <= localeArg.length()); } @@ -8534,7 +8536,7 @@ static int getEscape(const Char *uc, qsizetype *pos, qsizetype len, int maxNumbe { int i = *pos; ++i; - if (i < len && uc[i] == QLatin1Char('L')) + if (i < len && uc[i] == u'L') ++i; if (i < len) { int escape = to_unicode(uc[i]) - '0'; @@ -8630,7 +8632,7 @@ static ParseResult parseMultiArgFormatString(StringView s) qsizetype last = 0; while (i < end) { - if (uc[i] == QLatin1Char('%')) { + if (uc[i] == u'%') { qsizetype percent = i; int number = getEscape(uc, &i, len); if (number != -1) { @@ -10899,14 +10901,14 @@ QString QString::toHtmlEscaped() const const int len = length(); rich.reserve(qsizetype(len * 1.1)); for (int i = 0; i < len; ++i) { - if (at(i) == QLatin1Char('<')) - rich += QLatin1String("<"); - else if (at(i) == QLatin1Char('>')) - rich += QLatin1String(">"); - else if (at(i) == QLatin1Char('&')) - rich += QLatin1String("&"); - else if (at(i) == QLatin1Char('"')) - rich += QLatin1String("""); + if (at(i) == u'<') + rich += "<"_L1; + else if (at(i) == u'>') + rich += ">"_L1; + else if (at(i) == u'&') + rich += "&"_L1; + else if (at(i) == u'"') + rich += """_L1; else rich += at(i); } diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp index 8223c759e9..bba950102e 100644 --- a/src/corelib/text/qunicodetools.cpp +++ b/src/corelib/text/qunicodetools.cpp @@ -51,6 +51,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_AUTOTEST_EXPORT int qt_initcharattributes_default_algorithm_only = 0; namespace QUnicodeTools { @@ -1409,8 +1411,8 @@ static int init_libthai() { #if QT_CONFIG(library) static bool initialized = false; if (!initialized && (!th_brk || !th_next_cell)) { - th_brk = reinterpret_cast<th_brk_def>(QLibrary::resolve(QLatin1String("thai"), static_cast<int>(LIBTHAI_MAJOR), "th_brk")); - th_next_cell = (th_next_cell_def)QLibrary::resolve(QLatin1String("thai"), LIBTHAI_MAJOR, "th_next_cell"); + th_brk = reinterpret_cast<th_brk_def>(QLibrary::resolve("thai"_L1, static_cast<int>(LIBTHAI_MAJOR), "th_brk")); + th_next_cell = (th_next_cell_def)QLibrary::resolve("thai"_L1, LIBTHAI_MAJOR, "th_next_cell"); initialized = true; } if (th_brk && th_next_cell) |