From efcd4d9470781e3a0331afeab49cd00cee24399f Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 19 Feb 2012 23:56:50 +0100 Subject: QRegularExpression: add captureCount() QRegularExpression::captureCount() returns the number of capturing groups inside the regular expression pattern. Change-Id: Ib90ce67c67d06ab2966f0c98bd91da21defc156d Reviewed-by: Thiago Macieira --- src/corelib/tools/qregularexpression.cpp | 13 +++++++++++++ src/corelib/tools/qregularexpression.h | 2 ++ 2 files changed, 15 insertions(+) (limited to 'src') diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index 17988bdb31..7bbac0144b 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1340,6 +1340,19 @@ void QRegularExpression::setPatternOptions(PatternOptions options) d->patternOptions = options; } +/*! + Returns the number of capturing groups inside the pattern string, + or -1 if the regular expression is not valid. + + \sa isValid() +*/ +int QRegularExpression::captureCount() const +{ + if (!isValid()) // will compile the pattern + return -1; + return d->capturingCount; +} + /*! Returns true if the regular expression is a valid regular expression (that is, it contains no syntax errors, etc.), or false otherwise. Use diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h index 13c7de7cab..3ca83c9e27 100644 --- a/src/corelib/tools/qregularexpression.h +++ b/src/corelib/tools/qregularexpression.h @@ -94,6 +94,8 @@ public: int patternErrorOffset() const; QString errorString() const; + int captureCount() const; + enum MatchType { NormalMatch = 0, PartialPreferCompleteMatch, -- cgit v1.2.3