QLatin1StringMatcher Class | Qt Core 6.7.3
Description: Optimized search for substring in Latin-1 text.

- Qt 6.7
- Qt Core
- C++ Classes
- QLatin1StringMatcher
- Qt 6.7.3 Reference Documentation

# QLatin1StringMatcher Class

Optimized search for substring in Latin-1 text. More...

Header: | #include <QLatin1StringMatcher>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: | QT += core
Since: | Qt 6.5

- List of all members, including inherited members

## Public Functions

| QLatin1StringMatcher()
| QLatin1StringMatcher(QLatin1StringView pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive)
| ~QLatin1StringMatcher()
Qt::CaseSensitivity | caseSensitivity() const
qsizetype | indexIn(QLatin1StringView haystack, qsizetype from = 0) const
QLatin1StringView | pattern() const
void | setCaseSensitivity(Qt::CaseSensitivity cs)
void | setPattern(QLatin1StringView pattern)

## Detailed Description

A QLatin1StringMatcher can search for one QLatin1StringView as a substring of another, either ignoring case or taking it into account.

This class is useful when you have a Latin-1 encoded string that you want to repeatedly search for in some QLatin1StringViews (perhaps in a loop), or when you want to search for all instances of it in a given QLatin1StringView. Using a matcher object and indexIn() is faster than matching a plain QLatin1StringView with QLatin1StringView::indexOf() if repeated matching takes place. This class offers no benefit if you are doing one-off matches. The string to be searched for must not be destroyed or changed before the matcher object is destroyed, as the matcher accesses the string when searching for it.

Create a QLatin1StringMatcher for the QLatin1StringView you want to search for and the case sensitivity. Then call indexIn() with the QLatin1StringView that you want to search within.

See also QLatin1StringView, QStringMatcher, and QByteArrayMatcher.

## Member Function Documentation

### `[noexcept]` QLatin1StringMatcher::QLatin1StringMatcher()

Construct an empty Latin-1 string matcher. This will match at each position in any string.

See also setPattern(), setCaseSensitivity(), and indexIn().

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

Constructs a Latin-1 string matcher that searches for the given pattern with given case sensitivity cs. The pattern argument must not be destroyed before this matcher object. Call indexIn() to find the pattern in the given QLatin1StringView.

### `[noexcept]` QLatin1StringMatcher::~QLatin1StringMatcher()

Destroys the Latin-1 string matcher.

### `[noexcept]` Qt::CaseSensitivity QLatin1StringMatcher::caseSensitivity() const

Returns the case sensitivity the matcher uses.

See also setCaseSensitivity() and indexIn().

### `[noexcept]` qsizetype QLatin1StringMatcher::indexIn(QLatin1StringView haystack, qsizetype from = 0) const

Searches for the pattern in the given haystack starting from from.

See also caseSensitivity() and pattern().

### `[noexcept]` QLatin1StringView QLatin1StringMatcher::pattern() const

Returns the Latin-1 pattern that the matcher searches for.

See also setPattern() and indexIn().

### `[noexcept]` void QLatin1StringMatcher::setCaseSensitivity(Qt::CaseSensitivity cs)

Sets the case sensitivity to cs.

See also caseSensitivity() and indexIn().

### `[noexcept]` void QLatin1StringMatcher::setPattern(QLatin1StringView pattern)

Sets the pattern to search for. The string pointed to by the QLatin1StringView must not be destroyed before the matcher is destroyed, unless it is set to point to a different pattern with longer lifetime first.

See also pattern() and indexIn().