![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore \reentrant More...
#include <qregularexpression.h>
Public Member Functions | |
QRegularExpressionMatchIterator () | |
~QRegularExpressionMatchIterator () | |
Destroys the QRegularExpressionMatchIterator object. | |
QRegularExpressionMatchIterator (const QRegularExpressionMatchIterator &iterator) | |
Constructs a QRegularExpressionMatchIterator object as a copy of iterator. | |
QRegularExpressionMatchIterator (QRegularExpressionMatchIterator &&iterator)=default | |
QRegularExpressionMatchIterator & | operator= (const QRegularExpressionMatchIterator &iterator) |
Assigns the iterator iterator to this object, and returns a reference to the copy. | |
QRegularExpressionMatchIterator & | operator= (QRegularExpressionMatchIterator &&iterator) noexcept |
Move-assigns the iterator to this object, and returns a reference to the result. | |
void | swap (QRegularExpressionMatchIterator &other) noexcept |
Swaps the iterator other with this iterator object. | |
bool | isValid () const |
Returns true if the iterator object was obtained as a result from the QRegularExpression::globalMatch() function invoked on a valid QRegularExpression object; returns false if the QRegularExpression was invalid. | |
bool | hasNext () const |
Returns true if there is at least one match result ahead of the iterator; otherwise it returns false . | |
QRegularExpressionMatch | next () |
Returns the next match result and advances the iterator by one position. | |
QRegularExpressionMatch | peekNext () const |
Returns the next match result without moving the iterator. | |
QRegularExpression | regularExpression () const |
Returns the QRegularExpression object whose globalMatch() function returned this object. | |
QRegularExpression::MatchType | matchType () const |
Returns the match type that was used to get this QRegularExpressionMatchIterator object, that is, the match type that was passed to QRegularExpression::globalMatch(). | |
QRegularExpression::MatchOptions | matchOptions () const |
Returns the match options that were used to get this QRegularExpressionMatchIterator object, that is, the match options that were passed to QRegularExpression::globalMatch(). | |
Friends | |
class | QRegularExpression |
Q_CORE_EXPORT QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator | begin (const QRegularExpressionMatchIterator &iterator) |
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel | end (const QRegularExpressionMatchIterator &) |
\inmodule QtCore \reentrant
The QRegularExpressionMatchIterator class provides an iterator on the results of a global match of a QRegularExpression object against a string.
\keyword regular expression iterator
A QRegularExpressionMatchIterator object is a forward only Java-like iterator; it can be obtained by calling the QRegularExpression::globalMatch() function. A new QRegularExpressionMatchIterator will be positioned before the first result. You can then call the hasNext() function to check if there are more results available; if so, the next() function will return the next result and advance the iterator.
Each result is a QRegularExpressionMatch object holding all the information for that result (including captured substrings).
For instance:
Moreover, QRegularExpressionMatchIterator offers a peekNext() function to get the next result {without} advancing the iterator.
Starting with Qt 6.0, it is also possible to simply use the result of QRegularExpression::globalMatch in a range-based for loop, for instance like this:
You can retrieve the QRegularExpression object the subject string was matched against by calling the regularExpression() function; the match type and the match options are available as well by calling the matchType() and the matchOptions() respectively.
Please refer to the QRegularExpression documentation for more information about the Qt regular expression classes.
Definition at line 268 of file qregularexpression.h.
QRegularExpressionMatchIterator::QRegularExpressionMatchIterator | ( | ) |
Constructs an empty, valid QRegularExpressionMatchIterator object. The regular expression is set to a default-constructed one; the match type to QRegularExpression::NoMatch and the match options to QRegularExpression::NoMatchOption.
Invoking the hasNext() member function on the constructed object will return false, as the iterator is not iterating on a valid sequence of matches.
Definition at line 2592 of file qregularexpression.cpp.
QRegularExpressionMatchIterator::~QRegularExpressionMatchIterator | ( | ) |
Destroys the QRegularExpressionMatchIterator object.
Definition at line 2603 of file qregularexpression.cpp.
QRegularExpressionMatchIterator::QRegularExpressionMatchIterator | ( | const QRegularExpressionMatchIterator & | iterator | ) |
Constructs a QRegularExpressionMatchIterator object as a copy of iterator.
Definition at line 2615 of file qregularexpression.cpp.
|
default |
Constructs a QRegularExpressionMatchIterator object by moving from iterator.
Note that a moved-from QRegularExpressionMatchIterator can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.
bool QRegularExpressionMatchIterator::hasNext | ( | ) | const |
Returns true
if there is at least one match result ahead of the iterator; otherwise it returns false
.
Definition at line 2681 of file qregularexpression.cpp.
References QRegularExpressionMatchIteratorPrivate::hasNext().
Referenced by next(), QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator::operator++(), and peekNext().
bool QRegularExpressionMatchIterator::isValid | ( | ) | const |
Returns true
if the iterator object was obtained as a result from the QRegularExpression::globalMatch() function invoked on a valid QRegularExpression object; returns false
if the QRegularExpression was invalid.
Definition at line 2670 of file qregularexpression.cpp.
References QRegularExpressionMatch::isValid(), and QRegularExpressionMatchIteratorPrivate::next.
QRegularExpression::MatchOptions QRegularExpressionMatchIterator::matchOptions | ( | ) | const |
Returns the match options that were used to get this QRegularExpressionMatchIterator object, that is, the match options that were passed to QRegularExpression::globalMatch().
Definition at line 2747 of file qregularexpression.cpp.
References QRegularExpressionMatchIteratorPrivate::matchOptions.
QRegularExpression::MatchType QRegularExpressionMatchIterator::matchType | ( | ) | const |
Returns the match type that was used to get this QRegularExpressionMatchIterator object, that is, the match type that was passed to QRegularExpression::globalMatch().
Definition at line 2735 of file qregularexpression.cpp.
References QRegularExpressionMatchIteratorPrivate::matchType.
QRegularExpressionMatch QRegularExpressionMatchIterator::next | ( | ) |
Returns the next match result and advances the iterator by one position.
Definition at line 2706 of file qregularexpression.cpp.
References QExplicitlySharedDataPointer< T >::constData(), QExplicitlySharedDataPointer< T >::detach(), hasNext(), QRegularExpressionMatchIteratorPrivate::next, QRegularExpressionMatchPrivate::nextMatch(), and qWarning.
Referenced by QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator::operator++().
QRegularExpressionMatchIterator & QRegularExpressionMatchIterator::operator= | ( | const QRegularExpressionMatchIterator & | iterator | ) |
Assigns the iterator iterator to this object, and returns a reference to the copy.
Definition at line 2638 of file qregularexpression.cpp.
|
inlinenoexcept |
Move-assigns the iterator to this object, and returns a reference to the result.
Note that a moved-from QRegularExpressionMatchIterator can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.
Definition at line 276 of file qregularexpression.h.
References d.
QRegularExpressionMatch QRegularExpressionMatchIterator::peekNext | ( | ) | const |
Returns the next match result without moving the iterator.
Definition at line 2692 of file qregularexpression.cpp.
References hasNext(), QRegularExpressionMatchIteratorPrivate::next, and qWarning.
QRegularExpression QRegularExpressionMatchIterator::regularExpression | ( | ) | const |
Returns the QRegularExpression object whose globalMatch() function returned this object.
Definition at line 2723 of file qregularexpression.cpp.
References QRegularExpressionMatchIteratorPrivate::regularExpression.
|
inlinenoexcept |
Swaps the iterator other with this iterator object.
This operation is very fast and never fails.
Definition at line 278 of file qregularexpression.h.
|
friend |
Definition at line 2755 of file qregularexpression.cpp.
|
friend |
Definition at line 293 of file qregularexpression.h.
|
friend |
Definition at line 291 of file qregularexpression.h.