![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qtextboundaryfinder.h>
Public Types | |
enum | BoundaryType { Grapheme , Word , Sentence , Line } |
\value Grapheme Finds a grapheme which is the smallest boundary. More... | |
enum | BoundaryReason { NotAtBoundary = 0 , BreakOpportunity = 0x1f , StartOfItem = 0x20 , EndOfItem = 0x40 , MandatoryBreak = 0x80 , SoftHyphen = 0x100 } |
\value NotAtBoundary The boundary finder is not at a boundary position. More... | |
Public Member Functions | |
QTextBoundaryFinder () | |
Constructs an invalid QTextBoundaryFinder object. | |
QTextBoundaryFinder (const QTextBoundaryFinder &other) | |
Copies the QTextBoundaryFinder object, other. | |
QTextBoundaryFinder & | operator= (const QTextBoundaryFinder &other) |
Assigns the object, other, to another QTextBoundaryFinder object. | |
~QTextBoundaryFinder () | |
Destructs the QTextBoundaryFinder object. | |
QTextBoundaryFinder (BoundaryType type, const QString &string) | |
Creates a QTextBoundaryFinder object of type operating on string. | |
QTextBoundaryFinder (BoundaryType type, const QChar *chars, qsizetype length, unsigned char *buffer=nullptr, qsizetype bufferSize=0) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The same as QTextBoundaryFinder(type, QStringView(chars, length), buffer, bufferSize). | |
QTextBoundaryFinder (BoundaryType type, QStringView str, unsigned char *buffer=nullptr, qsizetype bufferSize=0) | |
Creates a QTextBoundaryFinder object of type operating on string. | |
bool | isValid () const |
Returns true if the text boundary finder is valid; otherwise returns false . | |
BoundaryType | type () const |
Returns the type of the QTextBoundaryFinder. | |
QString | string () const |
Returns the string the QTextBoundaryFinder object operates on. | |
void | toStart () |
Moves the finder to the start of the string. | |
void | toEnd () |
Moves the finder to the end of the string. | |
qsizetype | position () const |
Returns the current position of the QTextBoundaryFinder. | |
void | setPosition (qsizetype position) |
Sets the current position of the QTextBoundaryFinder to position. | |
qsizetype | toNextBoundary () |
Moves the QTextBoundaryFinder to the next boundary position and returns that position. | |
qsizetype | toPreviousBoundary () |
Moves the QTextBoundaryFinder to the previous boundary position and returns that position. | |
bool | isAtBoundary () const |
Returns true if the object's position() is currently at a valid text boundary. | |
BoundaryReasons | boundaryReasons () const |
Returns the reasons for the boundary finder to have chosen the current position as a boundary. | |
\inmodule QtCore
The QTextBoundaryFinder class provides a way of finding Unicode text boundaries in a string.
\reentrant
QTextBoundaryFinder allows to find Unicode text boundaries in a string, accordingly to the Unicode text boundary specification (see \l{https://www.unicode.org/reports/tr14/}{Unicode Standard Annex #14} and \l{https://www.unicode.org/reports/tr29/}{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 \l{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 \l{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 \l{https://www.unicode.org/reports/tr29/#Sentence_Boundaries} and \l{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.
Definition at line 15 of file qtextboundaryfinder.h.
\value NotAtBoundary The boundary finder is not at a boundary position.
\value BreakOpportunity 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. \value [since 5.0] StartOfItem The boundary finder is at the start of a grapheme, a word, a sentence, or a line. \value [since 5.0] EndOfItem The boundary finder is at the end of a grapheme, a word, a sentence, or a line. \value [since 5.0] MandatoryBreak The boundary finder is at the end of line (can occur for a Line boundary type only). \value SoftHyphen The boundary finder is at the soft hyphen (can occur for a Line boundary type only).
Enumerator | |
---|---|
NotAtBoundary | |
BreakOpportunity | |
StartOfItem | |
EndOfItem | |
MandatoryBreak | |
SoftHyphen |
Definition at line 30 of file qtextboundaryfinder.h.
\value Grapheme Finds a grapheme which is the smallest boundary.
It including letters, punctuation marks, numerals and more. \value Word Finds a word. \value Line Finds possible positions for breaking the text into multiple lines. \value Sentence Finds sentence boundaries. These include periods, question marks etc.
Enumerator | |
---|---|
Grapheme | |
Word | |
Sentence | |
Line |
Definition at line 23 of file qtextboundaryfinder.h.
QTextBoundaryFinder::QTextBoundaryFinder | ( | ) |
Constructs an invalid QTextBoundaryFinder object.
Definition at line 103 of file qtextboundaryfinder.cpp.
QTextBoundaryFinder::QTextBoundaryFinder | ( | const QTextBoundaryFinder & | other | ) |
Copies the QTextBoundaryFinder object, other.
Definition at line 111 of file qtextboundaryfinder.cpp.
References other(), Q_ASSERT, Q_CHECK_PTR(), and QStringView::size().
QTextBoundaryFinder::~QTextBoundaryFinder | ( | ) |
Destructs the QTextBoundaryFinder object.
Definition at line 162 of file qtextboundaryfinder.cpp.
References Q_UNUSED.
QTextBoundaryFinder::QTextBoundaryFinder | ( | BoundaryType | type, |
const QString & | string | ||
) |
Creates a QTextBoundaryFinder object of type operating on string.
Definition at line 172 of file qtextboundaryfinder.cpp.
References init(), Q_CHECK_PTR(), and QStringView::size().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The same as QTextBoundaryFinder(type, QStringView(chars, length), buffer, bufferSize).
Definition at line 41 of file qtextboundaryfinder.h.
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.
Definition at line 208 of file qtextboundaryfinder.cpp.
References init(), QStringView::isEmpty(), Q_CHECK_PTR(), and QStringView::size().
QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons | ( | ) | const |
Returns the reasons for the boundary finder to have chosen the current position as a boundary.
Definition at line 391 of file qtextboundaryfinder.cpp.
References BreakOpportunity, EndOfItem, Grapheme, QCharAttributes::graphemeBoundary, Line, QCharAttributes::lineBreak, MandatoryBreak, QCharAttributes::mandatoryBreak, NotAtBoundary, Sentence, QCharAttributes::sentenceBoundary, QStringView::size(), QChar::SoftHyphen, SoftHyphen, StartOfItem, Word, QCharAttributes::wordBreak, QCharAttributes::wordEnd, and QCharAttributes::wordStart.
Referenced by QQuickTextInput::moveCursorSelection(), and QWindowsInputContext::reconvertString().
bool QTextBoundaryFinder::isAtBoundary | ( | ) | const |
Returns true
if the object's position() is currently at a valid text boundary.
Definition at line 369 of file qtextboundaryfinder.cpp.
References Grapheme, QCharAttributes::graphemeBoundary, Line, QCharAttributes::lineBreak, Sentence, QCharAttributes::sentenceBoundary, QStringView::size(), Word, and QCharAttributes::wordBreak.
Referenced by QAndroidInputContext::getCursorCapsMode().
|
inline |
Returns true
if the text boundary finder is valid; otherwise returns false
.
A default QTextBoundaryFinder is invalid.
Definition at line 46 of file qtextboundaryfinder.h.
QTextBoundaryFinder & QTextBoundaryFinder::operator= | ( | const QTextBoundaryFinder & | other | ) |
Assigns the object, other, to another QTextBoundaryFinder object.
Definition at line 129 of file qtextboundaryfinder.cpp.
References other(), Q_ASSERT, Q_CHECK_PTR(), and QStringView::size().
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.
Definition at line 255 of file qtextboundaryfinder.cpp.
Referenced by QAndroidInputContext::handleLocationChanged(), QQuickTextInput::moveCursorSelection(), QWindowsInputContext::reconvertString(), and setPosition().
Sets the current position of the QTextBoundaryFinder to position.
If 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.
Definition at line 269 of file qtextboundaryfinder.cpp.
References position(), qBound(), and QStringView::size().
Referenced by QAndroidInputContext::getCursorCapsMode(), QQuickTextInput::moveCursorSelection(), and QWindowsInputContext::reconvertString().
QString QTextBoundaryFinder::string | ( | ) | const |
Returns the string the QTextBoundaryFinder object operates on.
Definition at line 288 of file qtextboundaryfinder.cpp.
References QStringView::data(), QStringView::size(), QStringView::toString(), and QChar::unicode().
void QTextBoundaryFinder::toEnd | ( | ) |
Moves the finder to the end of the string.
This is equivalent to setPosition(string.length()).
Definition at line 242 of file qtextboundaryfinder.cpp.
References QStringView::size().
Referenced by QAndroidInputContext::handleLocationChanged().
qsizetype QTextBoundaryFinder::toNextBoundary | ( | ) |
Moves the QTextBoundaryFinder to the next boundary position and returns that position.
Returns -1 if there is no next boundary.
Definition at line 301 of file qtextboundaryfinder.cpp.
References Grapheme, QCharAttributes::graphemeBoundary, Line, QCharAttributes::lineBreak, pos, Sentence, QCharAttributes::sentenceBoundary, QStringView::size(), Word, and QCharAttributes::wordBreak.
Referenced by QAndroidInputContext::handleLocationChanged(), QQuickTextInput::moveCursorSelection(), and QWindowsInputContext::reconvertString().
qsizetype QTextBoundaryFinder::toPreviousBoundary | ( | ) |
Moves the QTextBoundaryFinder to the previous boundary position and returns that position.
Returns -1 if there is no previous boundary.
Definition at line 336 of file qtextboundaryfinder.cpp.
References Grapheme, Line, lineBreak(), Sentence, QStringView::size(), and Word.
Referenced by QAndroidInputContext::handleLocationChanged(), QQuickTextInput::moveCursorSelection(), and QWindowsInputContext::reconvertString().
void QTextBoundaryFinder::toStart | ( | ) |
Moves the finder to the start of the string.
This is equivalent to setPosition(0).
Definition at line 232 of file qtextboundaryfinder.cpp.
Referenced by QAndroidInputContext::handleLocationChanged().
|
inline |
Returns the type of the QTextBoundaryFinder.
Definition at line 48 of file qtextboundaryfinder.h.