QTextBoundaryFinder Class
QTextBoundaryFinder 类提供了一种在字符串中查找 Unicode 文本边界的方法。更多
头文件: | #include <QTextBoundaryFinder> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
- 所有成员(包括继承成员)的列表
- QTextBoundaryFinder 属于隐式共享类和字符串数据类。
注意:该类中的所有函数都是可重入的。
公共类型
enum | BoundaryReason { NotAtBoundary, BreakOpportunity, StartOfItem, EndOfItem, MandatoryBreak, SoftHyphen } |
flags | BoundaryReasons |
enum | BoundaryType { Grapheme, Word, Line, Sentence } |
公共函数
QTextBoundaryFinder() | |
QTextBoundaryFinder(QTextBoundaryFinder::BoundaryType type, const QString &string) | |
(since 6.0) | QTextBoundaryFinder(QTextBoundaryFinder::BoundaryType type, QStringView string, unsigned char *buffer = nullptr, qsizetype bufferSize = 0) |
QTextBoundaryFinder(QTextBoundaryFinder::BoundaryType type, const QChar *chars, qsizetype length, unsigned char *buffer = nullptr, qsizetype bufferSize = 0) | |
QTextBoundaryFinder(const QTextBoundaryFinder &other) | |
~QTextBoundaryFinder() | |
QTextBoundaryFinder::BoundaryReasons | boundaryReasons() const |
bool | isAtBoundary() const |
bool | isValid() const |
qsizetype | position() const |
void | setPosition(qsizetype position) |
QString | string() const |
void | toEnd() |
qsizetype | toNextBoundary() |
qsizetype | toPreviousBoundary() |
void | toStart() |
QTextBoundaryFinder::BoundaryType | type() const |
QTextBoundaryFinder & | operator=(const QTextBoundaryFinder &other) |
详细说明
QTextBoundaryFinder 允许根据 Unicode 文本边界规范(参见Unicode 标准附件 #14和Unicode 标准附件 #29)查找字符串中的 Unicode 文本边界。
QTextBoundaryFinder 可以根据BoundaryType 的值,以四种可能的模式对QString 进行操作。
构成用户所认为的字符或语言基本单位的 Unicode 字符单位在此称为词素簇。例如,两个 Unicode 字符 "A "+重读构成一个词素簇,用户将其视为一个字符,但在这种情况下,它由两个 Unicode 码点表示(见 https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries)。
单词边界用于确定一种语言认为是单词的起点和终点(见 https://www.unicode.org/reports/tr29/#Word_Boundaries)。
换行边界表示可能发生换行的地方,句子边界表示整个句子的开始和结束(见 https://www.unicode.org/reports/tr29/#Sentence_Boundaries和https://www.unicode.org/reports/tr14/)。
字符串中的第一个位置总是有效的边界,指的是第一个字符之前的位置。字符串长度上的最后一个位置也是有效边界,指的是最后一个字符之后的位置。
成员类型文档
枚举 QTextBoundaryFinder::BoundaryReason
flags QTextBoundaryFinder::BoundaryReasons
常量 | 值 | 说明 |
---|---|---|
QTextBoundaryFinder::NotAtBoundary | 0 | 边界查找器不在边界位置。 |
QTextBoundaryFinder::BreakOpportunity | 0x1f | 边界查找器位于断点位置。这种断句机会也可能是条目边界(条目起始位置、条目结束位置或两者的组合)、强制性换行符或软连字符。 |
QTextBoundaryFinder::StartOfItem (since Qt 5.0) | 0x20 | 边界查找器位于词素、单词、句子或行的开头。 |
QTextBoundaryFinder::EndOfItem (since Qt 5.0) | 0x40 | 边界查找器位于词素、单词、句子或行的末尾。 |
QTextBoundaryFinder::MandatoryBreak (since Qt 5.0) | 0x80 | 边界搜索器位于行的末尾(仅适用于行边界类型)。 |
QTextBoundaryFinder::SoftHyphen | 0x100 | 边界查找器位于软连字号处(仅适用于行边界类型)。 |
BoundaryReasons 类型是QFlags<BoundaryReason> 的类型定义。它存储边界原因值的 OR 组合。
enum QTextBoundaryFinder::BoundaryType
常数 | 值 | 说明 |
---|---|---|
QTextBoundaryFinder::Grapheme | 0 | 查找最小边界的字符。它包括字母、标点符号、数字等。 |
QTextBoundaryFinder::Word | 1 | 查找单词。 |
QTextBoundaryFinder::Line | 3 | 查找将文本分成多行的可能位置。 |
QTextBoundaryFinder::Sentence | 2 | 查找句子边界。包括句号、问号等。 |
成员函数文档
QTextBoundaryFinder::QTextBoundaryFinder()
构造一个无效的 QTextBoundaryFinder 对象。
QTextBoundaryFinder::QTextBoundaryFinder(QTextBoundaryFinder::BoundaryType type, const QString &string)
在string 上创建一个type 的 QTextBoundaryFinder 对象。
[since 6.0]
QTextBoundaryFinder::QTextBoundaryFinder(QTextBoundaryFinder::BoundaryType type, QStringView string, unsigned char *buffer = nullptr, qsizetype bufferSize = 0)
创建一个在string 上运行的type 的 QTextBoundaryFinder 对象。
buffer 是一个可选的工作缓冲区,大小为 ,可以传递给 QTextBoundaryFinder。如果缓冲区的大小足以容纳所需的工作数据(bufferSize >= length + 1),它将使用该缓冲区而不是分配自己的缓冲区。bufferSize
警告 QTextBoundaryFinder 不会创建string 的副本。只要 QTextBoundaryFinder 对象还活着,应用程序程序员就有责任确保数组得到分配。这同样适用于buffer 。
该函数在 Qt 6.0 中引入。
QTextBoundaryFinder::QTextBoundaryFinder(QTextBoundaryFinder::BoundaryType type, const QChar *chars, qsizetype length, unsigned char *buffer = nullptr, qsizetype bufferSize = 0)
这是一个重载函数。
与 QTextBoundaryFinder(type,QStringView(chars, length), buffer, bufferSize) 相同。
QTextBoundaryFinder::QTextBoundaryFinder(const QTextBoundaryFinder &other)
复制 QTextBoundaryFinder 对象,other 。
[noexcept]
QTextBoundaryFinder::~QTextBoundaryFinder()
销毁QTextBoundaryFinder 对象。
QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() const
返回边界搜索器选择当前位置作为边界的原因。
bool QTextBoundaryFinder::isAtBoundary() const
如果对象的position() 当前位于有效文本边界,则返回true
。
bool QTextBoundaryFinder::isValid() const
如果文本边界查找器有效,则返回true
;否则返回false
。默认QTextBoundaryFinder 无效。
qsizetype QTextBoundaryFinder::position() const
返回QTextBoundaryFinder 的当前位置。
范围从 0(字符串的起始位置)到字符串的长度(含)。
另请参阅 setPosition()。
void QTextBoundaryFinder::setPosition(qsizetype position)
将QTextBoundaryFinder 的当前位置设置为position 。
如果position 越界,则只绑定到有效位置。在这种情况下,有效位置是从 0 到字符串长度(包含字符串长度)。
另请参阅 position() 。
QString QTextBoundaryFinder::string() const
返回QTextBoundaryFinder 对象操作的字符串。
void QTextBoundaryFinder::toEnd()
将查找器移到字符串的末尾。这等同于setPosition(string.length())。
另请参阅 setPosition() 和position()。
qsizetype QTextBoundaryFinder::toNextBoundary()
将QTextBoundaryFinder 移动到下一个边界位置,并返回该位置。
如果没有下一个边界,则返回-1。
qsizetype QTextBoundaryFinder::toPreviousBoundary()
将QTextBoundaryFinder 移动到上一个边界位置,并返回该位置。
如果没有前一个边界,则返回-1。
void QTextBoundaryFinder::toStart()
将查找器移到字符串的起始位置。这等同于setPosition(0)。
另请参阅 setPosition() 和position()。
QTextBoundaryFinder::BoundaryType QTextBoundaryFinder::type() const
返回QTextBoundaryFinder 的类型。
QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &other)
将对象other 分配给另一个QTextBoundaryFinder 对象。
© 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.