diff options
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index c3f67830ca..a51ee81023 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -129,6 +129,11 @@ inline bool isascii(int c) } #endif +#if defined(Q_OS_SYMBIAN) +void qt_symbianUpdateSystemPrivate(); +void qt_symbianInitSystemLocale(); +#endif + /****************************************************************************** ** Helpers for accessing Qt locale database */ @@ -170,16 +175,17 @@ static QLocale::Language codeToLanguage(const QChar *code) } // 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 +213,15 @@ static QString countryToCode(QLocale::Country country) 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 +257,7 @@ static bool splitLocaleName(const QString &name, QChar *lang_begin, QChar *cntry { 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 +288,7 @@ static bool splitLocaleName(const QString &name, QChar *lang_begin, QChar *cntry break; case 1: // parsing country - if (cntry - cntry_begin == 2) { + if (cntry - cntry_begin == 3) { cntry_begin[0] = 0; break; } @@ -301,7 +312,7 @@ void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Co 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 +430,7 @@ QByteArray getWinLocaleName(LCID id = LOCALE_USER_DEFAULT) 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 +754,7 @@ struct WindowsToISOListElt { 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 +957,7 @@ static QByteArray getMacLocaleName() QByteArray result = envVarLocale(); QChar lang[3]; - QChar cntry[2]; + QChar cntry[3]; if (result.isEmpty() || result != "C" && !splitLocaleName(QString::fromLocal8Bit(result), lang, cntry)) { QCFType<CFLocaleRef> l = CFLocaleCopyCurrent(); @@ -1215,7 +1227,7 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const 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())); @@ -1407,6 +1419,9 @@ static const QSystemLocale *systemLocale() { if (_systemLocale) return _systemLocale; +#if defined(Q_OS_SYMBIAN) + qt_symbianInitSystemLocale(); +#endif return QSystemLocale_globalSystemLocale(); } @@ -1417,6 +1432,10 @@ void QLocalePrivate::updateSystemPrivate() system_lp = globalLocalePrivate(); *system_lp = *sys_locale->fallbackLocale().d(); +#if defined(Q_OS_SYMBIAN) + qt_symbianUpdateSystemPrivate(); +#endif + QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant()); if (!res.isNull()) system_lp->m_language_id = res.toInt(); @@ -1570,7 +1589,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l) This constructor converts the locale name to a language/country pair; it does not use the system locale database. - QLocale's data is based on Common Locale Data Repository v1.8.0. + QLocale's data is based on Common Locale Data Repository v1.8.1. The double-to-string and string-to-double conversion functions are covered by the following licenses: @@ -3459,6 +3478,25 @@ QLocale::MeasurementSystem QLocale::measurementSystem() const } /*! + \since 4.7 + + Returns the text direction of the language. +*/ +Qt::LayoutDirection QLocale::textDirection() const +{ + Language lang = language(); + if (lang == QLocale::Arabic || + lang == QLocale::Hebrew || + lang == QLocale::Persian || + lang == QLocale::Urdu || + lang == QLocale::Syriac) + return Qt::RightToLeft; + + return Qt::LeftToRight; +} + + +/*! \since 4.5 Returns the localized name of the "AM" suffix for times specified using |