QString: merge the two toIntegral_helper() back to a template
We go from non-template toInt/toLongLong/etc. to template QString::toIntegral_helper<T>, then to non-template QString::toIntegral_helper, then back to template ::toIntegral(). I could maybe use QtPrivate::to{Signed,Unsigned}Integer, which operate on QByteArrayView, but its use of QtPrivate::ParsedNumber as a return type is slightly worse. Change-Id: I3d74c753055744deb8acfffd1723cbc567837483 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
30c491f3b2
commit
9f64065c1f
@ -7186,18 +7186,27 @@ QString QString::vasprintf(const char *cformat, va_list ap)
|
||||
\sa number(), toULongLong(), toInt(), QLocale::toLongLong()
|
||||
*/
|
||||
|
||||
qlonglong QString::toIntegral_helper(QStringView string, bool *ok, int base)
|
||||
template <typename Int>
|
||||
static Int toIntegral(QStringView string, bool *ok, int base)
|
||||
{
|
||||
#if defined(QT_CHECK_RANGE)
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
qWarning("QString::toULongLong: Invalid base (%d)", base);
|
||||
qWarning("QString::toIntegral: Invalid base (%d)", base);
|
||||
base = 10;
|
||||
}
|
||||
#endif
|
||||
|
||||
QVarLengthArray<uchar> latin1(string.size());
|
||||
qt_to_latin1(latin1.data(), string.utf16(), string.size());
|
||||
return QLocaleData::bytearrayToLongLong(latin1, base, ok);
|
||||
if constexpr (std::is_signed_v<Int>)
|
||||
return QLocaleData::bytearrayToLongLong(latin1, base, ok);
|
||||
else
|
||||
return QLocaleData::bytearrayToUnsLongLong(latin1, base, ok);
|
||||
}
|
||||
|
||||
qlonglong QString::toIntegral_helper(QStringView string, bool *ok, int base)
|
||||
{
|
||||
return toIntegral<qlonglong>(string, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -7231,16 +7240,7 @@ qlonglong QString::toIntegral_helper(QStringView string, bool *ok, int base)
|
||||
|
||||
qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base)
|
||||
{
|
||||
#if defined(QT_CHECK_RANGE)
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
qWarning("QString::toULongLong: Invalid base (%d)", base);
|
||||
base = 10;
|
||||
}
|
||||
#endif
|
||||
|
||||
QVarLengthArray<uchar> latin1(string.size());
|
||||
qt_to_latin1(latin1.data(), string.utf16(), string.size());
|
||||
return QLocaleData::bytearrayToUnsLongLong(latin1, base, ok);
|
||||
return toIntegral<qulonglong>(string, ok, base);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user