Get rid of QRegExp usage in qfiledialog

and replace with QRegularExpression

Change-Id: Ic692fc0ea24da84dd4b6bb4c8a846c0fcc62c3cb
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
Lars Knoll 2020-03-25 12:48:49 +01:00
parent 3532c0256d
commit adc1be3c33

View File

@ -68,6 +68,9 @@
#if QT_CONFIG(mimetype) #if QT_CONFIG(mimetype)
#include <qmimedatabase.h> #include <qmimedatabase.h>
#endif #endif
#if QT_CONFIG(regularexpression)
#include <qregularexpression.h>
#endif
#include <qapplication.h> #include <qapplication.h>
#include <qstylepainter.h> #include <qstylepainter.h>
#include "ui_qfiledialog.h" #include "ui_qfiledialog.h"
@ -1413,18 +1416,22 @@ bool QFileDialog::isNameFilterDetailsVisible() const
*/ */
QStringList qt_strip_filters(const QStringList &filters) QStringList qt_strip_filters(const QStringList &filters)
{ {
#if QT_CONFIG(regularexpression)
QStringList strippedFilters; QStringList strippedFilters;
QRegExp r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp)); QRegularExpression r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp));
const int numFilters = filters.count(); const int numFilters = filters.count();
strippedFilters.reserve(numFilters); strippedFilters.reserve(numFilters);
for (int i = 0; i < numFilters; ++i) { for (int i = 0; i < numFilters; ++i) {
QString filterName; QString filterName;
int index = r.indexIn(filters[i]); auto match = r.match(filters[i]);
if (index >= 0) if (match.hasMatch())
filterName = r.cap(1); filterName = match.captured(1);
strippedFilters.append(filterName.simplified()); strippedFilters.append(filterName.simplified());
} }
return strippedFilters; return strippedFilters;
#else
return filters;
#endif
} }
@ -4369,16 +4376,14 @@ QStringList QFSCompleter::splitPath(const QString &path) const
} }
#endif #endif
QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']'));
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QStringList parts = pathCopy.split(re, Qt::SkipEmptyParts); QStringList parts = pathCopy.split(sep, Qt::SkipEmptyParts);
if (!doubleSlash.isEmpty() && !parts.isEmpty()) if (!doubleSlash.isEmpty() && !parts.isEmpty())
parts[0].prepend(doubleSlash); parts[0].prepend(doubleSlash);
if (pathCopy.endsWith(sep)) if (pathCopy.endsWith(sep))
parts.append(QString()); parts.append(QString());
#else #else
QStringList parts = pathCopy.split(re); QStringList parts = pathCopy.split(sep);
if (pathCopy[0] == sep[0]) // read the "/" at the beginning as the split removed it if (pathCopy[0] == sep[0]) // read the "/" at the beginning as the split removed it
parts[0] = sep[0]; parts[0] = sep[0];
#endif #endif