summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-04-29 12:36:12 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-05-20 17:02:38 +0200
commita5dc381b4c987d933f1207035e275cdc24669de6 (patch)
tree2c79e8c6e1488b3df246e1c7720c831ae8620a85 /src
parente8297ba17602475e0fc94e3a67a625dc5bc8c136 (diff)
QByteArrayView: add compare
There was previously no way to compare QByteArrayView to with another QByteArrayView case-insensitively without allocating memory. [ChangeLog][QtCore][QByteArrayView] Added compare(), enabling case sensitive and insensitive comparison with other QByteArrayViews. Change-Id: I7582cc414563ddbde26da35a568421edcc649f93 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qbytearrayview.h8
-rw-r--r--src/corelib/text/qbytearrayview.qdoc12
2 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h
index 367fdb58b2..9d35e21415 100644
--- a/src/corelib/text/qbytearrayview.h
+++ b/src/corelib/text/qbytearrayview.h
@@ -270,6 +270,8 @@ public:
[[nodiscard]] qsizetype count(char ch) const noexcept
{ return QtPrivate::count(*this, QByteArrayView(&ch, 1)); }
+ inline int compare(QByteArrayView a, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
+
//
// STL compatibility API:
//
@@ -320,6 +322,12 @@ template<typename QByteArrayLike,
[[nodiscard]] inline QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
{ return QByteArrayView(b.data(), b.size()); }
+inline int QByteArrayView::compare(QByteArrayView a, Qt::CaseSensitivity cs) const noexcept
+{
+ return cs == Qt::CaseSensitive ? QtPrivate::compareMemory(*this, a) :
+ qstrnicmp(data(), size(), a.data(), a.size());
+}
+
#if QT_DEPRECATED_SINCE(6, 0)
QT_DEPRECATED_VERSION_X_6_0("Use the QByteArrayView overload.")
inline quint16 qChecksum(const char *s, qsizetype len,
diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc
index 91048c5dad..30d8d47685 100644
--- a/src/corelib/text/qbytearrayview.qdoc
+++ b/src/corelib/text/qbytearrayview.qdoc
@@ -354,6 +354,18 @@
*/
/*!
+ \fn int QByteArrayView::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
+ \since 6.2
+
+ Returns an integer less than, equal to, or greater than zero depending on
+ whether this QByteArrayView sorts before, at the same position as, or after
+ the QByteArrayView \a bv. The comparison is performed according to case
+ sensitivity \a cs.
+
+ \sa operator==()
+*/
+
+/*!
\fn QByteArrayView::const_iterator QByteArrayView::begin() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the