Introduce QRegularExpression::NoMatch match type
This match type doesn't do any match at all; it's only necessary to properly introduce default constructors for QRegularExpressionMatch and QRegularExpressionMatchIterator (since they return the match type that created them). Change-Id: Ibfe92459c7fdd23129cf3afe073cd443c461ddeb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
bc5a2336ab
commit
998899cf3a
@ -1,6 +1,7 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
|
||||
** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
@ -725,6 +726,13 @@ QT_BEGIN_NAMESPACE
|
||||
that (in this text) there are other characters beyond the end of the
|
||||
subject string. This can lead to surprising results; see the discussion
|
||||
in the \l{partial matching} section for more details.
|
||||
|
||||
\value NoMatch
|
||||
No matching is done. This value is returned as the match type by a
|
||||
default constructed QRegularExpressionMatch or
|
||||
QRegularExpressionMatchIterator. Using this match type is not very
|
||||
useful for the user, as no matching ever happens. This enum value
|
||||
has been introduced in Qt 5.1.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -1200,6 +1208,15 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
|
||||
return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions, 0);
|
||||
}
|
||||
|
||||
// skip optimizing and doing the actual matching if NoMatch type was requested
|
||||
if (matchType == QRegularExpression::NoMatch) {
|
||||
QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject,
|
||||
matchType, matchOptions,
|
||||
0);
|
||||
priv->isValid = true;
|
||||
return priv;
|
||||
}
|
||||
|
||||
QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject,
|
||||
matchType, matchOptions,
|
||||
capturingCount);
|
||||
|
@ -1,6 +1,7 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
|
||||
** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
@ -99,7 +100,8 @@ public:
|
||||
enum MatchType {
|
||||
NormalMatch = 0,
|
||||
PartialPreferCompleteMatch,
|
||||
PartialPreferFirstMatch
|
||||
PartialPreferFirstMatch,
|
||||
NoMatch
|
||||
};
|
||||
|
||||
enum MatchOption {
|
||||
|
@ -127,8 +127,6 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem)
|
||||
bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
|
||||
{
|
||||
QRegularExpressionMatchIterator i = iterator;
|
||||
if (i.isValid() != (!expectedMatchList.isEmpty()))
|
||||
return false;
|
||||
|
||||
foreach (const Match &expectedMatch, expectedMatchList)
|
||||
{
|
||||
@ -694,14 +692,30 @@ void tst_QRegularExpression::normalMatch()
|
||||
QFETCH(QRegularExpression::MatchOptions, matchOptions);
|
||||
QFETCH(Match, match);
|
||||
|
||||
QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
|
||||
consistencyCheck(m);
|
||||
QVERIFY(m == match);
|
||||
QCOMPARE(m.regularExpression(), regexp);
|
||||
QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
|
||||
QCOMPARE(m.matchOptions(), matchOptions);
|
||||
}
|
||||
{
|
||||
QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
|
||||
consistencyCheck(m);
|
||||
QVERIFY(m == match);
|
||||
QCOMPARE(m.regularExpression(), regexp);
|
||||
QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
|
||||
QCOMPARE(m.matchOptions(), matchOptions);
|
||||
}
|
||||
{
|
||||
// ignore the expected results provided by the match object --
|
||||
// we'll never get any result when testing the NoMatch type.
|
||||
// Just check the validity of the match here.
|
||||
Match realMatch;
|
||||
realMatch.clear();
|
||||
realMatch.isValid = match.isValid;
|
||||
|
||||
QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
|
||||
consistencyCheck(m);
|
||||
QVERIFY(m == realMatch);
|
||||
QCOMPARE(m.regularExpression(), regexp);
|
||||
QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
|
||||
QCOMPARE(m.matchOptions(), matchOptions);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QRegularExpression::partialMatch_data()
|
||||
{
|
||||
@ -956,12 +970,29 @@ void tst_QRegularExpression::partialMatch()
|
||||
QFETCH(QRegularExpression::MatchOptions, matchOptions);
|
||||
QFETCH(Match, match);
|
||||
|
||||
QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
|
||||
consistencyCheck(m);
|
||||
QVERIFY(m == match);
|
||||
QCOMPARE(m.regularExpression(), regexp);
|
||||
QCOMPARE(m.matchType(), matchType);
|
||||
QCOMPARE(m.matchOptions(), matchOptions);
|
||||
{
|
||||
QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
|
||||
consistencyCheck(m);
|
||||
QVERIFY(m == match);
|
||||
QCOMPARE(m.regularExpression(), regexp);
|
||||
QCOMPARE(m.matchType(), matchType);
|
||||
QCOMPARE(m.matchOptions(), matchOptions);
|
||||
}
|
||||
{
|
||||
// ignore the expected results provided by the match object --
|
||||
// we'll never get any result when testing the NoMatch type.
|
||||
// Just check the validity of the match here.
|
||||
Match realMatch;
|
||||
realMatch.clear();
|
||||
realMatch.isValid = match.isValid;
|
||||
|
||||
QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
|
||||
consistencyCheck(m);
|
||||
QVERIFY(m == realMatch);
|
||||
QCOMPARE(m.regularExpression(), regexp);
|
||||
QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
|
||||
QCOMPARE(m.matchOptions(), matchOptions);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QRegularExpression::globalMatch_data()
|
||||
@ -1230,13 +1261,28 @@ void tst_QRegularExpression::globalMatch()
|
||||
QFETCH(QRegularExpression::MatchType, matchType);
|
||||
QFETCH(QRegularExpression::MatchOptions, matchOptions);
|
||||
QFETCH(QList<Match>, matchList);
|
||||
{
|
||||
QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
|
||||
consistencyCheck(iterator);
|
||||
QVERIFY(iterator == matchList);
|
||||
QCOMPARE(iterator.regularExpression(), regexp);
|
||||
QCOMPARE(iterator.matchType(), matchType);
|
||||
QCOMPARE(iterator.matchOptions(), matchOptions);
|
||||
}
|
||||
{
|
||||
// ignore the expected results provided by the match object --
|
||||
// we'll never get any result when testing the NoMatch type.
|
||||
// Just check the validity of the match here.
|
||||
QList<Match> realMatchList;
|
||||
|
||||
QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions);
|
||||
consistencyCheck(iterator);
|
||||
QVERIFY(iterator == realMatchList);
|
||||
QCOMPARE(iterator.regularExpression(), regexp);
|
||||
QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
|
||||
QCOMPARE(iterator.matchOptions(), matchOptions);
|
||||
}
|
||||
|
||||
QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
|
||||
consistencyCheck(iterator);
|
||||
QVERIFY(iterator == matchList);
|
||||
QCOMPARE(iterator.regularExpression(), regexp);
|
||||
QCOMPARE(iterator.matchType(), matchType);
|
||||
QCOMPARE(iterator.matchOptions(), matchOptions);
|
||||
}
|
||||
|
||||
void tst_QRegularExpression::serialize_data()
|
||||
|
Loading…
Reference in New Issue
Block a user