diff options
Diffstat (limited to 'src/corelib/text/qregularexpression.cpp')
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 96 |
1 files changed, 37 insertions, 59 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 95fd0e3d9a..78261e14cb 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -42,6 +42,7 @@ using namespace Qt::StringLiterals; \keyword regular expression + \compares equality Regular expressions, or \e{regexps}, are a very powerful tool to handle strings and texts. This is useful in many contexts, e.g., @@ -721,7 +722,7 @@ struct QRegularExpressionPrivate : QSharedData CheckSubjectStringOption checkSubjectStringOption = CheckSubjectString, const QRegularExpressionMatchPrivate *previous = nullptr) const; - int captureIndexForName(QStringView name) const; + int captureIndexForName(QAnyStringView name) const; // sizeof(QSharedData) == 4, so start our members with an enum QRegularExpression::PatternOptions patternOptions; @@ -1013,7 +1014,7 @@ void QRegularExpressionPrivate::optimizePattern() Returns the capturing group number for the given name. Duplicated names for capturing groups are not supported. */ -int QRegularExpressionPrivate::captureIndexForName(QStringView name) const +int QRegularExpressionPrivate::captureIndexForName(QAnyStringView name) const { Q_ASSERT(!name.isEmpty()); @@ -1734,18 +1735,20 @@ void QRegularExpression::optimize() const } /*! - Returns \c true if the regular expression is equal to \a re, or false + \fn bool QRegularExpression::operator==(const QRegularExpression &lhs, const QRegularExpression &rhs) noexcept + + Returns \c true if the \a lhs regular expression is equal to the \a rhs, or false otherwise. Two QRegularExpression objects are equal if they have the same pattern string and the same pattern options. \sa operator!=() */ -bool QRegularExpression::operator==(const QRegularExpression &re) const +bool comparesEqual(const QRegularExpression &lhs, + const QRegularExpression &rhs) noexcept { - return (d == re.d) || - (d->pattern == re.d->pattern && d->patternOptions == re.d->patternOptions); + return (lhs.d == rhs.d) || + (lhs.d->pattern == rhs.d->pattern && lhs.d->patternOptions == rhs.d->patternOptions); } - /*! \fn QRegularExpression & QRegularExpression::operator=(QRegularExpression && re) @@ -1758,9 +1761,9 @@ bool QRegularExpression::operator==(const QRegularExpression &re) const */ /*! - \fn bool QRegularExpression::operator!=(const QRegularExpression &re) const + \fn bool QRegularExpression::operator!=(const QRegularExpression &lhs, const QRegularExpression &rhs) noexcept - Returns \c true if the regular expression is different from \a re, or + Returns \c true if the \a lhs regular expression is different from the \a rhs, or false otherwise. \sa operator==() @@ -2217,8 +2220,7 @@ int QRegularExpressionMatch::lastCapturedIndex() const } /*! - \fn bool QRegularExpressionMatch::hasCaptured(const QString &name) const - \fn bool QRegularExpressionMatch::hasCaptured(QStringView name) const + \fn bool QRegularExpressionMatch::hasCaptured(QAnyStringView name) const \since 6.3 Returns true if the capturing group named \a name captured something @@ -2235,9 +2237,12 @@ int QRegularExpressionMatch::lastCapturedIndex() const Similarly, a capturing group may capture a substring of length 0; this function will return \c{true} for such a capturing group. + \note In Qt versions prior to 6.8, this function took QString or + QStringView, not QAnyStringView. + \sa captured(), hasMatch() */ -bool QRegularExpressionMatch::hasCaptured(QStringView name) const +bool QRegularExpressionMatch::hasCaptured(QAnyStringView name) const { const int nth = d->regularExpression.d->captureIndexForName(name); return hasCaptured(nth); @@ -2317,17 +2322,6 @@ QStringView QRegularExpressionMatch::capturedView(int nth) const return d->subject.mid(start, capturedLength(nth)); } -/*! \fn QString QRegularExpressionMatch::captured(const QString &name) const - - Returns the substring captured by the capturing group named \a name. - - If the named capturing group \a name did not capture a string, or if - there is no capturing group named \a name, returns a null QString. - - \sa capturedView(), capturedStart(), capturedEnd(), capturedLength(), - QString::isNull() -*/ - /*! \since 5.10 @@ -2336,10 +2330,13 @@ QStringView QRegularExpressionMatch::capturedView(int nth) const If the named capturing group \a name did not capture a string, or if there is no capturing group named \a name, returns a null QString. + \note In Qt versions prior to 6.8, this function took QString or + QStringView, not QAnyStringView. + \sa capturedView(), capturedStart(), capturedEnd(), capturedLength(), QString::isNull() */ -QString QRegularExpressionMatch::captured(QStringView name) const +QString QRegularExpressionMatch::captured(QAnyStringView name) const { if (name.isEmpty()) { qWarning("QRegularExpressionMatch::captured: empty capturing group name passed"); @@ -2358,10 +2355,13 @@ QString QRegularExpressionMatch::captured(QStringView name) const If the named capturing group \a name did not capture a string, or if there is no capturing group named \a name, returns a null QStringView. + \note In Qt versions prior to 6.8, this function took QString or + QStringView, not QAnyStringView. + \sa captured(), capturedStart(), capturedEnd(), capturedLength(), QStringView::isNull() */ -QStringView QRegularExpressionMatch::capturedView(QStringView name) const +QStringView QRegularExpressionMatch::capturedView(QAnyStringView name) const { if (name.isEmpty()) { qWarning("QRegularExpressionMatch::capturedView: empty capturing group name passed"); @@ -2433,37 +2433,6 @@ qsizetype QRegularExpressionMatch::capturedEnd(int nth) const return d->capturedOffsets.at(nth * 2 + 1); } -/*! \fn qsizetype QRegularExpressionMatch::capturedStart(const QString &name) const - - Returns the offset inside the subject string corresponding to the starting - position of the substring captured by the capturing group named \a name. - If the capturing group named \a name did not capture a string or doesn't - exist, returns -1. - - \sa capturedEnd(), capturedLength(), captured() -*/ - -/*! \fn qsizetype QRegularExpressionMatch::capturedLength(const QString &name) const - - Returns the length of the substring captured by the capturing group named - \a name. - - \note This function returns 0 if the capturing group named \a name did not - capture a string or doesn't exist. - - \sa capturedStart(), capturedEnd(), captured() -*/ - -/*! \fn qsizetype QRegularExpressionMatch::capturedEnd(const QString &name) const - - Returns the offset inside the subject string immediately after the ending - position of the substring captured by the capturing group named \a name. If - the capturing group named \a name did not capture a string or doesn't - exist, returns -1. - - \sa capturedStart(), capturedLength(), captured() -*/ - /*! \since 5.10 @@ -2472,9 +2441,12 @@ qsizetype QRegularExpressionMatch::capturedEnd(int nth) const If the capturing group named \a name did not capture a string or doesn't exist, returns -1. + \note In Qt versions prior to 6.8, this function took QString or + QStringView, not QAnyStringView. + \sa capturedEnd(), capturedLength(), captured() */ -qsizetype QRegularExpressionMatch::capturedStart(QStringView name) const +qsizetype QRegularExpressionMatch::capturedStart(QAnyStringView name) const { if (name.isEmpty()) { qWarning("QRegularExpressionMatch::capturedStart: empty capturing group name passed"); @@ -2495,9 +2467,12 @@ qsizetype QRegularExpressionMatch::capturedStart(QStringView name) const \note This function returns 0 if the capturing group named \a name did not capture a string or doesn't exist. + \note In Qt versions prior to 6.8, this function took QString or + QStringView, not QAnyStringView. + \sa capturedStart(), capturedEnd(), captured() */ -qsizetype QRegularExpressionMatch::capturedLength(QStringView name) const +qsizetype QRegularExpressionMatch::capturedLength(QAnyStringView name) const { if (name.isEmpty()) { qWarning("QRegularExpressionMatch::capturedLength: empty capturing group name passed"); @@ -2517,9 +2492,12 @@ qsizetype QRegularExpressionMatch::capturedLength(QStringView name) const the capturing group named \a name did not capture a string or doesn't exist, returns -1. + \note In Qt versions prior to 6.8, this function took QString or + QStringView, not QAnyStringView. + \sa capturedStart(), capturedLength(), captured() */ -qsizetype QRegularExpressionMatch::capturedEnd(QStringView name) const +qsizetype QRegularExpressionMatch::capturedEnd(QAnyStringView name) const { if (name.isEmpty()) { qWarning("QRegularExpressionMatch::capturedEnd: empty capturing group name passed"); |