diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-09-23 12:54:27 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-10-19 10:24:48 +0200 |
commit | 4d70f2c19f93b1a22204dfb14036c5e62d8a2b10 (patch) | |
tree | f6b1e07d0a3f8446ce8287696d36bafa86821f4f /src | |
parent | 29ca6b9d14fbf9774e9829e59ac5f4e675c2c1d0 (diff) |
Add QStringView overloads to QRegularExpression::(global)Match()
Add these to simplify porting from Qt 5.15 to Qt 6.
Task-number: QTBUG-86516
Change-Id: I39f9c61e66a8084c7a4a6c5424e5b1a0b09beeff
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 38 | ||||
-rw-r--r-- | src/corelib/text/qregularexpression.h | 25 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 7201421d44..d7e3cc5ee2 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -1735,6 +1735,24 @@ QRegularExpressionMatch QRegularExpression::match(const QStringRef &subjectRef, } /*! + \fn QRegularExpressionMatch QRegularExpression::match(QStringView subject, int offset, QRegularExpression::MatchType matchType, MatchOptions matchOptions) const + \since 5.15.2 + \overload + + Attempts to match the regular expression against the given \a subjectRef + string reference, starting at the position \a offset inside the subject, using a + match of type \a matchType and honoring the given \a matchOptions. + + The returned QRegularExpressionMatch object contains the results of the + match. + + \note This overload has been added in 5.15.2 to simplify writing code that is portable + between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5. + + \sa QRegularExpressionMatch, {normal matching} +*/ + +/*! Attempts to perform a global match of the regular expression against the given \a subject string, starting at the position \a offset inside the subject, using a match of type \a matchType and honoring the given \a @@ -1787,6 +1805,26 @@ QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QStringRef return QRegularExpressionMatchIterator(*priv); } + +/*! + \fn QRegularExpressionMatchIterator QRegularExpression::globalMatch(QStringView subject, int offset, QRegularExpression::MatchType matchType, MatchOptions matchOptions) const + \since 5.15.2 + \overload + + Attempts to perform a global match of the regular expression against the + given \a subject string, starting at the position \a offset inside the + subject, using a match of type \a matchType and honoring the given \a + matchOptions. + + The returned QRegularExpressionMatchIterator is positioned before the + first match result (if any). + + \note This overload has been added in 5.15.2 to simplify writing code that is portable + between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5. + + \sa QRegularExpressionMatchIterator, {global matching} +*/ + /*! \since 5.4 diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h index e00979527d..3a4a068521 100644 --- a/src/corelib/text/qregularexpression.h +++ b/src/corelib/text/qregularexpression.h @@ -125,6 +125,11 @@ public: MatchType matchType = NormalMatch, MatchOptions matchOptions = NoMatchOption) const; + QRegularExpressionMatch match(QStringView subject, + int offset = 0, + MatchType matchType = NormalMatch, + MatchOptions matchOptions = NoMatchOption) const; + QRegularExpressionMatchIterator globalMatch(const QString &subject, int offset = 0, MatchType matchType = NormalMatch, @@ -135,6 +140,11 @@ public: MatchType matchType = NormalMatch, MatchOptions matchOptions = NoMatchOption) const; + QRegularExpressionMatchIterator globalMatch(QStringView subject, + int offset = 0, + MatchType matchType = NormalMatch, + MatchOptions matchOptions = NoMatchOption) const; + void optimize() const; #if QT_STRINGVIEW_LEVEL < 2 @@ -278,6 +288,21 @@ private: Q_DECLARE_SHARED(QRegularExpressionMatchIterator) +inline +QRegularExpressionMatch QRegularExpression::match(QStringView subject, int offset, + QRegularExpression::MatchType matchType, MatchOptions matchOptions) const +{ + return match(subject.toString(), offset, matchType, matchOptions); +} + +inline +QRegularExpressionMatchIterator QRegularExpression::globalMatch(QStringView subject, int offset, + QRegularExpression::MatchType matchType, MatchOptions matchOptions) const +{ + return globalMatch(subject.toString(), offset, matchType, matchOptions); +} + + // implementation here, so we have all required classes inline QList<QStringView> QStringView::split(const QRegularExpression &sep, Qt::SplitBehavior behavior) const |