diff options
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qlocale/tst_qlocale.cpp | 11 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index db2fc26..559ba81 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -4399,7 +4399,8 @@ double QLocalePrivate::stringToDouble(const QString &number, bool *ok, GroupSeparatorMode group_sep_mode) const { CharBuff buff; - if (!numberToCLocale(number, group_sep_mode, &buff)) { + if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number, + group_sep_mode, &buff)) { if (ok != 0) *ok = false; return 0.0; @@ -4411,7 +4412,8 @@ qlonglong QLocalePrivate::stringToLongLong(const QString &number, int base, bool *ok, GroupSeparatorMode group_sep_mode) const { CharBuff buff; - if (!numberToCLocale(number, group_sep_mode, &buff)) { + if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number, + group_sep_mode, &buff)) { if (ok != 0) *ok = false; return 0; @@ -4424,7 +4426,8 @@ qulonglong QLocalePrivate::stringToUnsLongLong(const QString &number, int base, bool *ok, GroupSeparatorMode group_sep_mode) const { CharBuff buff; - if (!numberToCLocale(number, group_sep_mode, &buff)) { + if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number, + group_sep_mode, &buff)) { if (ok != 0) *ok = false; return 0; diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp index 5e3e334..b8f7c22 100644 --- a/tests/auto/qlocale/tst_qlocale.cpp +++ b/tests/auto/qlocale/tst_qlocale.cpp @@ -591,6 +591,17 @@ void tst_QLocale::long_long_conversion_data() QTest::newRow("de_DE 12345.67") << QString("de_DE") << "12345.67"<< false << (qlonglong) 0; QTest::newRow("de_DE 123456.7") << QString("de_DE") << "123456.7"<< false << (qlonglong) 0; QTest::newRow("de_DE 1.234.567") << QString("de_DE")<< "1.234.567"<< true << (qlonglong) 1234567; + QTest::newRow("de_DE 1.234.567 ldspcs") << QString("de_DE")<< " 1.234.567" << true << (qlonglong) 1234567; + QTest::newRow("de_DE 1.234.567 trspcs") << QString("de_DE")<< "1.234.567 "<< true << (qlonglong) 1234567; + QTest::newRow("de_DE 1.234.567 ldtrspcs") << QString("de_DE")<< " 1.234.567 "<< true << (qlonglong) 1234567; + + // test that space is also accepted whenever QLocale::groupSeparator() == 0xa0 (which looks like space). + QTest::newRow("nb_NO 123 groupsep") << QString("nb_NO")<< QString("1")+QChar(0xa0)+QString("234") << true << (qlonglong) 1234; + QTest::newRow("nb_NO 123 groupsep_space") << QString("nb_NO")<< QString("1")+QChar(0x20)+QString("234") << true << (qlonglong) 1234; + + QTest::newRow("nb_NO 123 ldspcs") << QString("nb_NO")<< " 123" << true << (qlonglong) 123; + QTest::newRow("nb_NO 123 trspcs") << QString("nb_NO")<< "123 "<< true << (qlonglong) 123; + QTest::newRow("nb_NO 123 ldtrspcs") << QString("nb_NO")<< " 123 "<< true << (qlonglong) 123; QTest::newRow("C 1234") << QString("C") << " 1234" << true << (qlonglong) 1234; QTest::newRow("C 1234 ") << QString("C") << "1234 " << true << (qlonglong) 1234; |