Skip to content

Commit

Permalink
Get rid of QRegExp usage in qfiledialog
Browse files Browse the repository at this point in the history
and replace with QRegularExpression

Change-Id: Ic692fc0ea24da84dd4b6bb4c8a846c0fcc62c3cb
Reviewed-by: Shawn Rutledge <[email protected]>
Reviewed-by: Samuel Gaist <[email protected]>
  • Loading branch information
laknoll committed Mar 30, 2020
1 parent 3532c02 commit adc1be3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/widgets/dialogs/qfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
#if QT_CONFIG(mimetype)
#include <qmimedatabase.h>
#endif
#if QT_CONFIG(regularexpression)
#include <qregularexpression.h>
#endif
#include <qapplication.h>
#include <qstylepainter.h>
#include "ui_qfiledialog.h"
Expand Down Expand Up @@ -1413,18 +1416,22 @@ bool QFileDialog::isNameFilterDetailsVisible() const
*/
QStringList qt_strip_filters(const QStringList &filters)
{
#if QT_CONFIG(regularexpression)
QStringList strippedFilters;
QRegExp r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp));
QRegularExpression r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp));
const int numFilters = filters.count();
strippedFilters.reserve(numFilters);
for (int i = 0; i < numFilters; ++i) {
QString filterName;
int index = r.indexIn(filters[i]);
if (index >= 0)
filterName = r.cap(1);
auto match = r.match(filters[i]);
if (match.hasMatch())
filterName = match.captured(1);
strippedFilters.append(filterName.simplified());
}
return strippedFilters;
#else
return filters;
#endif
}


Expand Down Expand Up @@ -4369,16 +4376,14 @@ QStringList QFSCompleter::splitPath(const QString &path) const
}
#endif

QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']'));

#if defined(Q_OS_WIN)
QStringList parts = pathCopy.split(re, Qt::SkipEmptyParts);
QStringList parts = pathCopy.split(sep, Qt::SkipEmptyParts);
if (!doubleSlash.isEmpty() && !parts.isEmpty())
parts[0].prepend(doubleSlash);
if (pathCopy.endsWith(sep))
parts.append(QString());
#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
parts[0] = sep[0];
#endif
Expand Down

0 comments on commit adc1be3

Please sign in to comment.