Correct case of QLocale::toString(double, ...)'s exponent separator
The function follows various libc functions in forcing the caller to decide the case of the exponent separator, rather than allowing them to opt for the case the locale normally uses. At Qt 6 I changed the code reading from CLDR to not force the case, but didn't change toString() to force lower when that was requested. Since the function is documented to use lower-case when that's what it asks for, change it to do what it says in its documentation. A caller who wants the locale-appropriate case is thus obliged to call exponential() and scan it for lower- or upper-case letters and select the right one of 'e' and 'E' (or 'g' and 'G') to match. This partially reverts some test changes made in commit d5bb8d5150498dc059e8c17f224c66fb1a6bcf32 and expands the QLocale tests to include ones matching those it changed. Fixed some tests of QDoubleValidator that previously turned 'e' in the input into 'E' in the output; roughly alternate between changing the input to match the output and the other way round, to be sure we exercise both branches of the test. Pick-to: 6.9 6.8 6.5 Task-number: QTBUG-134785 Fixes: QTBUG-134768 Change-Id: I5cffbd772a166efab9f7a5145289771c16be1658 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8c88a077cc
commit
05c8a48612
@ -4195,7 +4195,9 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form,
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + (flags & CapitalEorX ? std::move(numStr).toUpper() : numStr);
|
||||
return prefix + (flags & CapitalEorX
|
||||
? std::move(numStr).toUpper()
|
||||
: std::move(numStr).toLower());
|
||||
}
|
||||
|
||||
QString QLocaleData::decimalForm(QString &&digits, int decpt, int precision,
|
||||
|
@ -2453,8 +2453,8 @@ void tst_QTextStream::generateRealNumbersDataWrite()
|
||||
QTest::newRow("0") << 0.0 << QByteArray("0") << QByteArray("0");
|
||||
QTest::newRow("3.14") << 3.14 << QByteArray("3.14") << QByteArray("3.14");
|
||||
QTest::newRow("-3.14") << -3.14 << QByteArray("-3.14") << QByteArray("-3.14");
|
||||
QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10") << QByteArray("1.2E+10");
|
||||
QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10") << QByteArray("-1.2E+10");
|
||||
QTest::newRow("1.2e+10") << 1.2e+10 << QByteArray("1.2e+10") << QByteArray("1.2e+10");
|
||||
QTest::newRow("-1.2e+10") << -1.2e+10 << QByteArray("-1.2e+10") << QByteArray("-1.2e+10");
|
||||
QTest::newRow("12345") << 12345. << QByteArray("12345") << QByteArray("12,345");
|
||||
}
|
||||
|
||||
|
@ -1276,8 +1276,10 @@ void tst_QLocale::doubleToString_data()
|
||||
|
||||
QTest::newRow("de_DE 3,4 f 1") << QString("de_DE") << QString("3,4") << 3.4 << 'f' << 1;
|
||||
QTest::newRow("de_DE 3,4 f -") << QString("de_DE") << QString("3,4") << 3.4 << 'f' << shortest;
|
||||
QTest::newRow("de_DE 3,4 e 1") << QString("de_DE") << QString("3,4E+00") << 3.4 << 'e' << 1;
|
||||
QTest::newRow("de_DE 3,4 e -") << QString("de_DE") << QString("3,4E+00") << 3.4 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 3,4 e 1") << QString("de_DE") << QString("3,4e+00") << 3.4 << 'e' << 1;
|
||||
QTest::newRow("de_DE 3,4 E 1") << QString("de_DE") << QString("3,4E+00") << 3.4 << 'E' << 1;
|
||||
QTest::newRow("de_DE 3,4 e -") << QString("de_DE") << QString("3,4e+00") << 3.4 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 3,4 E -") << QString("de_DE") << QString("3,4E+00") << 3.4 << 'E' << shortest;
|
||||
QTest::newRow("de_DE 3,4 g 2") << QString("de_DE") << QString("3,4") << 3.4 << 'g' << 2;
|
||||
QTest::newRow("de_DE 3,4 g -") << QString("de_DE") << QString("3,4") << 3.4 << 'g' << shortest;
|
||||
|
||||
@ -1297,29 +1299,33 @@ void tst_QLocale::doubleToString_data()
|
||||
|
||||
QTest::newRow("de_DE 0,035003945 f 9") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'f' << 9;
|
||||
QTest::newRow("de_DE 0,035003945 f -") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'f' << shortest;
|
||||
QTest::newRow("de_DE 0,035003945 e 7") << QString("de_DE") << QString("3,5003945E-02") << 0.035003945 << 'e' << 7;
|
||||
QTest::newRow("de_DE 0,035003945 e -") << QString("de_DE") << QString("3,5003945E-02") << 0.035003945 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 0,035003945 e 7") << QString("de_DE") << QString("3,5003945e-02") << 0.035003945 << 'e' << 7;
|
||||
QTest::newRow("de_DE 0,035003945 E 7") << QString("de_DE") << QString("3,5003945E-02") << 0.035003945 << 'E' << 7;
|
||||
QTest::newRow("de_DE 0,035003945 e -") << QString("de_DE") << QString("3,5003945e-02") << 0.035003945 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 0,035003945 E -") << QString("de_DE") << QString("3,5003945E-02") << 0.035003945 << 'E' << shortest;
|
||||
QTest::newRow("de_DE 0,035003945 g 8") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'g' << 8;
|
||||
QTest::newRow("de_DE 0,035003945 g -") << QString("de_DE") << QString("0,035003945") << 0.035003945 << 'g' << shortest;
|
||||
// Check 'f/F' iff (adjusted) precision > exponent >= -4:
|
||||
QTest::newRow("de_DE 12345 g 4") << QString("de_DE") << QString("1,235E+04") << 12345. << 'g' << 4;
|
||||
QTest::newRow("de_DE 12345 g 4") << QString("de_DE") << QString("1,235e+04") << 12345. << 'g' << 4;
|
||||
QTest::newRow("de_DE 12345 G 4") << QString("de_DE") << QString("1,235E+04") << 12345. << 'G' << 4;
|
||||
QTest::newRow("de_DE 1e7 g 8") << QString("de_DE") << QString("10.000.000") << 1e7 << 'g' << 8;
|
||||
QTest::newRow("de_DE 1e8 g 8") << QString("de_DE") << QString("1E+08") << 1e8 << 'g' << 8;
|
||||
QTest::newRow("de_DE 10.0 g 1") << QString("de_DE") << QString("1E+01") << 10.0 << 'g' << 1;
|
||||
QTest::newRow("de_DE 10.0 g 0") << QString("de_DE") << QString("1E+01") << 10.0 << 'g' << 0;
|
||||
QTest::newRow("de_DE 1e8 g 8") << QString("de_DE") << QString("1e+08") << 1e8 << 'g' << 8;
|
||||
QTest::newRow("de_DE 1e8 G 8") << QString("de_DE") << QString("1E+08") << 1e8 << 'G' << 8;
|
||||
QTest::newRow("de_DE 10.0 g 1") << QString("de_DE") << QString("1e+01") << 10.0 << 'g' << 1;
|
||||
QTest::newRow("de_DE 10.0 g 0") << QString("de_DE") << QString("1e+01") << 10.0 << 'g' << 0;
|
||||
QTest::newRow("de_DE 1.0 g 0") << QString("de_DE") << QString("1") << 1.0 << 'g' << 0;
|
||||
QTest::newRow("de_DE 0.0001 g 0") << QString("de_DE") << QString("0,0001") << 0.0001 << 'g' << 0;
|
||||
QTest::newRow("de_DE 0.00001 g 0") << QString("de_DE") << QString("1E-05") << 0.00001 << 'g' << 0;
|
||||
QTest::newRow("de_DE 0.00001 g 0") << QString("de_DE") << QString("1e-05") << 0.00001 << 'g' << 0;
|
||||
// Check transition to exponent form:
|
||||
QTest::newRow("de_DE 1245678900 g -") << QString("de_DE") << QString("1.245.678.900") << 12456789e2 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 12456789100 g -") << QString("de_DE") << QString("12.456.789.100") << 124567891e2 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 12456789000 g -") << QString("de_DE") << QString("1,2456789E+10") << 12456789e3 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 12456789000 g -") << QString("de_DE") << QString("1,2456789e+10") << 12456789e3 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 12000 g -")
|
||||
<< QString("de_DE") << QString("12.000") << 12e3 << 'g' << shortest;
|
||||
// 12e4 has "120.000" and "1.2E+05" of equal length; which shortest picks is unspecified.
|
||||
QTest::newRow("de_DE 1200000 g -") << QString("de_DE") << QString("1,2E+06") << 12e5 << 'g' << shortest;
|
||||
// 12e4 has "120.000" and "1.2e+05" of equal length; which shortest picks is unspecified.
|
||||
QTest::newRow("de_DE 1200000 g -") << QString("de_DE") << QString("1,2e+06") << 12e5 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 1000 g -") << QString("de_DE") << QString("1.000") << 1e3 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 10000 g -") << QString("de_DE") << QString("1E+04") << 1e4 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 10000 g -") << QString("de_DE") << QString("1e+04") << 1e4 << 'g' << shortest;
|
||||
|
||||
QTest::newRow("C 0.000003945 f 12") << QString("C") << QString("0.000003945000") << 0.000003945 << 'f' << 12;
|
||||
QTest::newRow("C 0.000003945 f 6") << QString("C") << QString("0.000004") << 0.000003945 << 'f' << 6;
|
||||
@ -1350,10 +1356,14 @@ void tst_QLocale::doubleToString_data()
|
||||
|
||||
QTest::newRow("de_DE 0,000003945 f 9") << QString("de_DE") << QString("0,000003945") << 0.000003945 << 'f' << 9;
|
||||
QTest::newRow("de_DE 0,000003945 f -") << QString("de_DE") << QString("0,000003945") << 0.000003945 << 'f' << shortest;
|
||||
QTest::newRow("de_DE 0,000003945 e 3") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'e' << 3;
|
||||
QTest::newRow("de_DE 0,000003945 e -") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 0,000003945 g 4") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'g' << 4;
|
||||
QTest::newRow("de_DE 0,000003945 g -") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 0,000003945 e 3") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'e' << 3;
|
||||
QTest::newRow("de_DE 0,000003945 E 3") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'E' << 3;
|
||||
QTest::newRow("de_DE 0,000003945 e -") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 0,000003945 E -") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'E' << shortest;
|
||||
QTest::newRow("de_DE 0,000003945 g 4") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'g' << 4;
|
||||
QTest::newRow("de_DE 0,000003945 G 4") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'G' << 4;
|
||||
QTest::newRow("de_DE 0,000003945 g -") << QString("de_DE") << QString("3,945e-06") << 0.000003945 << 'g' << shortest;
|
||||
QTest::newRow("de_DE 0,000003945 G -") << QString("de_DE") << QString("3,945E-06") << 0.000003945 << 'G' << shortest;
|
||||
|
||||
QTest::newRow("C 12456789012 f 3") << QString("C") << QString("12456789012.000") << 12456789012.0 << 'f' << 3;
|
||||
QTest::newRow("C 12456789012 e 13") << QString("C") << QString("1.2456789012000e+10") << 12456789012.0 << 'e' << 13;
|
||||
@ -1387,8 +1397,8 @@ void tst_QLocale::doubleToString_data()
|
||||
|
||||
QTest::newRow("de_DE 12456789012 f 0") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'f' << 0;
|
||||
QTest::newRow("de_DE 12456789012 f -") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'f' << shortest;
|
||||
QTest::newRow("de_DE 12456789012 e 10") << QString("de_DE") << QString("1,2456789012E+10") << 12456789012.0 << 'e' << 10;
|
||||
QTest::newRow("de_DE 12456789012 e -") << QString("de_DE") << QString("1,2456789012E+10") << 12456789012.0 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 12456789012 e 10") << QString("de_DE") << QString("1,2456789012e+10") << 12456789012.0 << 'e' << 10;
|
||||
QTest::newRow("de_DE 12456789012 e -") << QString("de_DE") << QString("1,2456789012e+10") << 12456789012.0 << 'e' << shortest;
|
||||
QTest::newRow("de_DE 12456789012 g 11") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'g' << 11;
|
||||
QTest::newRow("de_DE 12456789012 g -") << QString("de_DE") << QString("12.456.789.012") << 12456789012.0 << 'g' << shortest;
|
||||
}
|
||||
|
@ -501,21 +501,21 @@ void tst_QDoubleValidator::fixup_data()
|
||||
|
||||
QTest::newRow("en scientific no digit grouping")
|
||||
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-0.98765e2"
|
||||
<< "-9.8765E+01";
|
||||
<< "-9.8765e+01";
|
||||
QTest::newRow("en scientific with digit grouping")
|
||||
<< "en" << QDoubleValidator::ScientificNotation << -1 << "1,234.98765E-4"
|
||||
<< "1.23498765E-01";
|
||||
QTest::newRow("en scientific with invalid digit grouping")
|
||||
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-12,34.98765e2"
|
||||
<< "-1.23498765E+05";
|
||||
<< "-1.23498765e+05";
|
||||
QTest::newRow("en scientific with invalid group size")
|
||||
<< "en" << QDoubleValidator::ScientificNotation << 2 << "12,34.98765e2"
|
||||
<< "en" << QDoubleValidator::ScientificNotation << 2 << "12,34.98765E2"
|
||||
<< "1.23E+05";
|
||||
QTest::newRow("en scientific no fractional part")
|
||||
<< "en" << QDoubleValidator::ScientificNotation << -1 << "12,34e2"
|
||||
<< "1.234E+05";
|
||||
<< "1.234e+05";
|
||||
QTest::newRow("en scientific negative no fractional part")
|
||||
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-12,34e2"
|
||||
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-12,34E2"
|
||||
<< "-1.234E+05";
|
||||
QTest::newRow("en scientific no fractional and exponent")
|
||||
<< "en" << QDoubleValidator::ScientificNotation << -1 << "1,234"
|
||||
@ -543,21 +543,21 @@ void tst_QDoubleValidator::fixup_data()
|
||||
|
||||
QTest::newRow("de scientific no digit grouping")
|
||||
<< "de" << QDoubleValidator::ScientificNotation << -1 << "0,98765e2"
|
||||
<< "9,8765E+01";
|
||||
<< "9,8765e+01";
|
||||
QTest::newRow("de scientific with digit grouping")
|
||||
<< "de" << QDoubleValidator::ScientificNotation << -1 << "-1.234,98765E-4"
|
||||
<< "-1,23498765E-01";
|
||||
QTest::newRow("de scientific with invalid digit grouping")
|
||||
<< "de" << QDoubleValidator::ScientificNotation << -1 << "12.34,98765e2"
|
||||
<< "1,23498765E+05";
|
||||
<< "1,23498765e+05";
|
||||
QTest::newRow("de scientific with invalid group size")
|
||||
<< "de" << QDoubleValidator::ScientificNotation << 2 << "-12.34,98765e2"
|
||||
<< "de" << QDoubleValidator::ScientificNotation << 2 << "-12.34,98765E2"
|
||||
<< "-1,23E+05";
|
||||
QTest::newRow("de scientific no fractional part")
|
||||
<< "de" << QDoubleValidator::ScientificNotation << -1 << "1.234e2"
|
||||
<< "1,234E+05";
|
||||
<< "1,234e+05";
|
||||
QTest::newRow("de scientific negative no fractional part")
|
||||
<< "de" << QDoubleValidator::ScientificNotation << -1 << "-1.234e2"
|
||||
<< "de" << QDoubleValidator::ScientificNotation << -1 << "-1.234E2"
|
||||
<< "-1,234E+05";
|
||||
QTest::newRow("de scientific no fractional and exponent")
|
||||
<< "de" << QDoubleValidator::ScientificNotation << -1 << "12.34"
|
||||
@ -600,19 +600,19 @@ void tst_QDoubleValidator::fixup_data()
|
||||
|
||||
QTest::newRow("hi scientific no digit grouping")
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "-0.123e-2"
|
||||
<< "-1.23E-03";
|
||||
<< "-1.23e-03";
|
||||
QTest::newRow("hi scientific with digit grouping")
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "12,345.678e-2"
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "12,345.678E-2"
|
||||
<< "1.2345678E+02";
|
||||
QTest::newRow("hi scientific with invalid digit grouping")
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "-1,23,45.678e-2"
|
||||
<< "-1.2345678E+02";
|
||||
<< "-1.2345678e+02";
|
||||
QTest::newRow("hi scientific no fractional part")
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "1,23,456e2"
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "1,23,456E2"
|
||||
<< "1.23456E+07";
|
||||
QTest::newRow("hi scientific negative no fractional part")
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "-1,23,456e2"
|
||||
<< "-1.23456E+07";
|
||||
<< "-1.23456e+07";
|
||||
QTest::newRow("hi scientific no fractional and exponent")
|
||||
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "1,234,56"
|
||||
<< "1.23456E+05";
|
||||
|
Loading…
x
Reference in New Issue
Block a user