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:
parent
0f9f716f36
commit
1d2e3a5452
@ -372,48 +372,52 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
|
|||||||
const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country)
|
const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country)
|
||||||
{
|
{
|
||||||
QLocaleId localeId = QLocaleId::fromIds(language, script, 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
|
// Try a straight match with the likely data:
|
||||||
if (const QLocaleData *const data = findLocaleDataById(localeId))
|
if (const QLocaleData *const data = findLocaleDataById(likelyId))
|
||||||
return data;
|
return data;
|
||||||
QList<QLocaleId> tried;
|
QList<QLocaleId> tried;
|
||||||
tried.push_back(localeId);
|
tried.push_back(likelyId);
|
||||||
|
|
||||||
// No match; try again with likely country
|
// No match; try again with likely country
|
||||||
localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry);
|
if (country != QLocale::AnyCountry
|
||||||
localeId = localeId.withLikelySubtagsAdded();
|
&& (language != QLocale::AnyLanguage || script != QLocale::AnyScript)) {
|
||||||
if (!tried.contains(localeId)) {
|
localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry);
|
||||||
if (const QLocaleData *const data = findLocaleDataById(localeId))
|
likelyId = localeId.withLikelySubtagsAdded();
|
||||||
return data;
|
if (!tried.contains(likelyId)) {
|
||||||
tried.push_back(localeId);
|
if (const QLocaleData *const data = findLocaleDataById(likelyId))
|
||||||
}
|
return data;
|
||||||
|
tried.push_back(likelyId);
|
||||||
|
}
|
||||||
|
|
||||||
// No match; try again with any country
|
// No match; try again with any country
|
||||||
localeId = QLocaleId::fromIds(language, script, QLocale::AnyCountry);
|
if (!tried.contains(localeId)) {
|
||||||
if (!tried.contains(localeId)) {
|
if (const QLocaleData *const data = findLocaleDataById(localeId))
|
||||||
if (const QLocaleData *const data = findLocaleDataById(localeId))
|
return data;
|
||||||
return data;
|
tried.push_back(localeId);
|
||||||
tried.push_back(localeId);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No match; try again with likely script
|
// No match; try again with likely script
|
||||||
localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country);
|
if (script != QLocale::AnyScript
|
||||||
localeId = localeId.withLikelySubtagsAdded();
|
&& (language != QLocale::AnyLanguage || country != QLocale::AnyCountry)) {
|
||||||
if (!tried.contains(localeId)) {
|
localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country);
|
||||||
if (const QLocaleData *const data = findLocaleDataById(localeId))
|
likelyId = localeId.withLikelySubtagsAdded();
|
||||||
return data;
|
if (!tried.contains(likelyId)) {
|
||||||
tried.push_back(localeId);
|
if (const QLocaleData *const data = findLocaleDataById(likelyId))
|
||||||
}
|
return data;
|
||||||
|
tried.push_back(likelyId);
|
||||||
|
}
|
||||||
|
|
||||||
// No match; try again with any script
|
// No match; try again with any script
|
||||||
localeId = QLocaleId::fromIds(language, QLocale::AnyScript, country);
|
if (!tried.contains(localeId)) {
|
||||||
if (!tried.contains(localeId)) {
|
if (const QLocaleData *const data = findLocaleDataById(localeId))
|
||||||
if (const QLocaleData *const data = findLocaleDataById(localeId))
|
return data;
|
||||||
return data;
|
tried.push_back(localeId);
|
||||||
tried.push_back(localeId);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No match; return data at original index
|
// No match; return data at original index
|
||||||
|
Loading…
Reference in New Issue
Block a user