Deduplicate a common check for legacy codes

All of QLocalePrivate::codeToLanguage()'s legacy codes were
two-letter, so duplicated a "third letter is 0" check; pulling it out
in front of them all will get any three-letter code more promptly to
the final fall-back, while saving the two-letter codes repetition of
the check.

Change-Id: I8ee81a526adaa7b24c11c1de7a1750d87deb5fb3
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
Edward Welbourne 2017-10-04 11:34:08 +02:00
parent 9856f869f5
commit 1c1f42b4dc

View File

@ -110,31 +110,32 @@ QLocale::Language QLocalePrivate::codeToLanguage(QStringView code) Q_DECL_NOTHRO
return QLocale::Language((c - language_code_list)/3);
}
// legacy codes
if (uc1 == 'n' && uc2 == 'o' && uc3 == 0) { // no -> nb
Q_STATIC_ASSERT(QLocale::Norwegian == QLocale::NorwegianBokmal);
return QLocale::Norwegian;
if (uc3 == 0) {
// legacy codes
if (uc1 == 'n' && uc2 == 'o') { // no -> nb
Q_STATIC_ASSERT(QLocale::Norwegian == QLocale::NorwegianBokmal);
return QLocale::Norwegian;
}
if (uc1 == 't' && uc2 == 'l') { // tl -> fil
Q_STATIC_ASSERT(QLocale::Tagalog == QLocale::Filipino);
return QLocale::Tagalog;
}
if (uc1 == 's' && uc2 == 'h') { // sh -> sr[_Latn]
Q_STATIC_ASSERT(QLocale::SerboCroatian == QLocale::Serbian);
return QLocale::SerboCroatian;
}
if (uc1 == 'm' && uc2 == 'o') { // mo -> ro
Q_STATIC_ASSERT(QLocale::Moldavian == QLocale::Romanian);
return QLocale::Moldavian;
}
// Android uses the following deprecated codes
if (uc1 == 'i' && uc2 == 'w') // iw -> he
return QLocale::Hebrew;
if (uc1 == 'i' && uc2 == 'n') // in -> id
return QLocale::Indonesian;
if (uc1 == 'j' && uc2 == 'i') // ji -> yi
return QLocale::Yiddish;
}
if (uc1 == 't' && uc2 == 'l' && uc3 == 0) { // tl -> fil
Q_STATIC_ASSERT(QLocale::Tagalog == QLocale::Filipino);
return QLocale::Tagalog;
}
if (uc1 == 's' && uc2 == 'h' && uc3 == 0) { // sh -> sr[_Latn]
Q_STATIC_ASSERT(QLocale::SerboCroatian == QLocale::Serbian);
return QLocale::SerboCroatian;
}
if (uc1 == 'm' && uc2 == 'o' && uc3 == 0) { // mo -> ro
Q_STATIC_ASSERT(QLocale::Moldavian == QLocale::Romanian);
return QLocale::Moldavian;
}
// Android uses the following deprecated codes
if (uc1 == 'i' && uc2 == 'w' && uc3 == 0) // iw -> he
return QLocale::Hebrew;
if (uc1 == 'i' && uc2 == 'n' && uc3 == 0) // in -> id
return QLocale::Indonesian;
if (uc1 == 'j' && uc2 == 'i' && uc3 == 0) // ji -> yi
return QLocale::Yiddish;
return QLocale::C;
}