diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-07-20 21:23:32 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-07-26 01:29:15 +0200 |
commit | 88f2a78594e0272d7916e13aca39611a85571937 (patch) | |
tree | a7bd08976dad2ba32d6d66c02370b1b0cf4c64b1 | |
parent | 15a80cf8a9d59203f8e2b436a5c804197c044807 (diff) |
QLocale: port to qsizetype [1/N]: indexed to ranged loops
Ranged for loops are independent of the container's size_type, so port
what we can to them.
Pick-to: 6.4 6.3
Task-number: QTBUG-103531
Change-Id: I0fd5c9c721e892ea617f0b56b8ea423e7a9f0d04
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r-- | src/corelib/text/qlocale.cpp | 12 | ||||
-rw-r--r-- | src/corelib/text/qlocale_data_p.h | 2 | ||||
-rw-r--r-- | src/corelib/text/qlocale_unix.cpp | 4 |
3 files changed, 8 insertions, 10 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 153a25a035..e19a63fe1a 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3103,10 +3103,10 @@ Qt::DayOfWeek QLocale::firstDayOfWeek() const QLocale::MeasurementSystem QLocalePrivate::measurementSystem() const { - for (int i = 0; i < ImperialMeasurementSystemsCount; ++i) { - if (ImperialMeasurementSystems[i].languageId == m_data->m_language_id - && ImperialMeasurementSystems[i].territoryId == m_data->m_territory_id) { - return ImperialMeasurementSystems[i].system; + for (const auto &system : ImperialMeasurementSystems) { + if (system.languageId == m_data->m_language_id + && system.territoryId == m_data->m_territory_id) { + return system.system; } } return QLocale::MetricSystem; @@ -3573,8 +3573,8 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form, const char32_t zeroUcs4 = QChar::surrogateToUcs4(zero.at(0), zero.at(1)); QString converted; converted.reserve(2 * digits.size()); - for (int i = 0; i < digits.length(); ++i) { - const char32_t digit = unicodeForDigit(digits.at(i).unicode() - '0', zeroUcs4); + for (QChar ch : std::as_const(digits)) { + const char32_t digit = unicodeForDigit(ch.unicode() - '0', zeroUcs4); Q_ASSERT(QChar::requiresSurrogates(digit)); converted.append(QChar::highSurrogate(digit)); converted.append(QChar::lowSurrogate(digit)); diff --git a/src/corelib/text/qlocale_data_p.h b/src/corelib/text/qlocale_data_p.h index ceed2589c4..bf6e37b09f 100644 --- a/src/corelib/text/qlocale_data_p.h +++ b/src/corelib/text/qlocale_data_p.h @@ -37,8 +37,6 @@ static constexpr TerritoryLanguage ImperialMeasurementSystems[] = { { QLocale::Hawaiian, QLocale::UnitedStates, QLocale::ImperialUSSystem }, { QLocale::English, QLocale::UnitedKingdom, QLocale::ImperialUKSystem } }; -static constexpr int ImperialMeasurementSystemsCount = - sizeof(ImperialMeasurementSystems)/sizeof(ImperialMeasurementSystems[0]); /* Storage for alpha codes with length of up to 4 allowing efficient comparison. diff --git a/src/corelib/text/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp index c0f44fb953..6f6884d366 100644 --- a/src/corelib/text/qlocale_unix.cpp +++ b/src/corelib/text/qlocale_unix.cpp @@ -244,9 +244,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const else lst = languages.split(u':'); - for (int i = 0; i < lst.size(); ++i) { + for (const QString &e : std::as_const(lst)) { QStringView language, script, territory; - if (qt_splitLocaleName(lst.at(i), &language, &script, &territory)) { + if (qt_splitLocaleName(e, &language, &script, &territory)) { QString joined = language.isEmpty() ? u"und"_s : language.toString(); if (!script.isEmpty()) joined += u'-' + script; |