6.0.0-rc4Source

QLatin1StringMatcher Class

The QLatin1StringMatcher class searches for a Latin-1 pattern in Latin-1 and UTF-16 text. More…

Header#include <QLatin1StringMatcher>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since6.5

List of all members, including inherited members

Public Functions

Detailed Description

The matcher prepares a skip table for the pattern once, which makes it faster than QLatin1StringView::indexOf() for a pattern that is searched for many times:

QLatin1StringMatcher matcher("content-length"_L1, Qt::CaseInsensitive);
for (QLatin1StringView line : headerLines)
    if (matcher.indexIn(line) == 0)
        readLength(line);

The matcher keeps a view of the pattern and not a copy, so the characters of the pattern must stay valid for as long as the matcher is used.

See also QStringMatcher and QByteArrayMatcher.

Differences from Qt

The matcher uses the Boyer-Moore-Horspool algorithm. Case-insensitive matching folds the letters of Latin-1 only; a character of a UTF-16 text that is outside Latin-1, such as the Kelvin sign, never matches.

Member Function Documentation

QLatin1StringMatcher::QLatin1StringMatcher()

Constructs a matcher with an empty pattern. Call setPattern() to give it one.

[explicit] QLatin1StringMatcher::QLatin1StringMatcher(QLatin1StringView pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive)

Constructs a matcher that searches for pattern with the case sensitivity cs.

Qt::CaseSensitivity QLatin1StringMatcher::caseSensitivity() const

Returns the case sensitivity of the matcher.

See also setCaseSensitivity().

qsizetype QLatin1StringMatcher::indexIn(QLatin1StringView haystack, qsizetype from = 0) const

Searches 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. An empty pattern is found at from.

qsizetype QLatin1StringMatcher::indexIn(QStringView haystack, qsizetype from = 0) const

This is an overloaded function.

Searches the UTF-16 text haystack from index position from. The result counts UTF-16 code units.

This function was introduced in 6.8.

QLatin1StringView QLatin1StringMatcher::pattern() const

Returns the pattern that the matcher searches for.

See also setPattern().

void QLatin1StringMatcher::setCaseSensitivity(Qt::CaseSensitivity cs)

Sets the case sensitivity of the matcher to cs.

See also caseSensitivity().

void QLatin1StringMatcher::setPattern(QLatin1StringView pattern)

Sets the pattern to search for to pattern. The matcher views the characters and does not copy them.

See also pattern().