summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-08-09 12:11:46 (GMT)
committerSamuli Piippo <samuli.piippo@digia.com>2011-06-09 10:06:38 (GMT)
commit52fe778df2310660c84db581c53e2c3fae2cc42a (patch)
treea89ff8af40f026b67257d440191164354ac140ce
parent7da79f8d44ba06872e5bf298fde7a3fc45df7046 (diff)
downloadQt-52fe778df2310660c84db581c53e2c3fae2cc42a.zip
Qt-52fe778df2310660c84db581c53e2c3fae2cc42a.tar.gz
Qt-52fe778df2310660c84db581c53e2c3fae2cc42a.tar.bz2
Fix QString::arg: When specifying %L1, the group separator would be added even if the local specify QLocale::OmitGroupSeparator
Task-number: QTBUG-9281 Reviewed-by: Denis (cherry picked from commit 720f4ca0ec3b42a101ac24b2cf74cdc87d29eac9)
-rw-r--r--src/corelib/tools/qstring.cpp13
-rw-r--r--tests/auto/qstring/tst_qstring.cpp12
2 files changed, 20 insertions, 5 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 3f472d3..807fdd3 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -6510,8 +6510,9 @@ QString QString::arg(qlonglong a, int fieldWidth, int base, const QChar &fillCha
QString locale_arg;
if (d.locale_occurrences > 0) {
QLocale locale;
- locale_arg = locale.d()->longLongToString(a, -1, base, fieldWidth,
- flags | QLocalePrivate::ThousandsGroup);
+ if (!locale.numberOptions() & QLocale::OmitGroupSeparator)
+ flags |= QLocalePrivate::ThousandsGroup;
+ locale_arg = locale.d()->longLongToString(a, -1, base, fieldWidth, flags);
}
return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);
@@ -6553,8 +6554,9 @@ QString QString::arg(qulonglong a, int fieldWidth, int base, const QChar &fillCh
QString locale_arg;
if (d.locale_occurrences > 0) {
QLocale locale;
- locale_arg = locale.d()->unsLongLongToString(a, -1, base, fieldWidth,
- flags | QLocalePrivate::ThousandsGroup);
+ if (!locale.numberOptions() & QLocale::OmitGroupSeparator)
+ flags |= QLocalePrivate::ThousandsGroup;
+ locale_arg = locale.d()->unsLongLongToString(a, -1, base, fieldWidth, flags);
}
return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);
@@ -6687,7 +6689,8 @@ QString QString::arg(double a, int fieldWidth, char fmt, int prec, const QChar &
if (d.locale_occurrences > 0) {
QLocale locale;
- flags |= QLocalePrivate::ThousandsGroup;
+ if (!locale.numberOptions() & QLocale::OmitGroupSeparator)
+ flags |= QLocalePrivate::ThousandsGroup;
locale_arg = locale.d()->doubleToString(a, prec, form, fieldWidth, flags);
}
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index 5a153de..d26f5e6 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -203,6 +203,7 @@ private slots:
void repeated_data() const;
void task262677remove();
void QTBUG10404_compareRef();
+ void QTBUG9281_arg_locale();
};
typedef QList<int> IntList;
@@ -4712,6 +4713,17 @@ void tst_QString::QTBUG10404_compareRef()
QVERIFY(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 3), Qt::CaseInsensitive) < 0);
}
+void tst_QString::QTBUG9281_arg_locale()
+{
+ QLocale l(QLocale::English, QLocale::UnitedKingdom);
+ l.setNumberOptions(QLocale::OmitGroupSeparator);
+ QLocale::setDefault(l);
+ QString str("*%L1*%L2*");
+ str = str.arg(123456).arg(1234.56);
+ QCOMPARE(str, QString::fromLatin1("*123456*1234.56*"));
+ QLocale::setDefault(QLocale::C);
+}
+
QTEST_APPLESS_MAIN(tst_QString)