From d4242b8af3e6eb5e9f68e5ff2efee97de11da892 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 8 Apr 2021 10:11:51 +0200 Subject: Revise deprecation of countriesForLanguage() It was originally marked \obsolete without any comment on what was to be used to replace it, or deprecation markings in the declaration, so it got missed at 6.0. More recently it's been deprecated in favor of a territory-based name; but actually it was obsoleted by (iterating the territory() of each return from) matchingLocales() in Qt 4.8. So back out of adding territoriesForLanguage to replace it and, instead, mark it as deprecated in the declaration, in favor of matchingLocales(). Also rewrite the implementation to be exactly that replacement. Rewrote the one example using it. Fixes: QTBUG-92484 Change-Id: Iedaf30378446dd9adac5128b7ee5fee48aab1636 Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) (limited to 'src/corelib/text/qlocale.cpp') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 783d09a8b1..8c0ce2434e 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -2653,38 +2653,9 @@ QList QLocale::matchingLocales(QLocale::Language language, QLocale::Scr return result; } -/*! - \since 6.2 - - Returns the list of countries that have entries for \a language in Qt's locale - database. If the result is an empty list, then \a language is not represented in - Qt's locale database. - - \sa matchingLocales() -*/ -QList QLocale::territoriesForLanguage(QLocale::Language language) -{ - QList result; - if (language == C) { - result << AnyTerritory; - return result; - } - - unsigned language_id = language; - const QLocaleData *data = locale_data + locale_index[language_id]; - while (data->m_language_id == language_id) { - const QLocale::Territory territory = static_cast(data->m_territory_id); - if (!result.contains(territory)) - result.append(territory); - ++data; - } - - return result; -} - #if QT_DEPRECATED_SINCE(6, 6) /*! - \obsolete Use territoriesForLanguage(Language) instead. + \obsolete Use matchingLocales() instead and consult the territory() of each. \since 4.3 Returns the list of countries that have entries for \a language in Qt's locale @@ -2695,7 +2666,12 @@ QList QLocale::territoriesForLanguage(QLocale::Language lang */ QList QLocale::countriesForLanguage(Language language) { - return territoriesForLanguage(language); + const auto locales = matchingLocales(language, AnyScript, AnyCountry); + QList result; + result.reserve(locales.size()); + for (const auto &locale : locales) + result.append(locale.territory()); + return result; } #endif -- cgit v1.2.3