diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2022-11-17 14:04:29 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2022-12-02 20:53:01 +0100 |
commit | e35cf5ebdcabdb79f675780ed9ab985aacf4b7df (patch) | |
tree | 64ddf981915158dab00cc5542f5e9923ee8d72d1 /src/corelib/text/qbytearrayview.h | |
parent | acb012558b2b1e63992a01102f57dd86d6049518 (diff) |
QByteArrayView: Add mid/left/right
Because they are too convenient to leave out.
Change-Id: I844cfb794ce0f575c2c65075d9051b0b878a434f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qbytearrayview.h')
-rw-r--r-- | src/corelib/text/qbytearrayview.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index e0e318249c..ad3bfbdaeb 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -5,6 +5,7 @@ #include <QtCore/qbytearrayalgorithms.h> #include <QtCore/qstringfwd.h> +#include <QtCore/qarraydata.h> #include <string> @@ -198,6 +199,18 @@ public: [[nodiscard]] constexpr QByteArrayView chopped(qsizetype len) const { Q_ASSERT(len >= 0); Q_ASSERT(len <= size()); return first(size() - len); } + [[nodiscard]] constexpr QByteArrayView left(qsizetype n) const + { if (n < 0 || n > size()) n = size(); return QByteArrayView(data(), n); } + [[nodiscard]] constexpr QByteArrayView right(qsizetype n) const + { if (n < 0 || n > size()) n = size(); if (n < 0) n = 0; return QByteArrayView(data() + size() - n, n); } + [[nodiscard]] constexpr QByteArrayView mid(qsizetype pos, qsizetype n = -1) const + { + using namespace QtPrivate; + auto result = QContainerImplHelper::mid(size(), &pos, &n); + return result == QContainerImplHelper::Null ? QByteArrayView() + : QByteArrayView(m_data + pos, n); + } + constexpr void truncate(qsizetype n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size = n; } constexpr void chop(qsizetype n) |