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> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Since | 5.9 |
List of all members, including inherited members
Public Functions
| QStaticByteArrayMatcher(const char (&pattern)[N]) | |
| qsizetype | indexIn(const char *haystack, qsizetype hlen, qsizetype from = 0) const |
| qsizetype | indexIn(QByteArrayView haystack, qsizetype from = 0) const |
| QByteArray | pattern() 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
QStaticByteArrayMatcher::QStaticByteArrayMatcher(const char (&pattern)[N])
Constructs a matcher that searches for the string literal pattern, without its terminating zero.
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.