QString: rewrite toDouble() and toFloat() using QStringView

The implementations are identical. Just reuse them. And move the two
QStringView functions closer, instead of where they are today which
lacks apparent motivation.

Pick-to: 6.4
Change-Id: Ieba79baf5ac34264a988fffd172675ac3584f94b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Thiago Macieira 2022-11-10 23:01:34 -08:00
parent 07ac4690c7
commit 308f9ae8f0
1 changed files with 10 additions and 10 deletions

View File

@ -7481,6 +7481,11 @@ qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base)
*/
double QString::toDouble(bool *ok) const
{
return QStringView(*this).toDouble(ok);
}
double QStringView::toDouble(bool *ok) const
{
return QLocaleData::c()->stringToDouble(*this, ok, QLocale::RejectGroupSeparator);
}
@ -7520,6 +7525,11 @@ float QString::toFloat(bool *ok) const
return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
}
float QStringView::toFloat(bool *ok) const
{
return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
}
/*! \fn QString &QString::setNum(int n, int base)
Sets the string to the printed value of \a n in the specified \a
@ -11164,16 +11174,6 @@ void QAbstractConcatenable::appendLatin1To(QLatin1StringView in, QChar *out) noe
qt_from_latin1(reinterpret_cast<char16_t *>(out), in.data(), size_t(in.size()));
}
double QStringView::toDouble(bool *ok) const
{
return QLocaleData::c()->stringToDouble(*this, ok, QLocale::RejectGroupSeparator);
}
float QStringView::toFloat(bool *ok) const
{
return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
}
/*!
\fn template <typename T> qsizetype erase(QString &s, const T &t)
\relates QString