From e69b81101c6e09d1c1b81d50ea868a8625c9f248 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 15 Oct 2020 17:25:24 +0200 Subject: Fix locale look-up when language is unspecified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/text/qlocale.cpp | 21 +++++++++++++++------ 1 file 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; -- cgit v1.2.3