File 0001-QByteArray-add-slice-methods.patch of Package qt6-base.40448
From 8f68bd9e6353a42d3b71d893b27fec6bedced501 Mon Sep 17 00:00:00 2001
From: Ahmad Samir <a.samirh78@gmail.com>
Date: Sun, 2 Jul 2023 02:39:48 +0300
Subject: String Views: add slice() methods
Methods with preconditions can't be noexcept (from Marc in code
review).
[ChangeLog][QtCore][String Views] Added slice() methods to
Q{String,ByteArray,Latin1String,Utf8String,AnyString}View which work
like sliced() but modify the view they are called on.
Found in API review.
Pick-to: 6.8
Task-number: QTBUG-99218
Change-Id: Ic8ef3085f7cfac86b8404fb28d491ca38ad121eb
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
---
src/corelib/text/qbytearrayview.h | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'src/corelib/text/qbytearrayview.h')
diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h
index 34e38a36ffb..d55902537c4 100644
--- a/src/corelib/text/qbytearrayview.h
+++ b/src/corelib/text/qbytearrayview.h
@@ -205,6 +205,12 @@ public:
# { 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); }
{ Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QByteArrayView(data() + pos, size() - pos); }
[[nodiscard]] constexpr QByteArrayView sliced(qsizetype pos, qsizetype n) const
{ Q_ASSERT(pos >= 0); Q_ASSERT(n >= 0); Q_ASSERT(size_t(pos) + size_t(n) <= size_t(size())); return QByteArrayView(data() + pos, n); }
+
+ constexpr QByteArrayView &slice(qsizetype pos)
+ { *this = sliced(pos); return *this; }
+ constexpr QByteArrayView &slice(qsizetype pos, qsizetype n)
+ { *this = sliced(pos, n); return *this; }
+
[[nodiscard]] constexpr QByteArrayView chopped(qsizetype len) const
{ Q_ASSERT(len >= 0); Q_ASSERT(len <= size()); return first(size() - len); }
# [[nodiscard]] constexpr QByteArrayView chopped(qsizetype len) const
# { verify(0, len); return sliced(0, size() - len); }
#
--
cgit v1.2.3