summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@idiap.ch>2018-07-19 00:21:49 +0200
committerSamuel Gaist <samuel.gaist@idiap.ch>2018-08-19 04:03:29 +0000
commita2c85bffbeaa027e98fb6c23b2d7919adc8d28b7 (patch)
tree8dcb621ac9f3fbd495ef0f85a1878e6e56edd823 /src/corelib/io
parent3746eb8412ea42d7e3c519926460482530782a75 (diff)
Migrate QDir to use QRegularExpression
The match method still uses QRegExp. This patch updates the code to use QRegularExpression and translates the wildcard patterns to a suitable form for QRegularExpression. [ChangeLog][Core][QDir] QDir now uses QRegularExpression internally for wildcard matching. Note that QRegularExpression might not give the exact same result as QRegExp as its implementation follows strictly the glob patterns definition for wildcard expressions. Nevertheless, the tests for QDir return the same results as before. Change-Id: I095959443ac7362f7534e35454eff038061fca82 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdir.cpp24
-rw-r--r--src/corelib/io/qdir.h2
2 files changed, 17 insertions, 9 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 7c0a48f8f2..85ea2cb139 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -48,7 +48,9 @@
#include "qdiriterator.h"
#include "qdatetime.h"
#include "qstring.h"
-#include "qregexp.h"
+#if QT_CONFIG(regularexpression)
+# include <qregularexpression.h>
+#endif
#include "qvector.h"
#include "qvarlengtharray.h"
#include "qfilesystementry_p.h"
@@ -1038,7 +1040,7 @@ QStringList QDir::nameFilters() const
list of filters specified by \a nameFilters.
Each name filter is a wildcard (globbing) filter that understands
- \c{*} and \c{?} wildcards. (See \l{QRegExp wildcard matching}.)
+ \c{*} and \c{?} wildcards. (See \l{QRegularExpression wildcard matching}.)
For example, the following code sets three name filters on a QDir
to ensure that only files with extensions typically used for C++
@@ -2110,7 +2112,7 @@ QString QDir::rootPath()
return QFileSystemEngine::rootPath();
}
-#ifndef QT_NO_REGEXP
+#if QT_CONFIG(regularexpression)
/*!
\overload
@@ -2118,13 +2120,18 @@ QString QDir::rootPath()
patterns in the list of \a filters; otherwise returns \c false. The
matching is case insensitive.
- \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList()
+ \sa {QRegularExpression Wildcard matching}, QRegularExpression::wildcardToRegularExpression(),
+ entryList(), entryInfoList()
*/
bool QDir::match(const QStringList &filters, const QString &fileName)
{
for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) {
- QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard);
- if (rx.exactMatch(fileName))
+ QString wildcard = QRegularExpression::wildcardToRegularExpression(*sit);
+ // Insensitive exact match
+ // (see Notes for QRegExp Users in QRegularExpression's documentation)
+ QRegularExpression rx(QLatin1String("\\A(?:") + wildcard + QLatin1String(")\\z"),
+ QRegularExpression::CaseInsensitiveOption);
+ if (rx.match(fileName).hasMatch())
return true;
}
return false;
@@ -2136,13 +2143,14 @@ bool QDir::match(const QStringList &filters, const QString &fileName)
contain multiple patterns separated by spaces or semicolons.
The matching is case insensitive.
- \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList()
+ \sa {QRegularExpression wildcard matching}, QRegularExpression::wildcardToRegularExpression,
+ entryList(), entryInfoList()
*/
bool QDir::match(const QString &filter, const QString &fileName)
{
return match(nameFiltersFromString(filter), fileName);
}
-#endif // QT_NO_REGEXP
+#endif // QT_CONFIG(regularexpression)
/*!
\internal
diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h
index 950a26f327..45c59d9e1d 100644
--- a/src/corelib/io/qdir.h
+++ b/src/corelib/io/qdir.h
@@ -206,7 +206,7 @@ public:
static inline QDir temp() { return QDir(tempPath()); }
static QString tempPath();
-#ifndef QT_NO_REGEXP
+#if QT_CONFIG(regularexpression)
static bool match(const QStringList &filters, const QString &fileName);
static bool match(const QString &filter, const QString &fileName);
#endif