diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 01e8a7face4..58796e52055 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -46,6 +46,8 @@ QT_WARNING_DISABLE_GCC("-Wfree-nonheap-object") // false positive tracking #include "private/qgregoriancalendar_p.h" #include "qcalendar.h" +#include + QT_BEGIN_NAMESPACE QT_IMPL_METATYPE_EXTERN_TAGGED(QList, QList_Qt__DayOfWeek) @@ -461,9 +463,9 @@ QByteArray QLocalePrivate::bcp47Name(char separator) const return m_data->id().withLikelySubtagsRemoved().name(separator); } -static int findLocaleIndexById(const QLocaleId &localeId) +static qsizetype findLocaleIndexById(const QLocaleId &localeId) { - quint16 idx = locale_index[localeId.language_id]; + qsizetype idx = locale_index[localeId.language_id]; // If there are no locales for specified language (so we we've got the // default language, which has no associated script or country), give up: if (localeId.language_id && idx == 0) @@ -480,14 +482,14 @@ static int findLocaleIndexById(const QLocaleId &localeId) return -1; } -int QLocaleData::findLocaleIndex(QLocaleId lid) +qsizetype QLocaleData::findLocaleIndex(QLocaleId lid) { QLocaleId localeId = lid; QLocaleId likelyId = localeId.withLikelySubtagsAdded(); const ushort fallback = likelyId.language_id; // Try a straight match with the likely data: - int index = findLocaleIndexById(likelyId); + qsizetype index = findLocaleIndexById(likelyId); if (index >= 0) return index; QVarLengthArray tried; @@ -796,7 +798,7 @@ static const QLocaleData *defaultData() return default_data; } -static uint defaultIndex() +static qsizetype defaultIndex() { const QLocaleData *const data = defaultData(); #ifndef QT_NO_SYSTEMLOCALE @@ -834,7 +836,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l) } #endif // QT_NO_DATASTREAM -static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1; +static constexpr qsizetype locale_data_size = q20::ssize(locale_data) - 1; // trailing guard Q_CONSTINIT QBasicAtomicInt QLocalePrivate::s_generation = Q_BASIC_ATOMIC_INITIALIZER(0); Q_GLOBAL_STATIC(QSharedDataPointer, defaultLocalePrivate, @@ -844,8 +846,8 @@ static QLocalePrivate *localePrivateByName(QStringView name) { if (name == u"C") return c_private(); - const int index = QLocaleData::findLocaleIndex(QLocaleId::fromName(name)); - Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1); + const qsizetype index = QLocaleData::findLocaleIndex(QLocaleId::fromName(name)); + Q_ASSERT(index >= 0 && index < locale_data_size); return new QLocalePrivate(locale_data + index, index, locale_data[index].m_language_id == QLocale::C ? QLocale::OmitGroupSeparator : QLocale::DefaultNumberOptions); @@ -857,8 +859,8 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc if (language == QLocale::C) return c_private(); - int index = QLocaleData::findLocaleIndex(QLocaleId { language, script, territory }); - Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1); + qsizetype index = QLocaleData::findLocaleIndex(QLocaleId { language, script, territory }); + Q_ASSERT(index >= 0 && index < locale_data_size); const QLocaleData *data = locale_data + index; QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions; diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index 061e566d68f..ca53ac25f28 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -101,7 +101,7 @@ public: virtual QVariant query(QueryType type, QVariant in = QVariant()) const; virtual QLocale fallbackLocale() const; - inline uint fallbackLocaleIndex() const; + inline qsizetype fallbackLocaleIndex() const; private: QSystemLocale(bool); friend class QSystemLocaleSingleton; @@ -161,7 +161,7 @@ struct QLocaleData public: // Having an index for each locale enables us to have diverse sources of // data, e.g. calendar locales, as well as the main CLDR-derived data. - [[nodiscard]] static int findLocaleIndex(QLocaleId localeId); + [[nodiscard]] static qsizetype findLocaleIndex(QLocaleId localeId); [[nodiscard]] static const QLocaleData *c(); enum DoubleForm { @@ -372,7 +372,7 @@ public: class QLocalePrivate { public: - constexpr QLocalePrivate(const QLocaleData *data, const uint index, + constexpr QLocalePrivate(const QLocaleData *data, qsizetype index, QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions, int refs = 0) : m_data(data), ref Q_BASIC_ATOMIC_INITIALIZER(refs), @@ -410,14 +410,14 @@ public: // System locale has an m_data all its own; all others have m_data = locale_data + m_index const QLocaleData *const m_data; QBasicAtomicInt ref; - const uint m_index; + const qsizetype m_index; QLocale::NumberOptions m_numberOptions; static QBasicAtomicInt s_generation; }; #ifndef QT_NO_SYSTEMLOCALE -uint QSystemLocale::fallbackLocaleIndex() const { return fallbackLocale().d->m_index; } +qsizetype QSystemLocale::fallbackLocaleIndex() const { return fallbackLocale().d->m_index; } #endif template <>