QStaticLatin1StringMatcher Class
template <Qt::CaseSensitivity CS, size_t N> class QStaticLatin1StringMatcherQStaticLatin1StringMatcher 类是QLatin1StringMatcher 的编译时版本。更多...
头文件: | #include <QStaticLatin1StringMatcher> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
自 | Qt 6.7 |
- 所有成员的列表,包括继承成员
- QStaticLatin1StringMatcher 属于字符串数据类。
公共函数
qsizetype | indexIn(QLatin1StringView haystack, qsizetype from = 0) const |
qsizetype | indexIn(QStringView haystack, qsizetype from = 0) const |
相关非成员
(since 6.7) auto | qMakeStaticCaseInsensitiveLatin1StringMatcher(const char (&)[N] patternToMatch) |
(since 6.7) auto | qMakeStaticCaseSensitiveLatin1StringMatcher(const char (&)[N] patternToMatch) |
详细说明
当您的代码需要在 Latin-1 字符串中高效搜索编译时已知的子串时,该类非常有用。例如,这在解析器中很常见。使用匹配器对象的indexIn() 比使用要搜索的字符串的 indexOf() 成员方法更快,尤其是当要搜索的字符串将被重复搜索或在一个可能包含许多与要搜索的子串前缀匹配的大型 Latin-1 字符串中搜索时。
与QLatin1StringMatcher 不同,该类会在编译时计算内部表示法,因此即使是进行一次性的 Latin-1 字符串匹配,该类也能发挥作用。
通过调用qMakeStaticCaseSensitiveLatin1StringMatcher() 或qMakeStaticCaseInsensitiveLatin1StringMatcher() 函数来创建 QStaticLatin1StringMatcher,并将要搜索的 Latin-1 字符串作为 C 字符串字面形式传入。将该函数的返回值存储在static constexpr auto
变量中,因此无需明确传递N
模板参数。
然后在要搜索的QLatin1StringView 上调用indexIn() ,就像QLatin1StringMatcher 一样。
由于该类的设计目的是在编译时进行所有前期计算,因此不提供 setPattern() 或 setCaseSensitivity() 方法。
注: 目前不支持 INTEGRITY 操作系统。
另请参阅 QLatin1StringMatcher,QStaticByteArrayMatcher, 和QByteArrayMatcher 。
成员函数文档
[constexpr noexcept]
qsizetype QStaticLatin1StringMatcher::indexIn(QLatin1StringView haystack, qsizetype from = 0) const
[constexpr noexcept]
qsizetype QStaticLatin1StringMatcher::indexIn(QStringView haystack, qsizetype from = 0) const
从from (默认为 0,即从第一个字节开始)的字节位置开始,搜索QLatin1StringView haystack ,以查找在构造函数中设置的QLatin1StringView pattern()。使用构造函数中设置的大小写敏感性。
返回模式()在haystack 中匹配的位置,如果没有找到匹配,则返回-1。
相关非成员
[constexpr noexcept, since 6.7]
template <size_t N> auto qMakeStaticCaseInsensitiveLatin1StringMatcher(const char (&)[N] patternToMatch)
返回一个QStaticLatin1StringMatcher ,其正确的N
会根据所传递的patternToMatch 自动确定,且不区分大小写。
要充分利用此函数,请将结果赋值给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 ,其正确的N
会根据传递的patternToMatch 自动确定,并区分大小写。
要充分利用此函数,请将结果赋值给static constexpr auto
变量:
static constexpr auto matcher = qMakeStaticCaseSensitiveLatin1StringViewMatcher("needle");
此函数在 Qt 6.7 中引入。
© 2025 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.