QTextBoundaryFinder 类

QTextBoundaryFinder 类提供在字符串中查找 Unicode 文本边界的办法。 更多...

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

注意: 此类的所有函数 可重入 .

公共类型

enum BoundaryReason { NotAtBoundary, BreakOpportunity, StartOfItem, EndOfItem, MandatoryBreak, SoftHyphen }
flags BoundaryReasons
enum BoundaryType { Grapheme, Word, Line, Sentence }

公共函数

QTextBoundaryFinder ()
QTextBoundaryFinder (QTextBoundaryFinder::BoundaryType type , const QString & string )
QTextBoundaryFinder (QTextBoundaryFinder::BoundaryType type , const QChar * chars , qsizetype length , unsigned char * buffer = nullptr, qsizetype bufferSize = 0)
QTextBoundaryFinder (QTextBoundaryFinder::BoundaryType type , QStringView string , 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 allows to find Unicode text boundaries in a string, accordingly to the Unicode text boundary specification (see Unicode Standard Annex #14 and Unicode Standard Annex #29 ).

QTextBoundaryFinder can operate on a QString in four possible modes depending on the value of BoundaryType .

Units of Unicode characters that make up what the user thinks of as a character or basic unit of the language are here called Grapheme clusters. The two unicode characters 'A' + diaeresis do for example form one grapheme cluster as the user thinks of them as one character, yet it is in this case represented by two unicode code points (see https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries ).

Word boundaries are there to locate the start and end of what a language considers to be a word (see https://www.unicode.org/reports/tr29/#Word_Boundaries ).

Line break boundaries give possible places where a line break might happen and sentence boundaries will show the beginning and end of whole sentences (see https://www.unicode.org/reports/tr29/#Sentence_Boundaries and https://www.unicode.org/reports/tr14/ ).

The first position in a string is always a valid boundary and refers to the position before the first character. The last position at the length of the string is also valid and refers to the position after the last character.

成员类型文档编制

enum QTextBoundaryFinder:: BoundaryReason
flags QTextBoundaryFinder:: BoundaryReasons

常量 描述
QTextBoundaryFinder::NotAtBoundary 0 The boundary finder is not at a boundary position.
QTextBoundaryFinder::BreakOpportunity 0x1f The boundary finder is at a break opportunity position. Such a break opportunity might also be an item boundary (either StartOfItem, EndOfItem, or combination of both), a mandatory line break, or a soft hyphen.
QTextBoundaryFinder::StartOfItem (since Qt 5.0) 0x20 The boundary finder is at the start of a grapheme, a word, a sentence, or a line.
QTextBoundaryFinder::EndOfItem (since Qt 5.0) 0x40 The boundary finder is at the end of a grapheme, a word, a sentence, or a line.
QTextBoundaryFinder::MandatoryBreak (since Qt 5.0) 0x80 The boundary finder is at the end of line (can occur for a Line boundary type only).
QTextBoundaryFinder::SoftHyphen 0x100 The boundary finder is at the soft hyphen (can occur for a Line boundary type only).

The BoundaryReasons type is a typedef for QFlags <BoundaryReason>. It stores an OR combination of BoundaryReason values.

enum QTextBoundaryFinder:: BoundaryType

常量 描述
QTextBoundaryFinder::Grapheme 0 Finds a grapheme which is the smallest boundary. It including letters, punctuation marks, numerals and more.
QTextBoundaryFinder::Word 1 Finds a word.
QTextBoundaryFinder::Line 3 Finds possible positions for breaking the text into multiple lines.
QTextBoundaryFinder::Sentence 2 Finds sentence boundaries. These include periods, question marks etc.

成员函数文档编制

QTextBoundaryFinder:: QTextBoundaryFinder ()

Constructs an invalid QTextBoundaryFinder object.

QTextBoundaryFinder:: QTextBoundaryFinder ( QTextBoundaryFinder::BoundaryType type , const QString & string )

Creates a QTextBoundaryFinder object of type operating on string .

QTextBoundaryFinder:: QTextBoundaryFinder ( QTextBoundaryFinder::BoundaryType type , const QChar * chars , qsizetype length , unsigned char * buffer = nullptr, qsizetype bufferSize = 0)

这是重载函数。

The same as QTextBoundaryFinder(type, QStringView (chars, length), buffer, bufferSize).

[since 6.0] QTextBoundaryFinder:: QTextBoundaryFinder ( QTextBoundaryFinder::BoundaryType type , QStringView string , unsigned char * buffer = nullptr, qsizetype bufferSize = 0)

Creates a QTextBoundaryFinder object of type operating on string .

buffer is an optional working buffer of size bufferSize you can pass to the QTextBoundaryFinder. If the buffer is large enough to hold the working data required (bufferSize >= length + 1), it will use this instead of allocating its own buffer.

警告: QTextBoundaryFinder does not create a copy of string . It is the application programmer's responsibility to ensure the array is allocated for as long as the QTextBoundaryFinder object stays alive. The same applies to buffer .

该函数在 Qt 6.0 引入。

QTextBoundaryFinder:: QTextBoundaryFinder (const QTextBoundaryFinder & other )

Copies the QTextBoundaryFinder object, other .

[noexcept] QTextBoundaryFinder:: ~QTextBoundaryFinder ()

销毁 QTextBoundaryFinder 对象。

QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder:: boundaryReasons () const

Returns the reasons for the boundary finder to have chosen the current position as a boundary.

bool QTextBoundaryFinder:: isAtBoundary () const

返回 true if the object's position () is currently at a valid text boundary.

bool QTextBoundaryFinder:: isValid () const

返回 true if the text boundary finder is valid; otherwise returns false . A default QTextBoundaryFinder 无效。

qsizetype QTextBoundaryFinder:: position () const

Returns the current position of the QTextBoundaryFinder .

The range is from 0 (the beginning of the string) to the length of the string inclusive.

另请参阅 setPosition ().

void QTextBoundaryFinder:: setPosition ( qsizetype position )

Sets the current position of the QTextBoundaryFinder to position .

position is out of bounds, it will be bound to only valid positions. In this case, valid positions are from 0 to the length of the string inclusive.

另请参阅 position ().

QString QTextBoundaryFinder:: string () const

Returns the string the QTextBoundaryFinder object operates on.

void QTextBoundaryFinder:: toEnd ()

Moves the finder to the end of the string. This is equivalent to setPosition (string.length()).

另请参阅 setPosition () 和 position ().

qsizetype QTextBoundaryFinder:: toNextBoundary ()

移动 QTextBoundaryFinder to the next boundary position and returns that position.

Returns -1 if there is no next boundary.

qsizetype QTextBoundaryFinder:: toPreviousBoundary ()

移动 QTextBoundaryFinder to the previous boundary position and returns that position.

Returns -1 if there is no previous boundary.

void QTextBoundaryFinder:: toStart ()

Moves the finder to the start of the string. This is equivalent to setPosition (0).

另请参阅 setPosition () 和 position ().

QTextBoundaryFinder::BoundaryType QTextBoundaryFinder:: type () const

Returns the type of the QTextBoundaryFinder .

QTextBoundaryFinder &QTextBoundaryFinder:: operator= (const QTextBoundaryFinder & other )

Assigns the object, other , to another QTextBoundaryFinder 对象。