QStaticByteArrayMatcher Class

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

Header: #include <QStaticByteArrayMatcher>
qmake: QT += core
Since: Qt 5.9

Detailed Description

The QStaticByteArrayMatcher class is a compile-time version of QByteArrayMatcher

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, if your compiler supports C++14-level constexpr (C++11 is not sufficient), 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:

static const auto matcher = qMakeStaticByteArrayMatcher("needle");

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 and QStringMatcher.

© 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.