diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 2f62a3055d..87b2d14916 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -625,7 +625,7 @@ QBitArray QBitArray::operator~() const return QBitArray(*this).inverted_inplace(); } -#include "qbytearray.h" +#include "qbytearray.h" // also includes inlined API QByteArray QByteArray::left(qsizetype len) const { diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 69d21cbe24..a1ae331585 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -2656,6 +2656,11 @@ static inline qsizetype findCharHelper(QByteArrayView haystack, qsizetype from, return -1; } +qsizetype QtPrivate::findByteArray(QByteArrayView haystack, qsizetype from, char needle) noexcept +{ + return findCharHelper(haystack, from, needle); +} + qsizetype QtPrivate::findByteArray(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept { const auto ol = needle.size(); @@ -2690,6 +2695,7 @@ qsizetype QtPrivate::findByteArray(QByteArrayView haystack, qsizetype from, QByt */ /*! + \fn qsizetype QByteArray::indexOf(char ch, qsizetype from) const \overload Returns the index position of the start of the first occurrence of the @@ -2702,11 +2708,6 @@ qsizetype QtPrivate::findByteArray(QByteArrayView haystack, qsizetype from, QByt \sa lastIndexOf(), contains() */ -qsizetype QByteArray::indexOf(char ch, qsizetype from) const -{ - return qToByteArrayViewIgnoringNull(*this).indexOf(ch, from); -} - static qsizetype lastIndexOfHelper(const char *haystack, qsizetype l, const char *needle, qsizetype ol, qsizetype from) { @@ -2760,6 +2761,11 @@ static inline qsizetype lastIndexOfCharHelper(QByteArrayView haystack, qsizetype return -1; } +qsizetype QtPrivate::lastIndexOf(QByteArrayView haystack, qsizetype from, char needle) noexcept +{ + return lastIndexOfCharHelper(haystack, from, needle); +} + qsizetype QtPrivate::lastIndexOf(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept { if (haystack.isEmpty()) { @@ -2813,6 +2819,7 @@ qsizetype QtPrivate::lastIndexOf(QByteArrayView haystack, qsizetype from, QByteA */ /*! + \fn qsizetype QByteArray::lastIndexOf(char ch, qsizetype from) const \overload Returns the index position of the start of the last occurrence of byte \a ch @@ -2826,11 +2833,6 @@ qsizetype QtPrivate::lastIndexOf(QByteArrayView haystack, qsizetype from, QByteA \sa indexOf(), contains() */ -qsizetype QByteArray::lastIndexOf(char ch, qsizetype from) const -{ - return qToByteArrayViewIgnoringNull(*this).lastIndexOf(ch, from); -} - static inline qsizetype countCharHelper(QByteArrayView haystack, char needle) noexcept { qsizetype num = 0; diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index aeeeb15e0e..06d310856b 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -133,10 +133,12 @@ public: [[nodiscard]] char back() const { return at(size() - 1); } [[nodiscard]] inline char &back(); + QT_CORE_INLINE_SINCE(6, 7) qsizetype indexOf(char c, qsizetype from = 0) const; qsizetype indexOf(QByteArrayView bv, qsizetype from = 0) const { return QtPrivate::findByteArray(qToByteArrayViewIgnoringNull(*this), from, bv); } + QT_CORE_INLINE_SINCE(6, 7) qsizetype lastIndexOf(char c, qsizetype from = -1) const; qsizetype lastIndexOf(QByteArrayView bv) const { return lastIndexOf(bv, size()); } @@ -688,6 +690,16 @@ bool QByteArray::isNull() const noexcept return d->isNull(); } #endif +#if QT_CORE_INLINE_IMPL_SINCE(6, 7) +qsizetype QByteArray::indexOf(char ch, qsizetype from) const +{ + return qToByteArrayViewIgnoringNull(*this).indexOf(ch, from); +} +qsizetype QByteArray::lastIndexOf(char ch, qsizetype from) const +{ + return qToByteArrayViewIgnoringNull(*this).lastIndexOf(ch, from); +} +#endif #if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED) Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &); diff --git a/src/corelib/text/qbytearrayalgorithms.h b/src/corelib/text/qbytearrayalgorithms.h index 081fb66f81..db8b239fd8 100644 --- a/src/corelib/text/qbytearrayalgorithms.h +++ b/src/corelib/text/qbytearrayalgorithms.h @@ -25,9 +25,15 @@ bool startsWith(QByteArrayView haystack, QByteArrayView needle) noexcept; [[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QByteArrayView haystack, QByteArrayView needle) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION +qsizetype findByteArray(QByteArrayView haystack, qsizetype from, char needle) noexcept; + [[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findByteArray(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION +qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, char needle) noexcept; + [[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept; diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index d8ad65ae1e..0541436df9 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -263,7 +263,7 @@ public: [[nodiscard]] qsizetype indexOf(QByteArrayView a, qsizetype from = 0) const noexcept { return QtPrivate::findByteArray(*this, from, a); } [[nodiscard]] qsizetype indexOf(char ch, qsizetype from = 0) const noexcept - { return QtPrivate::findByteArray(*this, from, QByteArrayView(&ch, 1)); } + { return QtPrivate::findByteArray(*this, from, ch); } [[nodiscard]] bool contains(QByteArrayView a) const noexcept { return indexOf(a) != qsizetype(-1); } @@ -275,7 +275,7 @@ public: [[nodiscard]] qsizetype lastIndexOf(QByteArrayView a, qsizetype from) const noexcept { return QtPrivate::lastIndexOf(*this, from, a); } [[nodiscard]] qsizetype lastIndexOf(char ch, qsizetype from = -1) const noexcept - { return QtPrivate::lastIndexOf(*this, from, QByteArrayView(&ch, 1)); } + { return QtPrivate::lastIndexOf(*this, from, ch); } [[nodiscard]] qsizetype count(QByteArrayView a) const noexcept { return QtPrivate::count(*this, a); }