QStaticLatin1StringMatcher Class

template <Qt::CaseSensitivity CS, size_t N> class QStaticLatin1StringMatcher

The QStaticLatin1StringMatcher class is a compile-time version of QLatin1StringMatcher . 更多...

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

公共函数

qsizetype indexIn (QLatin1StringView haystack , qsizetype from = 0) const
(从 6.7 起) auto qMakeStaticCaseInsensitiveLatin1StringMatcher (const char (&)[N] patternToMatch )
(从 6.7 起) auto qMakeStaticCaseSensitiveLatin1StringMatcher (const char (&)[N] patternToMatch )

详细描述

This class is useful when your code needs to search efficiently in Latin-1 strings for a substring that's known at compile-time. This is common, for example, in parsers. Using a matcher object's indexIn () is faster than using the indexOf() member method of the string you are searching in, especially when the string to be found will be searched for repeatedly or within a large Latin-1 string that may contain many matches to prefixes of the substring to be found.

不像 QLatin1StringMatcher , this class calculates the internal representation at compile-time , so it can be beneficial even if you are doing one-off Latin-1 string matches.

Create the QStaticLatin1StringMatcher by calling qMakeStaticCaseSensitiveLatin1StringMatcher () 或 qMakeStaticCaseInsensitiveLatin1StringMatcher () passing the Latin-1 string to search for as a C string literal. Store the return value of that function in a static constexpr auto variable, so you don't need to pass the N template parameter explicitly.

Then call indexIn () on the QLatin1StringView in which you want to search, just like with QLatin1StringMatcher .

Since this class is designed to do all the up-front calculations at compile-time, it does not offer setPattern() or setCaseSensitivity() methods.

注意: INTEGRITY operating system is currently not supported.

另请参阅 QLatin1StringMatcher , QStaticByteArrayMatcher ,和 QByteArrayMatcher .

成员函数文档编制

[constexpr noexcept] qsizetype QStaticLatin1StringMatcher:: indexIn ( QLatin1StringView haystack , qsizetype from = 0) const

Searches the QLatin1StringView haystack , from byte position from (default 0, i.e. from the first byte), for QLatin1StringView pattern() that was set in the constructor. Using the case sensitivity that was also set in the constructor.

Returns the position where the pattern() matched in haystack , or -1 if no match was found.

相关非成员

[constexpr noexcept, since 6.7] template <size_t N> auto qMakeStaticCaseInsensitiveLatin1StringMatcher (const char (&)[ N ] patternToMatch )

返回 QStaticLatin1StringMatcher with the correct N determined automatically from the patternToMatch passed, and without case sensitivity.

To take full advantage of this function, assign the result to a static constexpr auto 变量:

static constexpr auto matcher = qMakeStaticCaseInsensitiveLatin1StringViewMatcher("needle");
					

该函数在 Qt 6.7 引入。

[constexpr noexcept, since 6.7] template <size_t N> auto qMakeStaticCaseSensitiveLatin1StringMatcher (const char (&)[ N ] patternToMatch )

返回 QStaticLatin1StringMatcher with the correct N determined automatically from the patternToMatch passed, and with case sensitivity.

To take full advantage of this function, assign the result to a static constexpr auto 变量:

static constexpr auto matcher = qMakeStaticCaseSensitiveLatin1StringViewMatcher("needle");
					

该函数在 Qt 6.7 引入。