diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-02-02 12:41:47 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-02-03 10:40:12 (GMT) |
commit | 470376b6e0574c8a6740e24229ade859a29817f1 (patch) | |
tree | 23faabc762c14281451595a80b1c64b3fe39555b | |
parent | 3d2504305fa39903ab680d7199cb4bb5427167e8 (diff) | |
download | Qt-470376b6e0574c8a6740e24229ade859a29817f1.zip Qt-470376b6e0574c8a6740e24229ade859a29817f1.tar.gz Qt-470376b6e0574c8a6740e24229ade859a29817f1.tar.bz2 |
Fixes QLocale locale name parsing.
Allow BCP47 dash as a language-country separator.
This only changes it one way - parsing 'en-US' will work, but
QLocale::name() will still return name with underscore as separator.
Task-number: QTBUG-15835
Reviewed-by: João Abecasis
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qlocale/tst_qlocale.cpp | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 6b1de5e..5499fea 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -274,7 +274,7 @@ static bool splitLocaleName(const QString &name, QChar *lang_begin, QChar *cntry switch (state) { case 0: // parsing language - if (uc->unicode() == '_') { + if (uc->unicode() == '_' || uc->unicode() == '-') { state = 1; break; } @@ -2201,7 +2201,7 @@ static quint16 localePrivateIndex(const QLocalePrivate *p) /*! Constructs a QLocale object with the specified \a name, which has the format - "language[_country][.codeset][@modifier]" or "C", where: + "language[_-country][.codeset][@modifier]" or "C", where: \list \i language is a lowercase, two-letter, ISO 639 language code, @@ -2209,6 +2209,8 @@ static quint16 localePrivateIndex(const QLocalePrivate *p) \i and codeset and modifier are ignored. \endlist + The separator can be either underscore or a minus sign. + If the string violates the locale format, or language is not a valid ISO 369 code, the "C" locale is used instead. If country is not present, or is not a valid ISO 3166 code, the most diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp index 7e9b8ec..a01cacb 100644 --- a/tests/auto/qlocale/tst_qlocale.cpp +++ b/tests/auto/qlocale/tst_qlocale.cpp @@ -316,6 +316,8 @@ void tst_QLocale::ctor() TEST_CTOR("en_GB.bla", English, UnitedKingdom) TEST_CTOR("en_GB@.bla", English, UnitedKingdom) TEST_CTOR("en_GB@bla", English, UnitedKingdom) + TEST_CTOR("en-GB", English, UnitedKingdom) + TEST_CTOR("en-GB@bla", English, UnitedKingdom) Q_ASSERT(QLocale::Norwegian == QLocale::NorwegianBokmal); TEST_CTOR("no", Norwegian, Norway) @@ -326,6 +328,7 @@ void tst_QLocale::ctor() TEST_CTOR("nn_NO", NorwegianNynorsk, Norway) TEST_CTOR("es_ES", Spanish, Spain) TEST_CTOR("es_419", Spanish, LatinAmericaAndTheCaribbean) + TEST_CTOR("es-419", Spanish, LatinAmericaAndTheCaribbean) // test default countries for languages TEST_CTOR("mn", Mongolian, Mongolia) |