QByteArrayMatcher Class
The QByteArrayMatcher class holds a sequence of bytes that can be quickly matched in a byte array. More…
| Header | #include <QByteArrayMatcher> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QByteArrayMatcher() | |
| QByteArrayMatcher(const QByteArray &pattern) | |
| QByteArrayMatcher(QByteArrayView pattern) | |
| QByteArrayMatcher(const char *pattern, qsizetype length = -1) | |
| void | setPattern(const QByteArray &pattern) |
| QByteArray | pattern() const |
| qsizetype | indexIn(const char *str, qsizetype len, qsizetype from = 0) const |
| qsizetype | indexIn(QByteArrayView data, qsizetype from = 0) const |
Detailed Description
Searching for the same bytes in many byte arrays, or many times in one, is faster with a QByteArrayMatcher than with QByteArray::indexOf(), because the matcher prepares a skip table for the pattern once:
QByteArrayMatcher matcher("\r\n\r\n");
const qsizetype endOfHeaders = matcher.indexIn(request);
See also QStaticByteArrayMatcher, QByteArray::indexOf() and QStringMatcher.
Differences from Qt
The matcher uses the Boyer-Moore-Horspool algorithm. There is no indexIn() overload that takes a QByteArray: the one that takes a QByteArrayView accepts a byte array too.
Member Function Documentation
QByteArrayMatcher::QByteArrayMatcher()
Constructs a matcher with an empty pattern. Call setPattern() to give it one.
QByteArrayMatcher::QByteArrayMatcher(const QByteArray &pattern)
Constructs a matcher that searches for pattern.
QByteArrayMatcher::QByteArrayMatcher(QByteArrayView pattern)
This is an overloaded function.
Constructs a matcher that searches for a copy of the bytes viewed by pattern.
This function was introduced in 5.12.
QByteArrayMatcher::QByteArrayMatcher(const char *pattern, qsizetype length = -1)
This is an overloaded function.
Constructs a matcher that searches for the length bytes at pattern. If length is negative, pattern is taken up to its terminating zero.
qsizetype QByteArrayMatcher::indexIn(const char *str, qsizetype len, qsizetype from = 0) const
Searches the len bytes at str from index position from (default 0) and returns the index of the first occurrence of the pattern, or -1 if it is not found. An empty pattern is found at from.
qsizetype QByteArrayMatcher::indexIn(QByteArrayView data, qsizetype from = 0) const
This is an overloaded function.
Searches the bytes viewed by data from index position from.
This function was introduced in 6.3.
QByteArray QByteArrayMatcher::pattern() const
Returns the bytes that the matcher searches for.
See also setPattern().
void QByteArrayMatcher::setPattern(const QByteArray &pattern)
Sets the bytes to search for to pattern.