diff options
author | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-04-19 15:20:05 +0200 |
---|---|---|
committer | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-05-06 16:01:28 +0200 |
commit | 7b738ffc583a19138d9772d7ed84c8d771c85a77 (patch) | |
tree | f4e7cb60eb5b7d695e7d3d16bfeca2a9b48f28ef /src/corelib | |
parent | a074dd561624c94a9f0dce3061529fe0dac9d452 (diff) |
QRegularExpression: use modernize comparisons
Replace class operators operator==(), operator!=() of
QRegularExpression to friend method comparesEqual() and
Q_DECLARE_EQUALITY_COMPARABLE macro.
Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of
current comparison methods and replace them with a friend.
Task-number: QTBUG-120304
Change-Id: Ib6fc83d29ad9bc710c2fdf32a3d60131fbf298b6
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/compat/removed_api.cpp | 5 | ||||
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 17 | ||||
-rw-r--r-- | src/corelib/text/qregularexpression.h | 34 |
3 files changed, 31 insertions, 25 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 23679bf4cc..ed285dc8f1 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -1069,6 +1069,11 @@ qsizetype QRegularExpressionMatch::capturedEnd(QStringView name) const { return capturedEnd(QAnyStringView(name)); } + +bool QRegularExpression::operator==(const QRegularExpression &other) const +{ + return comparesEqual(*this, other); +} #endif // QT_CONFIG(regularexpression) #include "qstring.h" // inlined API diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 67c422568b..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., @@ -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==() diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h index 2b51b94b15..ab147b87d4 100644 --- a/src/corelib/text/qregularexpression.h +++ b/src/corelib/text/qregularexpression.h @@ -157,11 +157,15 @@ public: static QRegularExpression fromWildcard(QStringView pattern, Qt::CaseSensitivity cs = Qt::CaseInsensitive, WildcardConversionOptions options = DefaultWildcardConversion); - +#if QT_CORE_REMOVED_SINCE(6, 8) bool operator==(const QRegularExpression &re) const; inline bool operator!=(const QRegularExpression &re) const { return !operator==(re); } - +#endif private: + friend Q_CORE_EXPORT bool comparesEqual(const QRegularExpression &lhs, + const QRegularExpression &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(QRegularExpression) + friend struct QRegularExpressionPrivate; friend class QRegularExpressionMatch; friend struct QRegularExpressionMatchPrivate; @@ -365,30 +369,24 @@ private: // [input.iterators] imposes operator== on us. Unfortunately, it's not // trivial to implement, so just do the bare minimum to satifisfy // Cpp17EqualityComparable. - friend bool operator==(const QRegularExpressionMatchIteratorRangeBasedForIterator &lhs, - const QRegularExpressionMatchIteratorRangeBasedForIterator &rhs) noexcept + friend bool comparesEqual(const QRegularExpressionMatchIteratorRangeBasedForIterator &lhs, + const QRegularExpressionMatchIteratorRangeBasedForIterator &rhs) + noexcept { return (&lhs == &rhs); } - - friend bool operator!=(const QRegularExpressionMatchIteratorRangeBasedForIterator &lhs, - const QRegularExpressionMatchIteratorRangeBasedForIterator &rhs) noexcept - { - return !(lhs == rhs); - } + Q_DECLARE_EQUALITY_COMPARABLE(QRegularExpressionMatchIteratorRangeBasedForIterator) // This is what we really use in a range-based for. - friend bool operator==(const QRegularExpressionMatchIteratorRangeBasedForIterator &lhs, - QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel) noexcept + friend bool comparesEqual(const QRegularExpressionMatchIteratorRangeBasedForIterator &lhs, + const QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel &rhs) + noexcept { + Q_UNUSED(rhs); return lhs.m_atEnd; } - - friend bool operator!=(const QRegularExpressionMatchIteratorRangeBasedForIterator &lhs, - QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel) noexcept - { - return !lhs.m_atEnd; - } + Q_DECLARE_EQUALITY_COMPARABLE(QRegularExpressionMatchIteratorRangeBasedForIterator, + QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel) QRegularExpressionMatchIterator m_matchIterator; QRegularExpressionMatch m_currentMatch; |