The C locale should omit group separators by default
Numbers formatted in the C locale should not use group separators by default. [ChangeLog][QtCore][QLocale] The C locale does not use group separators when formatting numbers any more. Task-number: QTBUG-4044 Task-number: QTBUG-3068 Change-Id: Ia647a72efc11fecd66d22f9253562b1d4ef58168 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
f7e9e035fd
commit
3695285fde
@ -526,7 +526,7 @@ static uint default_number_options = 0;
|
||||
static const QLocaleData *const c_data = locale_data;
|
||||
static QLocalePrivate *c_private()
|
||||
{
|
||||
static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0 };
|
||||
static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), QLocale::OmitGroupSeparator };
|
||||
return &c_locale;
|
||||
}
|
||||
|
||||
@ -698,7 +698,8 @@ static QLocalePrivate *localePrivateByName(const QString &name)
|
||||
{
|
||||
if (name == QLatin1String("C"))
|
||||
return c_private();
|
||||
return QLocalePrivate::create(findLocaleData(name));
|
||||
const QLocaleData *data = findLocaleData(name);
|
||||
return QLocalePrivate::create(data, data->m_language_id == QLocale::C ? QLocale::OmitGroupSeparator : 0);
|
||||
}
|
||||
|
||||
static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script,
|
||||
|
@ -902,6 +902,7 @@ void tst_QLocale::long_long_conversion()
|
||||
void tst_QLocale::long_long_conversion_extra()
|
||||
{
|
||||
QLocale l(QLocale::C);
|
||||
l.setNumberOptions(0);
|
||||
QCOMPARE(l.toString((qlonglong)1), QString("1"));
|
||||
QCOMPARE(l.toString((qlonglong)12), QString("12"));
|
||||
QCOMPARE(l.toString((qlonglong)123), QString("123"));
|
||||
@ -1613,6 +1614,14 @@ void tst_QLocale::numberOptions()
|
||||
bool ok;
|
||||
|
||||
QLocale locale(QLocale::C);
|
||||
QCOMPARE(locale.numberOptions(), QLocale::OmitGroupSeparator);
|
||||
QCOMPARE(locale.toInt(QString("12345"), &ok), 12345);
|
||||
QVERIFY(ok);
|
||||
QCOMPARE(locale.toInt(QString("12345"), &ok), 12345);
|
||||
QVERIFY(ok);
|
||||
QCOMPARE(locale.toString(12345), QString("12345"));
|
||||
|
||||
locale.setNumberOptions(0);
|
||||
QCOMPARE(locale.numberOptions(), 0);
|
||||
QCOMPARE(locale.toInt(QString("12,345"), &ok), 12345);
|
||||
QVERIFY(ok);
|
||||
@ -1620,14 +1629,6 @@ void tst_QLocale::numberOptions()
|
||||
QVERIFY(ok);
|
||||
QCOMPARE(locale.toString(12345), QString("12,345"));
|
||||
|
||||
locale.setNumberOptions(QLocale::OmitGroupSeparator);
|
||||
QCOMPARE(locale.numberOptions(), QLocale::OmitGroupSeparator);
|
||||
QCOMPARE(locale.toInt(QString("12,345"), &ok), 12345);
|
||||
QVERIFY(ok);
|
||||
QCOMPARE(locale.toInt(QString("12345"), &ok), 12345);
|
||||
QVERIFY(ok);
|
||||
QCOMPARE(locale.toString(12345), QString("12345"));
|
||||
|
||||
locale.setNumberOptions(QLocale::RejectGroupSeparator);
|
||||
QCOMPARE(locale.numberOptions(), QLocale::RejectGroupSeparator);
|
||||
locale.toInt(QString("12,345"), &ok);
|
||||
@ -2033,10 +2034,10 @@ void tst_QLocale::standaloneMonthName()
|
||||
void tst_QLocale::currency()
|
||||
{
|
||||
const QLocale c(QLocale::C);
|
||||
QCOMPARE(c.toCurrencyString(qulonglong(1234)), QString("1,234"));
|
||||
QCOMPARE(c.toCurrencyString(qlonglong(-1234)), QString("-1,234"));
|
||||
QCOMPARE(c.toCurrencyString(double(1234.56)), QString("1,234.56"));
|
||||
QCOMPARE(c.toCurrencyString(double(-1234.56)), QString("-1,234.56"));
|
||||
QCOMPARE(c.toCurrencyString(qulonglong(1234)), QString("1234"));
|
||||
QCOMPARE(c.toCurrencyString(qlonglong(-1234)), QString("-1234"));
|
||||
QCOMPARE(c.toCurrencyString(double(1234.56)), QString("1234.56"));
|
||||
QCOMPARE(c.toCurrencyString(double(-1234.56)), QString("-1234.56"));
|
||||
|
||||
const QLocale en_US("en_US");
|
||||
QCOMPARE(en_US.toCurrencyString(qulonglong(1234)), QString("$1,234"));
|
||||
|
@ -6255,14 +6255,15 @@ void tst_QString::arg_locale()
|
||||
QLocale l(QLocale::English, QLocale::UnitedKingdom);
|
||||
QString str("*%L1*%L2*");
|
||||
|
||||
QCOMPARE(str.arg(123456).arg(1234.56), QString::fromLatin1("*123,456*1,234.56*"));
|
||||
QLocale::setDefault(l);
|
||||
QCOMPARE(str.arg(123456).arg(1234.56), QString::fromLatin1("*123,456*1,234.56*"));
|
||||
|
||||
l.setNumberOptions(QLocale::OmitGroupSeparator);
|
||||
QLocale::setDefault(l);
|
||||
QCOMPARE(str.arg(123456).arg(1234.56), QString::fromLatin1("*123456*1234.56*"));
|
||||
|
||||
QLocale::setDefault(QLocale::C);
|
||||
QCOMPARE(str.arg(123456).arg(1234.56), QString::fromLatin1("*123456*1234.56*"));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user