Make QLocale(QString) explicit
We should not implicitly convert a QString to a QLocale object. It can easily create unwanted side effects. Change-Id: I7bd9b4a4e4512c0e60176ee4d241d172f00fdc32 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
098d2edb07
commit
66f06a930d
@ -941,7 +941,7 @@ public:
|
||||
Q_FLAG(DataSizeFormats)
|
||||
|
||||
QLocale();
|
||||
QLocale(const QString &name);
|
||||
explicit QLocale(const QString &name);
|
||||
QLocale(Language language, Country country = AnyCountry);
|
||||
QLocale(Language language, Script script, Country country);
|
||||
QLocale(const QLocale &other);
|
||||
|
@ -347,9 +347,9 @@ QString QIcuTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const
|
||||
{
|
||||
// TODO No ICU API, use short name instead
|
||||
if (isDaylightTime(atMSecsSinceEpoch))
|
||||
return displayName(QTimeZone::DaylightTime, QTimeZone::ShortName, QString());
|
||||
return displayName(QTimeZone::DaylightTime, QTimeZone::ShortName, QLocale());
|
||||
else
|
||||
return displayName(QTimeZone::StandardTime, QTimeZone::ShortName, QString());
|
||||
return displayName(QTimeZone::StandardTime, QTimeZone::ShortName, QLocale());
|
||||
}
|
||||
|
||||
int QIcuTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const
|
||||
|
@ -3022,7 +3022,7 @@ void tst_QTextStream::int_read_with_locale()
|
||||
QFETCH(int, output);
|
||||
|
||||
QTextStream stream(&input);
|
||||
stream.setLocale(locale);
|
||||
stream.setLocale(QLocale(locale));
|
||||
int result;
|
||||
stream >> result;
|
||||
QCOMPARE(result, output);
|
||||
@ -3053,7 +3053,7 @@ void tst_QTextStream::int_write_with_locale()
|
||||
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
stream.setLocale(locale);
|
||||
stream.setLocale(QLocale(locale));
|
||||
if (numberFlags)
|
||||
stream.setNumberFlags(QTextStream::NumberFlags(numberFlags));
|
||||
stream << input;
|
||||
|
@ -193,7 +193,7 @@ void tst_QCollator::compare()
|
||||
QFETCH(bool, ignorePunctuation);
|
||||
QFETCH(int, punctuationResult);
|
||||
|
||||
QCollator collator(locale);
|
||||
QCollator collator((QLocale(locale)));
|
||||
// Need to canonicalize sign to -1, 0 or 1, as .compare() can produce any -ve for <, any +ve for >.
|
||||
auto asSign = [](int compared) {
|
||||
return compared < 0 ? -1 : compared > 0 ? 1 : 0;
|
||||
|
@ -3010,7 +3010,8 @@ void tst_QLocale::systemLocale()
|
||||
QFETCH(QLocale::Language, language);
|
||||
|
||||
{
|
||||
MySystemLocale sLocale(name);
|
||||
QLocale locale(name);
|
||||
MySystemLocale sLocale(locale);
|
||||
QCOMPARE(QLocale().language(), language);
|
||||
QCOMPARE(QLocale::system().language(), language);
|
||||
}
|
||||
|
@ -4776,7 +4776,7 @@ void tst_QString::arg()
|
||||
is all messed up, because Qt Test itself uses QString::arg().
|
||||
*/
|
||||
|
||||
TransientDefaultLocale transient(QString("de_DE"));
|
||||
TransientDefaultLocale transient(QLocale(QString("de_DE")));
|
||||
|
||||
QString s4( "[%0]" );
|
||||
QString s5( "[%1]" );
|
||||
@ -4924,7 +4924,7 @@ void tst_QString::arg()
|
||||
QCOMPARE(QString("%1").arg(-1., 3, 'g', -1, QChar('x')), QLatin1String("x-1"));
|
||||
QCOMPARE(QString("%1").arg(-100., 3, 'g', -1, QChar('x')), QLatin1String("-100"));
|
||||
|
||||
transient.revise(QString("ar"));
|
||||
transient.revise(QLocale(QString("ar")));
|
||||
QCOMPARE( QString("%L1").arg(12345.6789, 10, 'g', 7, QLatin1Char('0')),
|
||||
QString::fromUtf8("\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xac\xd9\xa3\xd9\xa4\xd9\xa5\xd9\xab\xd9\xa6\xd9\xa8") ); // "٠١٢٬٣٤٥٫٦٨"
|
||||
QCOMPARE( QString("%L1").arg(123456789, 13, 10, QLatin1Char('0')),
|
||||
|
@ -165,7 +165,7 @@ static inline double nan()
|
||||
|
||||
void tst_QStringRef::cleanup()
|
||||
{
|
||||
QLocale::setDefault(QString(QLatin1Char('C')));
|
||||
QLocale::setDefault(QLocale(QString(QLatin1Char('C'))));
|
||||
}
|
||||
|
||||
void tst_QStringRef::at()
|
||||
|
@ -344,9 +344,9 @@ void tst_QTimeZone::dataStreamTest()
|
||||
QCOMPARE(tz2.comment(), QString("Qt Testing"));
|
||||
QCOMPARE(tz2.country(), QLocale::Norway);
|
||||
QCOMPARE(tz2.abbreviation(QDateTime::currentDateTime()), QString("QST"));
|
||||
QCOMPARE(tz2.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QString()),
|
||||
QCOMPARE(tz2.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()),
|
||||
QString("Qt Standard Time"));
|
||||
QCOMPARE(tz2.displayName(QTimeZone::DaylightTime, QTimeZone::LongName, QString()),
|
||||
QCOMPARE(tz2.displayName(QTimeZone::DaylightTime, QTimeZone::LongName, QLocale()),
|
||||
QString("Qt Standard Time"));
|
||||
QCOMPARE(tz2.offsetFromUtc(QDateTime::currentDateTime()), 123456);
|
||||
|
||||
@ -944,7 +944,7 @@ void tst_QTimeZone::utcTest()
|
||||
QCOMPARE(tzp.id(), QByteArray("UTC"));
|
||||
QCOMPARE(tzp.country(), QLocale::AnyCountry);
|
||||
QCOMPARE(tzp.abbreviation(0), QString("UTC"));
|
||||
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QString()), QString("UTC"));
|
||||
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()), QString("UTC"));
|
||||
QCOMPARE(tzp.offsetFromUtc(0), 0);
|
||||
QCOMPARE(tzp.standardTimeOffset(0), 0);
|
||||
QCOMPARE(tzp.daylightTimeOffset(0), 0);
|
||||
@ -985,7 +985,7 @@ void tst_QTimeZone::utcTest()
|
||||
QCOMPARE(tz.comment(), QString("Qt Testing"));
|
||||
QCOMPARE(tz.country(), QLocale::Norway);
|
||||
QCOMPARE(tz.abbreviation(now), QString("QST"));
|
||||
QCOMPARE(tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QString()),
|
||||
QCOMPARE(tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()),
|
||||
QString("Qt Standard Time"));
|
||||
QCOMPARE(tz.offsetFromUtc(now), 123456);
|
||||
QCOMPARE(tz.standardTimeOffset(now), 123456);
|
||||
|
Loading…
Reference in New Issue
Block a user