From 1c1f42b4dc6984959255adb4c26d44a0f26dd109 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 4 Oct 2017 11:34:08 +0200 Subject: 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 Reviewed-by: Konstantin Ritt --- src/corelib/tools/qlocale.cpp | 51 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 06beabbee3..c785a5882a 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -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 (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; - + 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; + } return QLocale::C; } -- cgit v1.2.3