Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QStaticByteArrayMatcher< N > Class Template Reference

The QStaticByteArrayMatcher class is a compile-time version of QByteArrayMatcher. More...

#include <qbytearraymatcher.h>

+ Inheritance diagram for QStaticByteArrayMatcher< N >:
+ Collaboration diagram for QStaticByteArrayMatcher< N >:

Public Member Functions

constexpr QStaticByteArrayMatcher (const char(&patternToMatch)[N]) noexcept
 
Q_WEAK_OVERLOAD qsizetype indexIn (const QByteArray &haystack, qsizetype from=0) const noexcept
 Searches the char string haystack, from byte position from (default 0, i.e.
 
qsizetype indexIn (const char *haystack, qsizetype hlen, qsizetype from=0) const noexcept
 Searches the char string haystack, which has length hlen, from byte position from (default 0, i.e.
 
qsizetype indexIn (QByteArrayView haystack, qsizetype from=0) const noexcept
 
QByteArray pattern () const
 Returns the byte array pattern that this byte array matcher will search for.
 

Related Symbols

(Note that these are not member symbols.)

template< size_t N > QStaticByteArrayMatcher qMakeStaticByteArrayMatcher (const char(&pattern)[N])
 

Detailed Description

template<size_t N>
class QStaticByteArrayMatcher< N >

The QStaticByteArrayMatcher class is a compile-time version of QByteArrayMatcher.

Since
5.9 \inmodule QtCore

This class is useful when you have a sequence of bytes that you want to repeatedly match against some byte arrays (perhaps in a loop), or when you want to search for the same sequence of bytes multiple times in the same byte array. Using a matcher object and indexIn() is faster than matching a plain QByteArray with QByteArray::indexOf(), in particular if repeated matching takes place.

Unlike QByteArrayMatcher, this class calculates the internal representation at {compile-time}, so it can even benefit if you are doing one-off byte array matches.

Create the QStaticByteArrayMatcher by calling qMakeStaticByteArrayMatcher(), passing it the C string literal you want to search for. Store the return value of that function in a {static const auto} variable, so you don't need to pass the {N} template parameter explicitly:

Then call indexIn() on the QByteArray in which you want to search, just like with QByteArrayMatcher.

Since this class is designed to do all the up-front calculations at compile-time, it does not offer a setPattern() method.

See also
QByteArrayMatcher, QStringMatcher

Definition at line 98 of file qbytearraymatcher.h.

Constructor & Destructor Documentation

◆ QStaticByteArrayMatcher()

template<size_t N>
template< size_t N > QStaticByteArrayMatcher< N >::QStaticByteArrayMatcher ( const char(&) pattern[N])
inlineexplicitconstexprnoexcept

Definition at line 104 of file qbytearraymatcher.h.

References i.

Member Function Documentation

◆ indexIn() [1/3]

template<size_t N>
template< size_t N > qsizetype QStaticByteArrayMatcher< N >::indexIn ( const char * haystack,
qsizetype hlen,
qsizetype from = 0 ) const
inlinenoexcept

Searches the char string haystack, which has length hlen, from byte position from (default 0, i.e.

from the first byte), for the byte array pattern() that was set in the constructor.

Returns the position where the pattern() matched in haystack, or -1 if no match was found.

Definition at line 114 of file qbytearraymatcher.h.

References QStaticByteArrayMatcherBase::indexOfIn().

+ Here is the call graph for this function:

◆ indexIn() [2/3]

template<size_t N>
template< size_t N > qsizetype QStaticByteArrayMatcher< N >::indexIn ( const QByteArray & haystack,
qsizetype from = 0 ) const
inlinenoexcept

Searches the char string haystack, from byte position from (default 0, i.e.

from the first byte), for the byte array pattern() that was set in the constructor.

Returns the position where the pattern() matched in haystack, or -1 if no match was found.

Definition at line 112 of file qbytearraymatcher.h.

References QStaticByteArrayMatcherBase::indexOfIn().

+ Here is the call graph for this function:

◆ indexIn() [3/3]

template<size_t N>
qsizetype QStaticByteArrayMatcher< N >::indexIn ( QByteArrayView haystack,
qsizetype from = 0 ) const
inlinenoexcept

Definition at line 116 of file qbytearraymatcher.h.

References QStaticByteArrayMatcherBase::indexOfIn().

+ Here is the call graph for this function:

◆ pattern()

template<size_t N>
template< size_t N > QByteArray QStaticByteArrayMatcher< N >::pattern ( ) const
inline

Returns the byte array pattern that this byte array matcher will search for.

See also
QByteArrayMatcher::setPattern()

Definition at line 119 of file qbytearraymatcher.h.

References QByteArray().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ qMakeStaticByteArrayMatcher()

template<size_t N>
template< size_t N > QStaticByteArrayMatcher qMakeStaticByteArrayMatcher ( const char(&) pattern[N])
related
Since
5.9

Return a QStaticByteArrayMatcher with the correct {N} determined automatically from the pattern passed.

To take full advantage of this function, assign the result to an {auto} variable:

Definition at line 123 of file qbytearraymatcher.h.


The documentation for this class was generated from the following files: