diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 1ed96118ce..c9e90ce62b 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -157,15 +157,15 @@ public: [[nodiscard]] QByteArray mid(qsizetype index, qsizetype len = -1) const; [[nodiscard]] QByteArray first(qsizetype n) const - { verify(0, n); return QByteArray(data(), n); } + { verify(0, n); return sliced(0, n); } [[nodiscard]] QByteArray last(qsizetype n) const - { verify(0, n); return QByteArray(data() + size() - n, n); } + { verify(0, n); return sliced(size() - n, n); } [[nodiscard]] QByteArray sliced(qsizetype pos) const { verify(pos, 0); return QByteArray(data() + pos, size() - pos); } [[nodiscard]] QByteArray sliced(qsizetype pos, qsizetype n) const { verify(pos, n); return QByteArray(data() + pos, n); } [[nodiscard]] QByteArray chopped(qsizetype len) const - { verify(0, len); return first(size() - len); } + { verify(0, len); return sliced(0, size() - len); } bool startsWith(QByteArrayView bv) const { return QtPrivate::startsWith(qToByteArrayViewIgnoringNull(*this), bv); } diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 2fe358b619..081cdbbd76 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -188,15 +188,15 @@ public: [[nodiscard]] constexpr char at(qsizetype n) const { return (*this)[n]; } [[nodiscard]] constexpr QByteArrayView first(qsizetype n) const - { verify(0, n); return QByteArrayView(data(), n); } + { verify(0, n); return sliced(0, n); } [[nodiscard]] constexpr QByteArrayView last(qsizetype n) const - { verify(0, n); return QByteArrayView(data() + size() - n, n); } + { verify(0, n); return sliced(size() - n, n); } [[nodiscard]] constexpr QByteArrayView sliced(qsizetype pos) const { verify(pos, 0); return QByteArrayView(data() + pos, size() - pos); } [[nodiscard]] constexpr QByteArrayView sliced(qsizetype pos, qsizetype n) const { verify(pos, n); return QByteArrayView(data() + pos, n); } [[nodiscard]] constexpr QByteArrayView chopped(qsizetype len) const - { verify(0, len); return first(size() - len); } + { verify(0, len); return sliced(0, size() - len); } [[nodiscard]] constexpr QByteArrayView left(qsizetype n) const { if (n < 0 || n > size()) n = size(); return QByteArrayView(data(), n); } diff --git a/src/corelib/text/qlatin1stringview.h b/src/corelib/text/qlatin1stringview.h index c705f5ca91..6b58607271 100644 --- a/src/corelib/text/qlatin1stringview.h +++ b/src/corelib/text/qlatin1stringview.h @@ -227,11 +227,11 @@ public: [[nodiscard]] constexpr QLatin1StringView sliced(qsizetype pos, qsizetype n) const { verify(pos, n); return {m_data + pos, n}; } [[nodiscard]] constexpr QLatin1StringView first(qsizetype n) const - { verify(0, n); return {m_data, n}; } + { verify(0, n); return sliced(0, n); } [[nodiscard]] constexpr QLatin1StringView last(qsizetype n) const - { verify(0, n); return {m_data + size() - n, n}; } + { verify(0, n); return sliced(size() - n, n); } [[nodiscard]] constexpr QLatin1StringView chopped(qsizetype n) const - { verify(0, n); return {m_data, size() - n}; } + { verify(0, n); return sliced(0, size() - n); } constexpr void chop(qsizetype n) { verify(0, n); m_size -= n; } diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index cd4af57e13..06c6f668c4 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -336,15 +336,15 @@ public: [[nodiscard]] QString mid(qsizetype position, qsizetype n = -1) const; [[nodiscard]] QString first(qsizetype n) const - { verify(0, n); return QString(data(), n); } + { verify(0, n); return sliced(0, n); } [[nodiscard]] QString last(qsizetype n) const - { verify(0, n); return QString(data() + size() - n, n); } + { verify(0, n); return sliced(size() - n, n); } [[nodiscard]] QString sliced(qsizetype pos) const { verify(pos, 0); return QString(data() + pos, size() - pos); } [[nodiscard]] QString sliced(qsizetype pos, qsizetype n) const { verify(pos, n); return QString(data() + pos, n); } [[nodiscard]] QString chopped(qsizetype n) const - { verify(0, n); return first(size() - n); } + { verify(0, n); return sliced(0, size() - n); } bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 6a1806d602..05e5ec3fdb 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -220,15 +220,15 @@ public: } [[nodiscard]] constexpr QStringView first(qsizetype n) const noexcept - { verify(0, n); return QStringView(m_data, n); } + { verify(0, n); return sliced(0, n); } [[nodiscard]] constexpr QStringView last(qsizetype n) const noexcept - { verify(0, n); return QStringView(m_data + size() - n, n); } + { verify(0, n); return sliced(size() - n, n); } [[nodiscard]] constexpr QStringView sliced(qsizetype pos) const noexcept { verify(pos, 0); return QStringView(m_data + pos, size() - pos); } [[nodiscard]] constexpr QStringView sliced(qsizetype pos, qsizetype n) const noexcept { verify(pos, n); return QStringView(m_data + pos, n); } [[nodiscard]] constexpr QStringView chopped(qsizetype n) const noexcept - { verify(0, n); return QStringView(m_data, m_size - n); } + { verify(0, n); return sliced(0, m_size - n); } constexpr void truncate(qsizetype n) noexcept { verify(0, n); ; m_size = n; } diff --git a/src/corelib/text/qutf8stringview.h b/src/corelib/text/qutf8stringview.h index 4a077ef843..0ea6927005 100644 --- a/src/corelib/text/qutf8stringview.h +++ b/src/corelib/text/qutf8stringview.h @@ -242,11 +242,11 @@ public: [[nodiscard]] constexpr QBasicUtf8StringView sliced(qsizetype pos, qsizetype n) const { verify(pos, n); return QBasicUtf8StringView(m_data + pos, n); } [[nodiscard]] constexpr QBasicUtf8StringView first(qsizetype n) const - { verify(0, n); return QBasicUtf8StringView(m_data, n); } + { verify(0, n); return sliced(0, n); } [[nodiscard]] constexpr QBasicUtf8StringView last(qsizetype n) const - { verify(0, n); return QBasicUtf8StringView(m_data + m_size - n, n); } + { verify(0, n); return sliced(m_size - n, n); } [[nodiscard]] constexpr QBasicUtf8StringView chopped(qsizetype n) const - { verify(0, n); return QBasicUtf8StringView(m_data, m_size - n); } + { verify(0, n); return sliced(0, m_size - n); } constexpr void truncate(qsizetype n) { verify(0, n); m_size = n; }