6.0.0-rc4Source

QStaticByteArrayMatcher Class

template <std::size_t N> class QStaticByteArrayMatcher

The QStaticByteArrayMatcher class is a QByteArrayMatcher whose pattern is known when the program is compiled. More…

Header#include <QStaticByteArrayMatcher>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since5.9

List of all members, including inherited members

Public Functions

QStaticByteArrayMatcher(const char (&pattern)[N])
qsizetypeindexIn(const char *haystack, qsizetype hlen, qsizetype from = 0) const
qsizetypeindexIn(QByteArrayView haystack, qsizetype from = 0) const
QByteArraypattern() const

Detailed Description

The skip table is computed by the compiler, so a matcher that is constexpr costs nothing when the program starts. N is the size of the string literal with its terminating zero; let qMakeStaticByteArrayMatcher() deduce it:

static constexpr auto matcher = qMakeStaticByteArrayMatcher("needle");
const qsizetype at = matcher.indexIn(haystack);

See also QByteArrayMatcher.

Differences from Qt

There is no indexIn() overload that takes a QByteArray: the one that takes a QByteArrayView accepts a byte array too.

Member Function Documentation

[explicit, constexpr] QStaticByteArrayMatcher::QStaticByteArrayMatcher(const char (&pattern)[N])

Constructs a matcher that searches for the string literal pattern, without its terminating zero.

[constexpr] qsizetype QStaticByteArrayMatcher::indexIn(const char *haystack, qsizetype hlen, qsizetype from = 0) const

Searches the hlen bytes at haystack from index position from (default 0) and returns the index of the first occurrence of the pattern, or -1 if it is not found.

qsizetype QStaticByteArrayMatcher::indexIn(QByteArrayView haystack, qsizetype from = 0) const

This is an overloaded function.

Searches the bytes viewed by haystack from index position from.

This function was introduced in 6.3.

QByteArray QStaticByteArrayMatcher::pattern() const

Returns the bytes that the matcher searches for.