Don't try (Any,Any,Any) before a partially-specified locale

We unconditionally tried Any-ing out various tags of a locale without
checking the remainer weren't Any, which would get us the C locale in
some cases where we might have done better.  So check some retained
tag isn't Any before Any-ing out any tag.

In the process, add a separate variable for the ID with likely tags
filled in, to distinguish it from the supplied localeId (thereby
somewhat clarifying what's afoot) and save duplicating the
construction of this.

Task-number: QTBUG-64940
Change-Id: Ibd9f1aba6862434cf00fbf77ba00288ac9a50a3b
Reviewed-by: Jason Erb (Suitable Technologies) <erb@suitabletech.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2017-12-04 16:37:46 +01:00
parent 0f9f716f36
commit 1d2e3a5452

View File

@ -372,48 +372,52 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country)
{
QLocaleId localeId = QLocaleId::fromIds(language, script, country);
localeId = localeId.withLikelySubtagsAdded();
QLocaleId likelyId = localeId.withLikelySubtagsAdded();
const uint idx = locale_index[localeId.language_id];
const uint idx = locale_index[likelyId.language_id];
// Try a straight match
if (const QLocaleData *const data = findLocaleDataById(localeId))
// Try a straight match with the likely data:
if (const QLocaleData *const data = findLocaleDataById(likelyId))
return data;
QList<QLocaleId> tried;
tried.push_back(localeId);
tried.push_back(likelyId);
// No match; try again with likely country
localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry);
localeId = localeId.withLikelySubtagsAdded();
if (!tried.contains(localeId)) {
if (const QLocaleData *const data = findLocaleDataById(localeId))
return data;
tried.push_back(localeId);
}
if (country != QLocale::AnyCountry
&& (language != QLocale::AnyLanguage || script != QLocale::AnyScript)) {
localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry);
likelyId = localeId.withLikelySubtagsAdded();
if (!tried.contains(likelyId)) {
if (const QLocaleData *const data = findLocaleDataById(likelyId))
return data;
tried.push_back(likelyId);
}
// No match; try again with any country
localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry);
if (!tried.contains(localeId)) {
if (const QLocaleData *const data = findLocaleDataById(localeId))
return data;
tried.push_back(localeId);
// No match; try again with any country
if (!tried.contains(localeId)) {
if (const QLocaleData *const data = findLocaleDataById(localeId))
return data;
tried.push_back(localeId);
}
}
// No match; try again with likely script
localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country);
localeId = localeId.withLikelySubtagsAdded();
if (!tried.contains(localeId)) {
if (const QLocaleData *const data = findLocaleDataById(localeId))
return data;
tried.push_back(localeId);
}
if (script != QLocale::AnyScript
&& (language != QLocale::AnyLanguage || country != QLocale::AnyCountry)) {
localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country);
likelyId = localeId.withLikelySubtagsAdded();
if (!tried.contains(likelyId)) {
if (const QLocaleData *const data = findLocaleDataById(likelyId))
return data;
tried.push_back(likelyId);
}
// No match; try again with any script
localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country);
if (!tried.contains(localeId)) {
if (const QLocaleData *const data = findLocaleDataById(localeId))
return data;
tried.push_back(localeId);
// No match; try again with any script
if (!tried.contains(localeId)) {
if (const QLocaleData *const data = findLocaleDataById(localeId))
return data;
tried.push_back(localeId);
}
}
// No match; return data at original index