From 9f64065c1f70827e3c41a04630ebc50369af5697 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 2 Nov 2022 07:45:35 -0700 Subject: [PATCH] QString: merge the two toIntegral_helper() back to a template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We go from non-template toInt/toLongLong/etc. to template QString::toIntegral_helper, 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 --- src/corelib/text/qstring.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 8b5c02324d..707b13082a 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -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 +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 latin1(string.size()); qt_to_latin1(latin1.data(), string.utf16(), string.size()); - return QLocaleData::bytearrayToLongLong(latin1, base, ok); + if constexpr (std::is_signed_v) + 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(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 latin1(string.size()); - qt_to_latin1(latin1.data(), string.utf16(), string.size()); - return QLocaleData::bytearrayToUnsLongLong(latin1, base, ok); + return toIntegral(string, ok, base); } /*!