Utils: Replace QRegExp by QRegularExpression

Task-number: QTCREATORBUG-24098
Change-Id: I0e29d2a43de6ff29dfeb5c9c70ac18ed95ba2657
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2020-07-17 09:14:44 +02:00
parent 42ab5c84b9
commit f154b23c78
3 changed files with 26 additions and 22 deletions

View File

@@ -26,7 +26,7 @@
#include "filenamevalidatinglineedit.h"
#include "qtcassert.h"
#include <QRegExp>
#include <QRegularExpression>
#include <QDebug>
/*!
@@ -46,16 +46,18 @@ namespace Utils {
// Naming a file like a device name will break on Windows, even if it is
// "com1.txt". Since we are cross-platform, we generally disallow such file
// names.
static const QRegExp &windowsDeviceNoSubDirPattern()
static const QRegularExpression &windowsDeviceNoSubDirPattern()
{
static const QRegExp rc(QLatin1String(WINDOWS_DEVICES_PATTERN), Qt::CaseInsensitive);
static const QRegularExpression rc(QString("^" WINDOWS_DEVICES_PATTERN "$"),
QRegularExpression::CaseInsensitiveOption);
QTC_ASSERT(rc.isValid(), return rc);
return rc;
}
static const QRegExp &windowsDeviceSubDirPattern()
static const QRegularExpression &windowsDeviceSubDirPattern()
{
static const QRegExp rc(QLatin1String(".*[/\\\\]" WINDOWS_DEVICES_PATTERN), Qt::CaseInsensitive);
static const QRegularExpression rc(QString("^.*[/\\\\]" WINDOWS_DEVICES_PATTERN "$"),
QRegularExpression::CaseInsensitiveOption);
QTC_ASSERT(rc.isValid(), return rc);
return rc;
}
@@ -135,9 +137,9 @@ bool FileNameValidatingLineEdit::validateFileName(const QString &name,
}
}
// Windows devices
bool matchesWinDevice = windowsDeviceNoSubDirPattern().exactMatch(name);
bool matchesWinDevice = name.contains(windowsDeviceNoSubDirPattern());
if (!matchesWinDevice && allowDirectories)
matchesWinDevice = windowsDeviceSubDirPattern().exactMatch(name);
matchesWinDevice = name.contains(windowsDeviceSubDirPattern());
if (matchesWinDevice) {
if (errorMessage)
*errorMessage = tr("Name matches MS Windows device"