diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2014-08-26 19:01:06 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2014-09-02 00:37:50 +0200 |
commit | f137618baf8418002a5a58564705619583ee82fb (patch) | |
tree | b7fbf995096c5406960bef858289cc583327a02b /src/corelib | |
parent | c714f58085859024b4a3f6ed1968b716b5a70036 (diff) |
QRegularExpression: add overloads matching over a QStringRef
[ChangeLog][QtCore][QRegularExpression] Support for matching
using QStringRef as the subject's string type has been added.
Change-Id: Idb956bbbdf4213f9ebe035db32cd37cf3370c6bc
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qregularexpression.cpp | 54 | ||||
-rw-r--r-- | src/corelib/tools/qregularexpression.h | 10 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index c039289028..c4c6fe4451 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1722,6 +1722,32 @@ QRegularExpressionMatch QRegularExpression::match(const QString &subject, } /*! + \since 5.5 + \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. + + \sa QRegularExpressionMatch, {normal matching} +*/ +QRegularExpressionMatch QRegularExpression::match(const QStringRef &subjectRef, + int offset, + MatchType matchType, + MatchOptions matchOptions) const +{ + d.data()->compilePattern(); + + const QString subject = subjectRef.string() ? *subjectRef.string() : QString(); + + QRegularExpressionMatchPrivate *priv = d->doMatch(subject, subjectRef.position(), subjectRef.length(), offset, matchType, matchOptions); + return QRegularExpressionMatch(*priv); +} + +/*! 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 @@ -1747,6 +1773,34 @@ QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &s } /*! + \since 5.5 + \overload + + Attempts to perform a global match of 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 QRegularExpressionMatchIterator is positioned before the + first match result (if any). + + \sa QRegularExpressionMatchIterator, {global matching} +*/ +QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QStringRef &subjectRef, + int offset, + MatchType matchType, + MatchOptions matchOptions) const +{ + QRegularExpressionMatchIteratorPrivate *priv = + new QRegularExpressionMatchIteratorPrivate(*this, + matchType, + matchOptions, + match(subjectRef, offset, matchType, matchOptions)); + + return QRegularExpressionMatchIterator(*priv); +} + +/*! \since 5.4 Forces an immediate optimization of the pattern, including diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h index ce91eace5f..1bd655ee2d 100644 --- a/src/corelib/tools/qregularexpression.h +++ b/src/corelib/tools/qregularexpression.h @@ -120,11 +120,21 @@ public: MatchType matchType = NormalMatch, MatchOptions matchOptions = NoMatchOption) const; + QRegularExpressionMatch match(const QStringRef &subjectRef, + int offset = 0, + MatchType matchType = NormalMatch, + MatchOptions matchOptions = NoMatchOption) const; + QRegularExpressionMatchIterator globalMatch(const QString &subject, int offset = 0, MatchType matchType = NormalMatch, MatchOptions matchOptions = NoMatchOption) const; + QRegularExpressionMatchIterator globalMatch(const QStringRef &subjectRef, + int offset = 0, + MatchType matchType = NormalMatch, + MatchOptions matchOptions = NoMatchOption) const; + void optimize() const; static QString escape(const QString &str); |