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.

Change-Id: Ieba79baf5ac34264a988fffd172675ac3584f94b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit 308f9ae8f041e0cac47fdca55f1172a7d3ea892d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2022-11-10 23:01:34 -08:00 committed by Qt Cherry-pick Bot
parent b54689f8a8
commit 1f92a4005c

View File

@ -7368,6 +7368,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);
}
@ -7407,6 +7412,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
@ -11059,16 +11069,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