Skip to content

Commit

Permalink
Don't try (Any,Any,Any) before a partially-specified locale
Browse files Browse the repository at this point in the history
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) <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
ediosyncratic committed Jan 19, 2018
1 parent 0f9f716 commit 1d2e3a5
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions src/corelib/tools/qlocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// 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);
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
if (!tried.contains(localeId)) {
if (const QLocaleData *const data = findLocaleDataById(localeId))
return data;
tried.push_back(localeId);
}
}

// No match; return data at original index
Expand Down

0 comments on commit 1d2e3a5

Please sign in to comment.