diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-04-08 10:11:51 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-04-16 10:23:23 +0200 |
commit | d4242b8af3e6eb5e9f68e5ff2efee97de11da892 (patch) | |
tree | 637a0fd77b774c7980ab26d0e7c04ba639c02ed1 /src/corelib/text/qlocale.cpp | |
parent | 530e0bd469e6859269c2d1a792b8ce819fbff389 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 38 |
1 files changed, 7 insertions, 31 deletions
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> 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::Territory> QLocale::territoriesForLanguage(QLocale::Language language) -{ - QList<Territory> 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<Territory>(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::Territory> QLocale::territoriesForLanguage(QLocale::Language lang */ QList<QLocale::Country> QLocale::countriesForLanguage(Language language) { - return territoriesForLanguage(language); + const auto locales = matchingLocales(language, AnyScript, AnyCountry); + QList<QLocale::Country> result; + result.reserve(locales.size()); + for (const auto &locale : locales) + result.append(locale.territory()); + return result; } #endif |