diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-27 15:48:12 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-30 17:46:00 +0200 |
commit | 88b54cc22a45f9724c201e7249ac79deb55ff48a (patch) | |
tree | e6538e9bc7f6633ffbd7868c10e85923e84f6d35 /src/corelib/text/qbytearray.cpp | |
parent | 7d33779a795afb54af1a96c0da93b532f9db3ba2 (diff) |
Rework QLocalePrivate::bytearrayToU?LongLong()
Change it to take a QByteArrayView instead of a plain char *; all its
callers do know the size and propagating it enables the implementation
to call strntou?ll() rather than strtou?ll(), thereby escaping the
need for '\0'-termination.
Fixes: QTBUG-74286
Change-Id: Ie9394786e9fcf25c1d1be2421805f47c018d13bb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 70526825f3..320f744c4f 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -3507,18 +3507,18 @@ bool QByteArray::isNull() const return d->isNull(); } -static qlonglong toIntegral_helper(const char *data, bool *ok, int base, qlonglong) +static qlonglong toIntegral_helper(QByteArrayView data, bool *ok, int base, qlonglong) { return QLocaleData::bytearrayToLongLong(data, base, ok); } -static qulonglong toIntegral_helper(const char *data, bool *ok, int base, qulonglong) +static qulonglong toIntegral_helper(QByteArrayView data, bool *ok, int base, qulonglong) { return QLocaleData::bytearrayToUnsLongLong(data, base, ok); } template <typename T> static inline -T toIntegral_helper(const char *data, bool *ok, int base) +T toIntegral_helper(QByteArrayView data, bool *ok, int base) { using Int64 = typename std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type; @@ -3528,7 +3528,7 @@ T toIntegral_helper(const char *data, bool *ok, int base) base = 10; } #endif - if (!data) { + if (data.isEmpty()) { if (ok) *ok = false; return 0; @@ -3568,7 +3568,7 @@ T toIntegral_helper(const char *data, bool *ok, int base) qlonglong QByteArray::toLongLong(bool *ok, int base) const { - return toIntegral_helper<qlonglong>(nulTerminated().constData(), ok, base); + return toIntegral_helper<qlonglong>(*this, ok, base); } /*! @@ -3595,7 +3595,7 @@ qlonglong QByteArray::toLongLong(bool *ok, int base) const qulonglong QByteArray::toULongLong(bool *ok, int base) const { - return toIntegral_helper<qulonglong>(nulTerminated().constData(), ok, base); + return toIntegral_helper<qulonglong>(*this, ok, base); } /*! @@ -3624,7 +3624,7 @@ qulonglong QByteArray::toULongLong(bool *ok, int base) const int QByteArray::toInt(bool *ok, int base) const { - return toIntegral_helper<int>(nulTerminated().constData(), ok, base); + return toIntegral_helper<int>(*this, ok, base); } /*! @@ -3651,7 +3651,7 @@ int QByteArray::toInt(bool *ok, int base) const uint QByteArray::toUInt(bool *ok, int base) const { - return toIntegral_helper<uint>(nulTerminated().constData(), ok, base); + return toIntegral_helper<uint>(*this, ok, base); } /*! @@ -3681,7 +3681,7 @@ uint QByteArray::toUInt(bool *ok, int base) const */ long QByteArray::toLong(bool *ok, int base) const { - return toIntegral_helper<long>(nulTerminated().constData(), ok, base); + return toIntegral_helper<long>(*this, ok, base); } /*! @@ -3709,7 +3709,7 @@ long QByteArray::toLong(bool *ok, int base) const */ ulong QByteArray::toULong(bool *ok, int base) const { - return toIntegral_helper<ulong>(nulTerminated().constData(), ok, base); + return toIntegral_helper<ulong>(*this, ok, base); } /*! @@ -3736,7 +3736,7 @@ ulong QByteArray::toULong(bool *ok, int base) const short QByteArray::toShort(bool *ok, int base) const { - return toIntegral_helper<short>(nulTerminated().constData(), ok, base); + return toIntegral_helper<short>(*this, ok, base); } /*! @@ -3763,7 +3763,7 @@ short QByteArray::toShort(bool *ok, int base) const ushort QByteArray::toUShort(bool *ok, int base) const { - return toIntegral_helper<ushort>(nulTerminated().constData(), ok, base); + return toIntegral_helper<ushort>(*this, ok, base); } |