From bcd80eebf983a2b547662d7e0d67bc8624d1130f Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 25 Jul 2018 09:23:28 +0200 Subject: Implement exact match expression builder for QRegularExpression QRegularExpression doesn't offer a direct equivalent of QRegExp's exact match. There are several places in the Qt sources that use this feature. This patch implements a small helper function that builds the expression as recommended in the documentation and updates the related code. [ChangeLog][Core][Tools] QRegularExpression now provides anchoredPattern() which is a helper function to build regular expressions used for exact matching. Change-Id: Idbbf142c4c5cb9b62abf8229f4ce85fd4409e5d0 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/tools/qstringlist.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools/qstringlist.cpp') diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index e9b7397a74..712ba74716 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -692,7 +692,7 @@ int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpres if (from < 0) from = qMax(from + that->size(), 0); - QString exactPattern = QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"); + QString exactPattern = QRegularExpression::anchoredPattern(re.pattern()); QRegularExpression exactRe(exactPattern, re.patternOptions()); for (int i = from; i < that->size(); ++i) { @@ -722,7 +722,7 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx else if (from >= that->size()) from = that->size() - 1; - QString exactPattern = QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"); + QString exactPattern = QRegularExpression::anchoredPattern(re.pattern()); QRegularExpression exactRe(exactPattern, re.patternOptions()); for (int i = from; i >= 0; --i) { -- cgit v1.2.3