QLatin1StringMatcher Class
优化搜索 Latin-1 文本中的子串。更多
头文件: | #include <QLatin1StringMatcher> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
自 | Qt 6.5 |
- 所有成员的列表,包括继承成员
- QLatin1StringMatcher 属于字符串数据类。
公共函数
QLatin1StringMatcher() | |
QLatin1StringMatcher(QLatin1StringView pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive) | |
~QLatin1StringMatcher() | |
Qt::CaseSensitivity | caseSensitivity() const |
qsizetype | indexIn(QLatin1StringView haystack, qsizetype from = 0) const |
(since 6.8) qsizetype | indexIn(QStringView haystack, qsizetype from = 0) const |
QLatin1StringView | pattern() const |
void | setCaseSensitivity(Qt::CaseSensitivity cs) |
void | setPattern(QLatin1StringView pattern) |
详细说明
QLatin1StringMatcher 可以搜索一个QLatin1StringView 作为另一个的子串,可以忽略大小写,也可以考虑大小写。
当您想在某些 QLatin1StringViews(也许是循环)中重复搜索一个拉丁字母 1 编码的字符串,或者想在给定的QLatin1StringView 中搜索该字符串的所有实例时,该类非常有用。如果重复匹配,使用匹配器对象和indexIn() 比使用QLatin1StringView::indexOf() 匹配普通QLatin1StringView 更快。如果进行一次性匹配,该类则没有任何好处。在销毁匹配器对象之前,不能销毁或更改要搜索的字符串,因为匹配器在搜索字符串时会访问该字符串。
为要搜索的QLatin1StringView 和大小写敏感性创建一个 QLatin1StringMatcher。然后使用要搜索的QLatin1StringView 调用indexIn() 。
另请参阅 QLatin1StringView,QStringMatcher, 和QByteArrayMatcher 。
成员函数文档
[noexcept]
QLatin1StringMatcher::QLatin1StringMatcher()
构建一个空的 Latin-1 字符串匹配器。它将匹配任何字符串中的每个位置。
另请参阅 setPattern()、setCaseSensitivity() 和indexIn()。
[explicit noexcept]
QLatin1StringMatcher::QLatin1StringMatcher(QLatin1StringView pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive)
构造一个 Latin-1 字符串匹配器,以给定的大小写敏感性搜索给定的pattern cs 。pattern 参数不得在此匹配器对象之前销毁。调用indexIn() 在给定的QLatin1StringView 中查找pattern 。
[noexcept]
QLatin1StringMatcher::~QLatin1StringMatcher()
销毁 Latin-1 字符串匹配器。
[noexcept]
Qt::CaseSensitivity QLatin1StringMatcher::caseSensitivity() const
返回匹配器使用的大小写敏感性。
另请参阅 setCaseSensitivity() 和indexIn()。
[noexcept]
qsizetype QLatin1StringMatcher::indexIn(QLatin1StringView haystack, qsizetype from = 0) const
从from 开始,在给定的haystack 中搜索模式。
另请参见 caseSensitivity() 和pattern()。
[noexcept, since 6.8]
qsizetype QLatin1StringMatcher::indexIn(QStringView haystack, qsizetype from = 0) const
这是一个重载函数。
从索引位置from 开始,在给定的haystack 中搜索模式。
该函数在 Qt 6.8 中引入。
另请参阅 caseSensitivity() 和pattern()。
[noexcept]
QLatin1StringView QLatin1StringMatcher::pattern() const
返回匹配器搜索的 Latin-1 图案。
另请参阅 setPattern() 和indexIn()。
[noexcept]
void QLatin1StringMatcher::setCaseSensitivity(Qt::CaseSensitivity cs)
将大小写敏感性设置为cs 。
另请参阅 caseSensitivity() 和indexIn()。
[noexcept]
void QLatin1StringMatcher::setPattern(QLatin1StringView pattern)
设置要搜索的pattern 。QLatin1StringView 指向的字符串不得在匹配器被销毁前被销毁,除非它被设置为指向另一个生命周期更长的pattern 。
© 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.