From 65fba49d639fe2499d66374486f16269e669daf0 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 16 Dec 2012 20:47:47 +0100 Subject: Introduce default ctors for QRegularExpressionMatch(Iterator) This allows to put them in containers, and to enable subsequent features for QString. Change-Id: I3b3fe695ffe6930331ed9f670738376722e0fc36 Reviewed-by: Thiago Macieira --- src/corelib/tools/qregularexpression.cpp | 40 ++++++++++++++++++++++ src/corelib/tools/qregularexpression.h | 2 ++ .../qregularexpression/tst_qregularexpression.cpp | 25 ++++++++++++++ .../qregularexpression/tst_qregularexpression.h | 1 + 4 files changed, 68 insertions(+) diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index 06c696e1e2..e3f39a2662 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1657,6 +1657,26 @@ QString QRegularExpression::escape(const QString &str) return result; } +/*! + \since 5.1 + + Constructs a valid, empty QRegularExpressionMatch object. The regular + expression is set to a default-constructed one; the match type to + QRegularExpression::NoMatch and the match options to + QRegularExpression::NoMatchOption. + + The object will report no match through the hasMatch() and the + hasPartialMatch() member functions. +*/ +QRegularExpressionMatch::QRegularExpressionMatch() + : d(new QRegularExpressionMatchPrivate(QRegularExpression(), + QString(), + QRegularExpression::NoMatch, + QRegularExpression::NoMatchOption)) +{ + d->isValid = true; +} + /*! Destroys the match result. */ @@ -2000,6 +2020,26 @@ QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(QRegularExpress { } +/*! + \since 5.1 + + Constructs an empty, valid QRegularExpressionMatchIterator object. The + regular expression is set to a default-constructed one; the match type to + QRegularExpression::NoMatch and the match options to + QRegularExpression::NoMatchOption. + + Invoking the hasNext() member function on the constructed object will + return false, as the iterator is not iterating on a valid sequence of + matches. +*/ +QRegularExpressionMatchIterator::QRegularExpressionMatchIterator() + : d(new QRegularExpressionMatchIteratorPrivate(QRegularExpression(), + QRegularExpression::NoMatch, + QRegularExpression::NoMatchOption, + QRegularExpressionMatch())) +{ +} + /*! Destroys the QRegularExpressionMatchIterator object. */ diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h index 57d03a34e5..a5c273e4a2 100644 --- a/src/corelib/tools/qregularexpression.h +++ b/src/corelib/tools/qregularexpression.h @@ -154,6 +154,7 @@ struct QRegularExpressionMatchPrivate; class Q_CORE_EXPORT QRegularExpressionMatch { public: + QRegularExpressionMatch(); ~QRegularExpressionMatch(); QRegularExpressionMatch(const QRegularExpressionMatch &match); QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match); @@ -211,6 +212,7 @@ struct QRegularExpressionMatchIteratorPrivate; class Q_CORE_EXPORT QRegularExpressionMatchIterator { public: + QRegularExpressionMatchIterator(); ~QRegularExpressionMatchIterator(); QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator); QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator); diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 3662d32655..139f831b3d 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -291,6 +291,31 @@ void tst_QRegularExpression::provideRegularExpressions() | QRegularExpression::InvertedGreedinessOption); } +void tst_QRegularExpression::defaultConstructors() +{ + QRegularExpression re; + QCOMPARE(re.pattern(), QString()); + QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); + + QRegularExpressionMatch match; + QCOMPARE(match.regularExpression(), QRegularExpression()); + QCOMPARE(match.regularExpression(), re); + QCOMPARE(match.matchType(), QRegularExpression::NoMatch); + QCOMPARE(match.matchOptions(), QRegularExpression::NoMatchOption); + QCOMPARE(match.hasMatch(), false); + QCOMPARE(match.hasPartialMatch(), false); + QCOMPARE(match.isValid(), true); + QCOMPARE(match.lastCapturedIndex(), -1); + + QRegularExpressionMatchIterator iterator; + QCOMPARE(iterator.regularExpression(), QRegularExpression()); + QCOMPARE(iterator.regularExpression(), re); + QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch); + QCOMPARE(iterator.matchOptions(), QRegularExpression::NoMatchOption); + QCOMPARE(iterator.isValid(), true); + QCOMPARE(iterator.hasNext(), false); +} + void tst_QRegularExpression::gettersSetters_data() { provideRegularExpressions(); diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h index d6f9312411..6df7b80ac4 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h @@ -51,6 +51,7 @@ class tst_QRegularExpression : public QObject Q_OBJECT private slots: + void defaultConstructors(); void gettersSetters_data(); void gettersSetters(); void escape_data(); -- cgit v1.2.3