mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
fix corner case locale lookup
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
bb97a7c863
commit
e114af5a8d
2 changed files with 10 additions and 27 deletions
|
@ -212,37 +212,20 @@ const QLocalePrivate *QLocalePrivate::findLocale(QLocale::Language language, QLo
|
|||
script = subtagAliasTbl[i].toscript;
|
||||
country = subtagAliasTbl[i].tocountry;
|
||||
QLOCALEDEBUG << "to" << language << script << country;
|
||||
break;
|
||||
return QLocalePrivate::findLocale(language, script, country);
|
||||
}
|
||||
}
|
||||
|
||||
if (language == QLocale::AnyLanguage) {
|
||||
for (qint16 i = 0; i < localeTblSize; i++) {
|
||||
if (localeTbl[i].m_script == script && localeTbl[i].m_country == country)
|
||||
return &localeTbl[i];
|
||||
}
|
||||
} else if (country == QLocale::AnyCountry) {
|
||||
for (qint16 i = 0; i < localeTblSize; i++) {
|
||||
if (localeTbl[i].m_language == language && localeTbl[i].m_script == script)
|
||||
return &localeTbl[i];
|
||||
}
|
||||
} else if (script == QLocale::AnyScript) {
|
||||
for (qint16 i = 0; i < localeTblSize; i++) {
|
||||
if (localeTbl[i].m_language == language && localeTbl[i].m_country == country)
|
||||
return &localeTbl[i];
|
||||
}
|
||||
} else {
|
||||
// both script and country are explicitly specified, language is checked to ensure
|
||||
// different languages with identical script and country are not matched
|
||||
for (qint16 i = 0; i < localeTblSize; i++) {
|
||||
if (localeTbl[i].m_language == language && localeTbl[i].m_script == script && localeTbl[i].m_country == country)
|
||||
if ((language == QLocale::AnyLanguage || localeTbl[i].m_language == language)
|
||||
&& (script == QLocale::AnyScript || localeTbl[i].m_script == QLocale::AnyScript || localeTbl[i].m_script == script)
|
||||
&& (country == QLocale::AnyCountry || localeTbl[i].m_country == QLocale::AnyCountry || localeTbl[i].m_country == country)) {
|
||||
QLOCALEDEBUG << "exact match for" << language << script << country;
|
||||
return &localeTbl[i];
|
||||
}
|
||||
}
|
||||
|
||||
// greedy matching, e.g. language is C with specific country and script in which case they can
|
||||
// safely be ignored or scripts/country does not have table entry but it has likely subtag
|
||||
// (e.g. ha_Latn_NG), the first match is returned
|
||||
// for compatibility match invalid cases, e.g. en_zz, to the first match for that language
|
||||
for (qint16 i = 0; i < localeTblSize; i++) {
|
||||
if (localeTbl[i].m_language == language) {
|
||||
QLOCALEDEBUG << "greedy match for" << language << script << country;
|
||||
|
|
|
@ -283,7 +283,7 @@ void tst_QLocale::ctor()
|
|||
TEST_CTOR(Dutch, AnyCountry, QLocale::Dutch, QLocale::Netherlands)
|
||||
TEST_CTOR(German, AnyCountry, QLocale::German, QLocale::Germany)
|
||||
TEST_CTOR(Greek, AnyCountry, QLocale::Greek, QLocale::Greece)
|
||||
TEST_CTOR(Malay, AnyCountry, QLocale::Malay, QLocale::Brunei)
|
||||
TEST_CTOR(Malay, AnyCountry, QLocale::Malay, QLocale::Malaysia)
|
||||
TEST_CTOR(Persian, AnyCountry, QLocale::Persian, QLocale::Iran)
|
||||
TEST_CTOR(Portuguese, AnyCountry, QLocale::Portuguese, QLocale::Brazil)
|
||||
TEST_CTOR(Serbian, AnyCountry, QLocale::Serbian, QLocale::Serbia)
|
||||
|
@ -381,7 +381,7 @@ void tst_QLocale::ctor()
|
|||
TEST_CTOR("ha_NG", Hausa, AnyScript, Nigeria)
|
||||
// substitutions
|
||||
TEST_CTOR("ha_Latn_GH", Hausa, AnyScript, Ghana)
|
||||
// TEST_CTOR("ha_Latn_NG", Hausa, AnyScript, Nigeria)
|
||||
TEST_CTOR("ha_Latn_NG", Hausa, AnyScript, Nigeria)
|
||||
|
||||
#undef TEST_CTOR
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue