summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-10-15 17:25:24 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-10-21 17:56:48 +0200
commite69b81101c6e09d1c1b81d50ea868a8625c9f248 (patch)
treeeccd65072cc47d15d8a7529fc3ad7db8ee4afbe7
parentc67ea659e5447fc2d898dbb78189bfe22893522c (diff)
Fix locale look-up when language is unspecified
Looking up a locale with unspecified language got the C locale, due to taking a short-cut that would make sense if no locale were found for a specified language. Stop assuming the language was specified. Task-number: QTBUG-74287 Pick-to: 5.15 5.12 Change-Id: I8b3c232da584fb187ebb6c190729c377d0083808 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/text/qlocale.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 035e2c4724..01278f343c 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -362,12 +362,15 @@ QByteArray QLocalePrivate::rawName(char separator) const
static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
{
const uint idx = locale_index[localeId.language_id];
- if (idx == 0) // default language has no associated script or country
+ // 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)
return locale_data;
- Q_ASSERT(localeId.language_id);
const QLocaleData *data = locale_data + idx;
- Q_ASSERT(data->m_language_id == localeId.language_id);
+ Q_ASSERT(localeId.language_id
+ ? data->m_language_id == localeId.language_id
+ : data->m_language_id);
if (localeId.script_id == QLocale::AnyScript && localeId.country_id == QLocale::AnyCountry)
return data;
@@ -377,13 +380,17 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
if (data->m_country_id == localeId.country_id)
return data;
++data;
- } while (data->m_language_id == localeId.language_id);
+ } while (localeId.language_id
+ ? data->m_language_id == localeId.language_id
+ : data->m_language_id);
} else if (localeId.country_id == QLocale::AnyCountry) {
do {
if (data->m_script_id == localeId.script_id)
return data;
++data;
- } while (data->m_language_id == localeId.language_id);
+ } while (localeId.language_id
+ ? data->m_language_id == localeId.language_id
+ : data->m_language_id);
} else {
do {
if (data->m_script_id == localeId.script_id
@@ -391,7 +398,9 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
return data;
}
++data;
- } while (data->m_language_id == localeId.language_id);
+ } while (localeId.language_id
+ ? data->m_language_id == localeId.language_id
+ : data->m_language_id);
}
return nullptr;