From 470376b6e0574c8a6740e24229ade859a29817f1 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Wed, 2 Feb 2011 13:41:47 +0100 Subject: Fixes QLocale locale name parsing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/tools/qlocale.cpp | 6 ++++-- 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) -- cgit v0.12