QByteArrayMatcher: add QByteArrayView overloads
The modification to the existing constructor was necessary to avoid ambiguous overloads from plain strings. They'd previously only match QByteArray, but now they match QByteArrayView too. The QByteArray constructor must stay even in Qt 7 because the pattern is stored. The QByteArray indexIn also stays in because of ambiguous overloads. Unless we want to remove the const char* overloads. Change-Id: I2bbf422288924c198645fffd16a92859b67f3978 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
90c54b02f8
commit
f6fa78fd60
@ -131,7 +131,10 @@ QByteArrayMatcher::QByteArrayMatcher()
|
||||
QByteArrayMatcher::QByteArrayMatcher(const char *pattern, qsizetype length) : d(nullptr)
|
||||
{
|
||||
p.p = reinterpret_cast<const uchar *>(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
|
||||
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user