Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QTextBoundaryFinder Class Reference

\inmodule QtCore More...

#include <qtextboundaryfinder.h>

Collaboration diagram for QTextBoundaryFinder:

Public Types

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 (QTextBoundaryFinder &&other) noexcept
QTextBoundaryFinderoperator= (const QTextBoundaryFinder &other)
 Assigns the object, other, to another QTextBoundaryFinder object.
 ~QTextBoundaryFinder ()
 Destructs the QTextBoundaryFinder object.
void swap (QTextBoundaryFinder &other) noexcept
enum BoundaryType QT7_ONLY (:quint8)
 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.

Detailed Description

\inmodule QtCore

The QTextBoundaryFinder class provides a way of finding Unicode text boundaries in a string.

Since
4.4

\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 19 of file qtextboundaryfinder.h.

Member Enumeration Documentation

◆ BoundaryReason

\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 56 of file qtextboundaryfinder.h.

Constructor & Destructor Documentation

◆ QTextBoundaryFinder() [1/6]

QTextBoundaryFinder::QTextBoundaryFinder ( )

Constructs an invalid QTextBoundaryFinder object.

Definition at line 105 of file qtextboundaryfinder.cpp.

◆ QTextBoundaryFinder() [2/6]

QTextBoundaryFinder::QTextBoundaryFinder ( const QTextBoundaryFinder & other)

Copies the QTextBoundaryFinder object, other.

Definition at line 112 of file qtextboundaryfinder.cpp.

◆ QTextBoundaryFinder() [3/6]

QTextBoundaryFinder::QTextBoundaryFinder ( QTextBoundaryFinder && other)
inlinenoexcept
Since
6.11

Move-constructs a new QTextBoundaryFinder from other.

Note
The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

Definition at line 24 of file qtextboundaryfinder.h.

◆ ~QTextBoundaryFinder()

QTextBoundaryFinder::~QTextBoundaryFinder ( )

Destructs the QTextBoundaryFinder object.

Definition at line 182 of file qtextboundaryfinder.cpp.

◆ QTextBoundaryFinder() [4/6]

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

Creates a QTextBoundaryFinder object of type operating on string.

Definition at line 197 of file qtextboundaryfinder.cpp.

◆ QTextBoundaryFinder() [5/6]

QTextBoundaryFinder::QTextBoundaryFinder ( BoundaryType type,
const QChar * chars,
qsizetype length,
unsigned char * buffer = nullptr,
qsizetype bufferSize = 0 )
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 67 of file qtextboundaryfinder.h.

◆ QTextBoundaryFinder() [6/6]

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

Creates a QTextBoundaryFinder object of type operating on string.

Since
6.0

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.

Warning
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.

Definition at line 229 of file qtextboundaryfinder.cpp.

Member Function Documentation

◆ boundaryReasons()

QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons ( ) const

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

Definition at line 409 of file qtextboundaryfinder.cpp.

◆ isAtBoundary()

bool QTextBoundaryFinder::isAtBoundary ( ) const

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

Definition at line 387 of file qtextboundaryfinder.cpp.

◆ isValid()

bool QTextBoundaryFinder::isValid ( ) const
inline

Returns true if the text boundary finder is valid; otherwise returns false.

A default QTextBoundaryFinder is invalid.

Definition at line 72 of file qtextboundaryfinder.h.

◆ operator=()

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

Assigns the object, other, to another QTextBoundaryFinder object.

Since
6.11

Move-assigns other to this QTextBoundaryFinder instance.

Note
The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

Definition at line 138 of file qtextboundaryfinder.cpp.

◆ position()

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.

See also
setPosition()

Definition at line 273 of file qtextboundaryfinder.cpp.

◆ QT7_ONLY()

enum BoundaryType QTextBoundaryFinder::QT7_ONLY ( :quint8 )
inline

Definition at line 49 of file qtextboundaryfinder.h.

◆ setPosition()

void QTextBoundaryFinder::setPosition ( qsizetype position)

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.

See also
position()

Definition at line 287 of file qtextboundaryfinder.cpp.

◆ string()

QString QTextBoundaryFinder::string ( ) const

Returns the string the QTextBoundaryFinder object operates on.

Definition at line 306 of file qtextboundaryfinder.cpp.

◆ swap()

void QTextBoundaryFinder::swap ( QTextBoundaryFinder & other)
inlinenoexcept
Since
6.11

\memberswap{text boundary finder}

Definition at line 38 of file qtextboundaryfinder.h.

◆ toEnd()

void QTextBoundaryFinder::toEnd ( )

Moves the finder to the end of the string.

This is equivalent to setPosition(string.length()).

See also
setPosition(), position()

Definition at line 260 of file qtextboundaryfinder.cpp.

◆ toNextBoundary()

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 319 of file qtextboundaryfinder.cpp.

◆ toPreviousBoundary()

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 354 of file qtextboundaryfinder.cpp.

◆ toStart()

void QTextBoundaryFinder::toStart ( )

Moves the finder to the start of the string.

This is equivalent to setPosition(0).

See also
setPosition(), position()

Definition at line 250 of file qtextboundaryfinder.cpp.

◆ type()

BoundaryType QTextBoundaryFinder::type ( ) const
inline

Returns the type of the QTextBoundaryFinder.

Definition at line 74 of file qtextboundaryfinder.h.


The documentation for this class was generated from the following files: