diff --git a/src/corelib/text/qbytearraymatcher.cpp b/src/corelib/text/qbytearraymatcher.cpp index 4292064de2..ca1791c18b 100644 --- a/src/corelib/text/qbytearraymatcher.cpp +++ b/src/corelib/text/qbytearraymatcher.cpp @@ -131,7 +131,10 @@ QByteArrayMatcher::QByteArrayMatcher() QByteArrayMatcher::QByteArrayMatcher(const char *pattern, qsizetype length) : d(nullptr) { p.p = reinterpret_cast(pattern); - p.l = length; + if (length < 0) + p.l = qstrlen(pattern); + else + p.l = length; bm_init_skiptable(p.p, p.l, p.q_skiptable); } @@ -147,6 +150,15 @@ QByteArrayMatcher::QByteArrayMatcher(const QByteArray &pattern) bm_init_skiptable(p.p, p.l, p.q_skiptable); } +/*! + \fn QByteArrayMatcher::QByteArrayMatcher(QByteArrayView pattern) + \since 6.3 + \overload + + Constructs a byte array matcher that will search for \a pattern. + Call indexIn() to perform a search. +*/ + /*! Copies the \a other byte array matcher to this byte array matcher. */ @@ -218,6 +230,18 @@ qsizetype QByteArrayMatcher::indexIn(const char *str, qsizetype len, qsizetype f p.p, p.l, p.q_skiptable); } +/*! + \fn qsizetype QByteArrayMatcher::indexIn(QByteArrayView data, qsizetype from) const + \since 6.3 + \overload + + Searches the byte array \a view, from byte position \a from (default + 0, i.e. from the first byte), for the byte array pattern() that + was set in the constructor or in the most recent call to + setPattern(). Returns the position where the pattern() matched in + \a data, or -1 if no match was found. +*/ + /*! \fn QByteArray QByteArrayMatcher::pattern() const diff --git a/src/corelib/text/qbytearraymatcher.h b/src/corelib/text/qbytearraymatcher.h index db6c06128c..d9ea638500 100644 --- a/src/corelib/text/qbytearraymatcher.h +++ b/src/corelib/text/qbytearraymatcher.h @@ -54,7 +54,10 @@ class Q_CORE_EXPORT QByteArrayMatcher public: QByteArrayMatcher(); explicit QByteArrayMatcher(const QByteArray &pattern); - explicit QByteArrayMatcher(const char *pattern, qsizetype length); + explicit QByteArrayMatcher(QByteArrayView pattern) + : QByteArrayMatcher(pattern.data(), pattern.size()) + {} + explicit QByteArrayMatcher(const char *pattern, qsizetype length = -1); QByteArrayMatcher(const QByteArrayMatcher &other); ~QByteArrayMatcher(); @@ -64,6 +67,10 @@ public: qsizetype indexIn(const QByteArray &ba, qsizetype from = 0) const; qsizetype indexIn(const char *str, qsizetype len, qsizetype from = 0) const; + qsizetype indexIn(QByteArrayView data, qsizetype from = 0) const + { + return indexIn(data.data(), data.size(), from); + } inline QByteArray pattern() const { if (q_pattern.isNull())