Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QLatin1StringMatcher Class Reference

\inmodule QtCore More...

#include <qlatin1stringmatcher.h>

+ Collaboration diagram for QLatin1StringMatcher:

Public Member Functions

Q_CORE_EXPORT QLatin1StringMatcher () noexcept
 Construct an empty Latin-1 string matcher.
 
Q_CORE_EXPORT QLatin1StringMatcher (QLatin1StringView pattern, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
 Constructs a Latin-1 string matcher that searches for the given pattern with given case sensitivity cs.
 
Q_CORE_EXPORT ~QLatin1StringMatcher () noexcept
 Destroys the Latin-1 string matcher.
 
Q_CORE_EXPORT void setPattern (QLatin1StringView pattern) noexcept
 Sets the pattern to search for.
 
Q_CORE_EXPORT QLatin1StringView pattern () const noexcept
 Returns the Latin-1 pattern that the matcher searches for.
 
Q_CORE_EXPORT void setCaseSensitivity (Qt::CaseSensitivity cs) noexcept
 Sets the case sensitivity to cs.
 
Q_CORE_EXPORT Qt::CaseSensitivity caseSensitivity () const noexcept
 Returns the case sensitivity the matcher uses.
 
Q_CORE_EXPORT qsizetype indexIn (QLatin1StringView haystack, qsizetype from=0) const noexcept
 Searches for the pattern in the given haystack starting from from.
 
Q_CORE_EXPORT qsizetype indexIn (QStringView haystack, qsizetype from=0) const noexcept
 

Detailed Description

\inmodule QtCore

Optimized search for substring in Latin-1 text.

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

Since
6.5

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, QByteArrayMatcher

Definition at line 140 of file qlatin1stringmatcher.h.

Constructor & Destructor Documentation

◆ QLatin1StringMatcher() [1/2]

QLatin1StringMatcher::QLatin1StringMatcher ( )
noexcept

Construct an empty Latin-1 string matcher.

This will match at each position in any string.

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

Definition at line 45 of file qlatin1stringmatcher.cpp.

◆ QLatin1StringMatcher() [2/2]

QLatin1StringMatcher::QLatin1StringMatcher ( QLatin1StringView pattern,
Qt::CaseSensitivity cs = Qt::CaseSensitive )
explicitnoexcept

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.

Definition at line 58 of file qlatin1stringmatcher.cpp.

◆ ~QLatin1StringMatcher()

QLatin1StringMatcher::~QLatin1StringMatcher ( )
noexcept

Destroys the Latin-1 string matcher.

Definition at line 68 of file qlatin1stringmatcher.cpp.

Member Function Documentation

◆ caseSensitivity()

Qt::CaseSensitivity QLatin1StringMatcher::caseSensitivity ( ) const
noexcept

Returns the case sensitivity the matcher uses.

See also
setCaseSensitivity(), indexIn()

Definition at line 150 of file qlatin1stringmatcher.cpp.

◆ indexIn() [1/2]

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

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

See also
caseSensitivity(), pattern()

Definition at line 161 of file qlatin1stringmatcher.cpp.

◆ indexIn() [2/2]

qsizetype QLatin1StringMatcher::indexIn ( QStringView haystack,
qsizetype from = 0 ) const
noexcept
Since
6.8 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

See also
caseSensitivity(), pattern()

Definition at line 175 of file qlatin1stringmatcher.cpp.

◆ pattern()

QLatin1StringView QLatin1StringMatcher::pattern ( ) const
noexcept

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

See also
setPattern(), indexIn()

Definition at line 125 of file qlatin1stringmatcher.cpp.

◆ setCaseSensitivity()

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

Sets the case sensitivity to cs.

See also
caseSensitivity(), indexIn()

Definition at line 135 of file qlatin1stringmatcher.cpp.

◆ setPattern()

void QLatin1StringMatcher::setPattern ( QLatin1StringView pattern)
noexcept

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(), indexIn()

Definition at line 110 of file qlatin1stringmatcher.cpp.

Member Data Documentation

◆ m_caseInsensitiveSearcher

CaseInsensitiveSearcher QLatin1StringMatcher::m_caseInsensitiveSearcher

Definition at line 170 of file qlatin1stringmatcher.h.

◆ m_caseSensitiveSearcher

CaseSensitiveSearcher QLatin1StringMatcher::m_caseSensitiveSearcher

Definition at line 169 of file qlatin1stringmatcher.h.


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