QStaticLatin1StringMatcher Class
template <Qt::CaseSensitivity CS, size_t N> class QStaticLatin1StringMatcherThe QStaticLatin1StringMatcher class is a compile-time version of QLatin1StringMatcher. More...
Header: | #include <QStaticLatin1StringMatcher> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Since: | Qt 6.7 |
- List of all members, including inherited members
- QStaticLatin1StringMatcher is part of Classes for String Data.
Public Functions
qsizetype | indexIn(QLatin1StringView haystack, qsizetype from = 0) const |
qsizetype | indexIn(QStringView haystack, qsizetype from = 0) const |
Related Non-Members
(since 6.7) auto | qMakeStaticCaseInsensitiveLatin1StringMatcher(const char (&)[N] patternToMatch) |
(since 6.7) auto | qMakeStaticCaseSensitiveLatin1StringMatcher(const char (&)[N] patternToMatch) |
Detailed Description
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.
Unlike 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() or 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.
Note: INTEGRITY operating system is currently not supported.
See also QLatin1StringMatcher, QStaticByteArrayMatcher, and QByteArrayMatcher.
Member Function Documentation
[constexpr noexcept]
qsizetype QStaticLatin1StringMatcher::indexIn(QLatin1StringView haystack, qsizetype from = 0) const
[constexpr noexcept]
qsizetype QStaticLatin1StringMatcher::indexIn(QStringView 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.
Related Non-Members
[constexpr noexcept, since 6.7]
template <size_t N> auto qMakeStaticCaseInsensitiveLatin1StringMatcher(const char (&)[N] patternToMatch)
Return a 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
variable:
static constexpr auto matcher = qMakeStaticCaseInsensitiveLatin1StringViewMatcher("needle");
This function was introduced in Qt 6.7.
[constexpr noexcept, since 6.7]
template <size_t N> auto qMakeStaticCaseSensitiveLatin1StringMatcher(const char (&)[N] patternToMatch)
Return a 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
variable:
static constexpr auto matcher = qMakeStaticCaseSensitiveLatin1StringViewMatcher("needle");
This function was introduced in Qt 6.7.
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.