diff -r e24348a560a6 -r b72c6db6890b src/corelib/tools/qlocale.cpp --- a/src/corelib/tools/qlocale.cpp Fri Jun 11 14:24:45 2010 +0300 +++ b/src/corelib/tools/qlocale.cpp Wed Jun 23 19:07:03 2010 +0300 @@ -170,16 +170,17 @@ } // Assumes that code is a -// QChar code[2]; +// QChar code[3]; static QLocale::Country codeToCountry(const QChar *code) { ushort uc1 = code[0].unicode(); ushort uc2 = code[1].unicode(); + ushort uc3 = code[2].unicode(); const unsigned char *c = country_code_list; - for (; *c != 0; c += 2) { - if (uc1 == c[0] && uc2 == c[1]) - return QLocale::Country((c - country_code_list)/2); + for (; *c != 0; c += 3) { + if (uc1 == c[0] && uc2 == c[1] && uc3 == c[2]) + return QLocale::Country((c - country_code_list)/3); } return QLocale::AnyCountry; @@ -207,10 +208,15 @@ if (country == QLocale::AnyCountry) return QString(); - QString code(2, Qt::Uninitialized); - const unsigned char *c = country_code_list + 2*(uint(country)); + const unsigned char *c = country_code_list + 3*(uint(country)); + + QString code(c[2] == 0 ? 2 : 3, Qt::Uninitialized); + code[0] = ushort(c[0]); code[1] = ushort(c[1]); + if (c[2] != 0) + code[2] = ushort(c[2]); + return code; } @@ -246,7 +252,7 @@ { for (int i = 0; i < 3; ++i) lang_begin[i] = 0; - for (int i = 0; i < 2; ++i) + for (int i = 0; i < 3; ++i) cntry_begin[i] = 0; int l = name.length(); @@ -277,7 +283,7 @@ break; case 1: // parsing country - if (cntry - cntry_begin == 2) { + if (cntry - cntry_begin == 3) { cntry_begin[0] = 0; break; } @@ -301,7 +307,7 @@ cntry = QLocale::AnyCountry; QChar lang_code[3]; - QChar cntry_code[2]; + QChar cntry_code[3]; if (!splitLocaleName(name, lang_code, cntry_code)) return; @@ -419,7 +425,7 @@ if (id == LOCALE_USER_DEFAULT) { result = envVarLocale(); QChar lang[3]; - QChar cntry[2]; + QChar cntry[3]; if ( result == "C" || (!result.isEmpty() && splitLocaleName(QString::fromLocal8Bit(result), lang, cntry)) ) { long id = 0; @@ -743,6 +749,7 @@ char iso_name[6]; }; +/* NOTE: This array should be sorted by the first column! */ static const WindowsToISOListElt windows_to_iso_list[] = { { 0x0401, "ar_SA" }, { 0x0402, "bg\0 " }, @@ -945,7 +952,7 @@ QByteArray result = envVarLocale(); QChar lang[3]; - QChar cntry[2]; + QChar cntry[3]; if (result.isEmpty() || result != "C" && !splitLocaleName(QString::fromLocal8Bit(result), lang, cntry)) { QCFType l = CFLocaleCopyCurrent(); @@ -1215,7 +1222,7 @@ case LanguageId: case CountryId: { QString preferredLanguage; - QString preferredCountry; + QString preferredCountry(3, QChar()); // codeToCountry assumes QChar[3] getMacPreferredLanguageAndCountry(&preferredLanguage, &preferredCountry); QLocale::Language languageCode = (preferredLanguage.isEmpty() ? QLocale::C : codeToLanguage(preferredLanguage.data())); QLocale::Country countryCode = (preferredCountry.isEmpty() ? QLocale::AnyCountry : codeToCountry(preferredCountry.data()));