From 19f9e7c04532c0f9755264ffbca1021198e0eb17 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 20 Jul 2022 21:23:32 +0200 Subject: [PATCH] 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. Task-number: QTBUG-103531 Change-Id: I0fd5c9c721e892ea617f0b56b8ea423e7a9f0d04 Reviewed-by: Sona Kurazyan Reviewed-by: Thiago Macieira Reviewed-by: Edward Welbourne (cherry picked from commit 88f2a78594e0272d7916e13aca39611a85571937) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qlocale.cpp | 12 ++++++------ src/corelib/text/qlocale_data_p.h | 2 -- 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 85df96c7d8e..d141eb2c334 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3104,10 +3104,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; @@ -3574,8 +3574,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 ceed2589c41..bf6e37b09f5 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 c0f44fb9537..6f6884d3661 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;