QLatin1StringMatcher Class

Optimized search for substring in Latin-1 text. 更多...

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

公共函数

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 )

详细描述

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 () 采用 QLatin1StringView that you want to search within.

另请参阅 QLatin1StringView , QStringMatcher ,和 QByteArrayMatcher .

成员函数文档编制

QLatin1StringMatcher:: QLatin1StringMatcher ()

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

另请参阅 setPattern (), setCaseSensitivity (),和 indexIn ().

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 cspattern argument must not be destroyed before this matcher object. Call indexIn () to find the pattern 以给定 QLatin1StringView .

QLatin1StringMatcher:: ~QLatin1StringMatcher ()

Destroys the Latin-1 string matcher.

Qt::CaseSensitivity QLatin1StringMatcher:: caseSensitivity () const

Returns the case sensitivity the matcher uses.

另请参阅 setCaseSensitivity () 和 indexIn ().

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

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

另请参阅 caseSensitivity () 和 pattern ().

QLatin1StringView QLatin1StringMatcher:: pattern () const

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

另请参阅 setPattern () 和 indexIn ().

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

Sets the case sensitivity to cs .

另请参阅 caseSensitivity () 和 indexIn ().

void QLatin1StringMatcher:: setPattern ( QLatin1StringView pattern )

设置 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.

另请参阅 pattern () 和 indexIn ().