QByteArray: Disentangle number(double) from QLocale
Previously number(double) would go through QLocale which takes a lot of factors into consideration (which we don't need in this case) and outputs a QString in the end, which we then have to convert back to QByteArray. Avoid all that extra work and format it directly into a QByteArray. The other number() functions do not use QLocale, so are left alone for now. Task-number: QTBUG-88484 Change-Id: I4c2eaf101a55ba16e858f95017fb171589a0184e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
e5e8e4f59b
commit
de9c03dc6e
|
|
@ -4110,13 +4110,8 @@ QByteArray QByteArray::number(qulonglong n, int base)
|
|||
QByteArray QByteArray::number(double n, char format, int precision)
|
||||
{
|
||||
QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
|
||||
uint flags = QLocaleData::ZeroPadExponent;
|
||||
|
||||
char lower = asciiLower(uchar(format));
|
||||
if (format != lower)
|
||||
flags |= QLocaleData::CapitalEorX;
|
||||
|
||||
switch (lower) {
|
||||
switch (asciiLower(format)) {
|
||||
case 'f':
|
||||
form = QLocaleData::DFDecimal;
|
||||
break;
|
||||
|
|
@ -4133,7 +4128,7 @@ QByteArray QByteArray::number(double n, char format, int precision)
|
|||
break;
|
||||
}
|
||||
|
||||
return QLocaleData::c()->doubleToString(n, precision, form, -1, flags).toUtf8();
|
||||
return qdtoAscii(n, form, precision, isUpperCaseAscii(format));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -628,6 +628,7 @@ static constexpr int digits(int number)
|
|||
return i;
|
||||
}
|
||||
|
||||
// Used generically for both QString and QByteArray
|
||||
template <typename T>
|
||||
static T dtoString(double d, QLocaleData::DoubleForm form, int precision, bool uppercase)
|
||||
{
|
||||
|
|
@ -783,4 +784,9 @@ QString qdtoBasicLatin(double d, QLocaleData::DoubleForm form, int precision, bo
|
|||
return dtoString<QString>(d, form, precision, uppercase);
|
||||
}
|
||||
|
||||
QByteArray qdtoAscii(double d, QLocaleData::DoubleForm form, int precision, bool uppercase)
|
||||
{
|
||||
return dtoString<QByteArray>(d, form, precision, uppercase);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ QString qulltoBasicLatin(qulonglong l, int base, bool negative);
|
|||
QString qulltoa(qulonglong l, int base, const QStringView zero);
|
||||
Q_CORE_EXPORT QString qdtoa(qreal d, int *decpt, int *sign);
|
||||
QString qdtoBasicLatin(double d, QLocaleData::DoubleForm form, int precision, bool uppercase);
|
||||
QByteArray qdtoAscii(double d, QLocaleData::DoubleForm form, int precision, bool uppercase);
|
||||
|
||||
inline bool isZero(double d)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue