summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <dangelog@gmail.com>2012-02-19 23:56:50 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-06 23:56:14 +0100
commitefcd4d9470781e3a0331afeab49cd00cee24399f (patch)
tree00d8da81efb63985afb3513491e357e213e776dd /src/corelib
parent1899861858eb262df7826eb32d1274233a35536e (diff)
QRegularExpression: add captureCount()
QRegularExpression::captureCount() returns the number of capturing groups inside the regular expression pattern. Change-Id: Ib90ce67c67d06ab2966f0c98bd91da21defc156d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qregularexpression.cpp13
-rw-r--r--src/corelib/tools/qregularexpression.h2
2 files changed, 15 insertions, 0 deletions
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
@@ -1341,6 +1341,19 @@ void QRegularExpression::setPatternOptions(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
errorString() to obtain a textual description of the error.
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,