diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-09 15:19:02 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-11 22:32:42 +0200 |
commit | 6f833eff92fe703a13214a0c1a593d94e51847d1 (patch) | |
tree | c90f1862030c850cfe6b22e47a458c055a16e833 /src | |
parent | 761f32ae2ad98e8fb12a4f05b45b4aa277e47a1b (diff) |
Add QByteArrayView::trimmed()
Unlike simplified(), it just moves the end-points, without needing to
modify contents, so it makes sense (as for QStringView and
QLatin1String) to provide it. Moved QByteArray's trimmed() tests to
tst_QByteArrayApiSymmetry so that QBAV can now share them.
[ChangeLog][QtCore][QByteArrayView] Added trimmed().
Change-Id: Ifd7a752adb5f3d3e2ad0aa8220efa7e7d2d39baa
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 7 | ||||
-rw-r--r-- | src/corelib/text/qbytearrayalgorithms.h | 4 | ||||
-rw-r--r-- | src/corelib/text/qbytearrayview.h | 5 | ||||
-rw-r--r-- | src/corelib/text/qbytearrayview.qdoc | 17 |
4 files changed, 30 insertions, 3 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index d97375897d..23db7db3e2 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -3390,6 +3390,13 @@ QByteArray QByteArray::trimmed_helper(QByteArray &a) return QStringAlgorithms<QByteArray>::trimmed_helper(a); } +QByteArrayView QtPrivate::trimmed(QByteArrayView view) noexcept +{ + auto start = view.begin(); + auto stop = view.end(); + QStringAlgorithms<QByteArrayView>::trimmed_helper_positions(start, stop); + return QByteArrayView(start, stop); +} /*! Returns a byte array of size \a width that contains this byte array padded diff --git a/src/corelib/text/qbytearrayalgorithms.h b/src/corelib/text/qbytearrayalgorithms.h index be1e6cc953..638af2948b 100644 --- a/src/corelib/text/qbytearrayalgorithms.h +++ b/src/corelib/text/qbytearrayalgorithms.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -72,6 +72,8 @@ qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept; [[nodiscard]] Q_CORE_EXPORT int compareMemory(QByteArrayView lhs, QByteArrayView rhs); +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QByteArrayView trimmed(QByteArrayView s) noexcept; + } // namespace QtPrivate /***************************************************************************** diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 9d35e21415..1dfc65b4c4 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -240,6 +240,9 @@ public: constexpr void chop(qsizetype n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } + [[nodiscard]] QByteArrayView trimmed() const noexcept + { return QtPrivate::trimmed(*this); } + [[nodiscard]] bool startsWith(QByteArrayView other) const noexcept { return QtPrivate::startsWith(*this, other); } [[nodiscard]] bool startsWith(char c) const noexcept diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc index 30d8d47685..740734ebbd 100644 --- a/src/corelib/text/qbytearrayview.qdoc +++ b/src/corelib/text/qbytearrayview.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -620,6 +620,21 @@ */ /*! + \fn QByteArrayView QByteArrayView::trimmed() const noexcept + \since 6.3 + + Returns a copy of this byte array view with spacing characters + removed from the start and end. + + The spacing characters are those for which the standard C++ \c isspace() + function returns \c true in the C locale; these are the ASCII characters + tabulation '\\t', line feed '\\n', carriage return '\\r', vertical + tabulation '\\v', form feed '\\f', and space ' '. + + \sa QChar::SpecialCharacter, {QByteArray#Spacing Characters}{Spacing Characters} +*/ + +/*! \fn bool QByteArrayView::startsWith(QByteArrayView bv) const \fn bool QByteArrayView::startsWith(char ch) const |