diff options
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 52 | ||||
-rw-r--r-- | src/corelib/text/qbytearrayview.h | 11 | ||||
-rw-r--r-- | src/corelib/text/qbytearrayview.qdoc | 240 |
3 files changed, 301 insertions, 2 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 320f744c4f..a1b0f30d01 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -3571,6 +3571,11 @@ qlonglong QByteArray::toLongLong(bool *ok, int base) const return toIntegral_helper<qlonglong>(*this, ok, base); } +qlonglong QByteArrayView::toLongLong(bool *ok, int base) const +{ + return toIntegral_helper<qlonglong>(*this, ok, base); +} + /*! Returns the byte array converted to an \c {unsigned long long} using base \a base, which is ten by default. Bases 0 and 2 through 36 are supported, using @@ -3598,6 +3603,11 @@ qulonglong QByteArray::toULongLong(bool *ok, int base) const return toIntegral_helper<qulonglong>(*this, ok, base); } +qulonglong QByteArrayView::toULongLong(bool *ok, int base) const +{ + return toIntegral_helper<qulonglong>(*this, ok, base); +} + /*! Returns the byte array converted to an \c int using base \a base, which is ten by default. Bases 0 and 2 through 36 are supported, using letters for @@ -3627,6 +3637,11 @@ int QByteArray::toInt(bool *ok, int base) const return toIntegral_helper<int>(*this, ok, base); } +int QByteArrayView::toInt(bool *ok, int base) const +{ + return toIntegral_helper<int>(*this, ok, base); +} + /*! Returns the byte array converted to an \c {unsigned int} using base \a base, which is ten by default. Bases 0 and 2 through 36 are supported, using @@ -3654,6 +3669,11 @@ uint QByteArray::toUInt(bool *ok, int base) const return toIntegral_helper<uint>(*this, ok, base); } +uint QByteArrayView::toUInt(bool *ok, int base) const +{ + return toIntegral_helper<uint>(*this, ok, base); +} + /*! \since 4.1 @@ -3684,6 +3704,11 @@ long QByteArray::toLong(bool *ok, int base) const return toIntegral_helper<long>(*this, ok, base); } +long QByteArrayView::toLong(bool *ok, int base) const +{ + return toIntegral_helper<long>(*this, ok, base); +} + /*! \since 4.1 @@ -3712,6 +3737,11 @@ ulong QByteArray::toULong(bool *ok, int base) const return toIntegral_helper<ulong>(*this, ok, base); } +ulong QByteArrayView::toULong(bool *ok, int base) const +{ + return toIntegral_helper<ulong>(*this, ok, base); +} + /*! Returns the byte array converted to a \c short using base \a base, which is ten by default. Bases 0 and 2 through 36 are supported, using letters for @@ -3739,6 +3769,11 @@ short QByteArray::toShort(bool *ok, int base) const return toIntegral_helper<short>(*this, ok, base); } +short QByteArrayView::toShort(bool *ok, int base) const +{ + return toIntegral_helper<short>(*this, ok, base); +} + /*! Returns the byte array converted to an \c {unsigned short} using base \a base, which is ten by default. Bases 0 and 2 through 36 are supported, using @@ -3766,6 +3801,10 @@ ushort QByteArray::toUShort(bool *ok, int base) const return toIntegral_helper<ushort>(*this, ok, base); } +ushort QByteArrayView::toUShort(bool *ok, int base) const +{ + return toIntegral_helper<ushort>(*this, ok, base); +} /*! Returns the byte array converted to a \c double value. @@ -3794,10 +3833,14 @@ ushort QByteArray::toUShort(bool *ok, int base) const double QByteArray::toDouble(bool *ok) const { + return QByteArrayView(*this).toDouble(ok); +} + +double QByteArrayView::toDouble(bool *ok) const +{ bool nonNullOk = false; int processed = 0; - double d = qt_asciiToDouble(constData(), size(), - nonNullOk, processed, WhitespacesAllowed); + double d = qt_asciiToDouble(data(), size(), nonNullOk, processed, WhitespacesAllowed); if (ok) *ok = nonNullOk; return d; @@ -3833,6 +3876,11 @@ float QByteArray::toFloat(bool *ok) const return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); } +float QByteArrayView::toFloat(bool *ok) const +{ + return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); +} + /*! \since 5.2 diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 1824826437..1cd5b0333e 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -240,8 +240,19 @@ public: constexpr void chop(qsizetype n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } + // Defined in qbytearray.cpp: [[nodiscard]] QByteArrayView trimmed() const noexcept { return QtPrivate::trimmed(*this); } + [[nodiscard]] short toShort(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] ushort toUShort(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] int toInt(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] uint toUInt(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] long toLong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] ulong toULong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] qlonglong toLongLong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] float toFloat(bool *ok = nullptr) const; + [[nodiscard]] double toDouble(bool *ok = nullptr) const; [[nodiscard]] bool startsWith(QByteArrayView other) const noexcept { return QtPrivate::startsWith(*this, other); } diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc index 5bfd8bdef2..624b056744 100644 --- a/src/corelib/text/qbytearrayview.qdoc +++ b/src/corelib/text/qbytearrayview.qdoc @@ -646,6 +646,246 @@ */ /*! + \fn qlonglong QByteArrayView::toLongLong(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to a \c {long long} using base \a + base, which is ten by default. Bases 0 and 2 through 36 are supported, using + letters for digits beyond 9; A is ten, B is eleven and so on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn qulonglong QByteArrayView::toULongLong(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to an \c {unsigned long long} using + base \a base, which is ten by default. Bases 0 and 2 through 36 are + supported, using letters for digits beyond 9; A is ten, B is eleven and so + on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn int QByteArrayView::toInt(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to an \c int using base \a base, + which is ten by default. Bases 0 and 2 through 36 are supported, using + letters for digits beyond 9; A is ten, B is eleven and so on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \snippet code/src_corelib_text_qbytearrayview.cpp 2 + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn uint QByteArrayView::toUInt(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to an \c {unsigned int} using base \a + base, which is ten by default. Bases 0 and 2 through 36 are supported, using + letters for digits beyond 9; A is ten, B is eleven and so on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn long QByteArrayView::toLong(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to a \c long int using base \a base, + which is ten by default. Bases 0 and 2 through 36 are supported, using + letters for digits beyond 9; A is ten, B is eleven and so on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \snippet code/src_corelib_text_qbytearrayview.cpp 3 + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn ulong QByteArrayView::toULong(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to an \c {unsigned long int} using + base \a base, which is ten by default. Bases 0 and 2 through 36 are + supported, using letters for digits beyond 9; A is ten, B is eleven and so + on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn short QByteArrayView::toShort(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to a \c short using base \a base, + which is ten by default. Bases 0 and 2 through 36 are supported, using + letters for digits beyond 9; A is ten, B is eleven and so on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn ushort QByteArrayView::toUShort(bool *ok, int base) const + \since 6.3 + + Returns this byte array view converted to an \c {unsigned short} using base + \a base, which is ten by default. Bases 0 and 2 through 36 are supported, + using letters for digits beyond 9; A is ten, B is eleven and so on. + + If \a base is 0, the base is determined automatically using the following + rules: if the byte array view begins with "0x", the rest of it is read as + hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is + read as octal (base 8); otherwise it is read as decimal. + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. +*/ + +/*! + \fn double QByteArrayView::toDouble(bool *ok) const + \since 6.3 + + Returns this byte array view converted to a \c double value. + + Returns an infinity if the conversion overflows or 0.0 if the + conversion fails for other reasons (e.g. underflow). + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \warning The QByteArrayView content may only contain valid numerical + characters which includes the plus/minus sign, the character e used in + scientific notation, and the decimal point. Including the unit or additional + characters leads to a conversion error. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. + + This function ignores leading and trailing spacing characters. +*/ + +/*! + \fn float QByteArrayView::toFloat(bool *ok) const + \since 6.3 + + Returns this byte array view converted to a \c float value. + + Returns an infinity if the conversion overflows or 0.0 if the + conversion fails for other reasons (e.g. underflow). + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \snippet code/src_corelib_text_qbytearrayview.cpp 4 + + \warning The QByteArrayView content may only contain valid numerical + characters which includes the plus/minus sign, the character e used in + scientific notation, and the decimal point. Including the unit or additional + characters leads to a conversion error. + + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. + + This function ignores leading and trailing whitespace. +*/ + +/*! \fn bool QByteArrayView::startsWith(QByteArrayView bv) const \fn bool QByteArrayView::startsWith(char ch) const |