QtSupport: Replace QRegExp by QRegularExpression

Task-number: QTCREATORBUG-24098
Change-Id: I1eefae2473919e3d2f9fa93d7d54797effd4a5f2
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2020-06-16 08:59:54 +02:00
parent d8b1fcb9d3
commit 241b24486e
3 changed files with 18 additions and 20 deletions

View File

@@ -25,8 +25,6 @@
#include "qtkitinformation.h" #include "qtkitinformation.h"
#include <QRegExp>
#include "qtsupportconstants.h" #include "qtsupportconstants.h"
#include "qtversionmanager.h" #include "qtversionmanager.h"
#include "qtparser.h" #include "qtparser.h"

View File

@@ -44,12 +44,10 @@ namespace QtSupport {
#define FILE_PATTERN "^(([A-Za-z]:)?[^:]+\\.[^:]+)" #define FILE_PATTERN "^(([A-Za-z]:)?[^:]+\\.[^:]+)"
QtParser::QtParser() : QtParser::QtParser() :
m_mocRegExp(QLatin1String(FILE_PATTERN"[:\\(](\\d+)\\)?:\\s([Ww]arning|[Ee]rror|[Nn]ote):\\s(.+)$")), m_mocRegExp(QLatin1String(FILE_PATTERN"[:\\(](\\d+?)\\)?:\\s([Ww]arning|[Ee]rror|[Nn]ote):\\s(.+?)$")),
m_translationRegExp(QLatin1String("^([Ww]arning|[Ee]rror):\\s+(.*) in '(.*)'$")) m_translationRegExp(QLatin1String("^([Ww]arning|[Ee]rror):\\s+(.*?) in '(.*?)'$"))
{ {
setObjectName(QLatin1String("QtParser")); setObjectName(QLatin1String("QtParser"));
m_mocRegExp.setMinimal(true);
m_translationRegExp.setMinimal(true);
} }
Utils::OutputLineParser::Result QtParser::handleLine(const QString &line, Utils::OutputFormat type) Utils::OutputLineParser::Result QtParser::handleLine(const QString &line, Utils::OutputFormat type)
@@ -58,34 +56,36 @@ Utils::OutputLineParser::Result QtParser::handleLine(const QString &line, Utils:
return Status::NotHandled; return Status::NotHandled;
QString lne = rightTrimmed(line); QString lne = rightTrimmed(line);
if (m_mocRegExp.indexIn(lne) > -1) { QRegularExpressionMatch match = m_mocRegExp.match(lne);
if (match.hasMatch()) {
bool ok; bool ok;
int lineno = m_mocRegExp.cap(3).toInt(&ok); int lineno = match.captured(3).toInt(&ok);
if (!ok) if (!ok)
lineno = -1; lineno = -1;
Task::TaskType type = Task::Error; Task::TaskType type = Task::Error;
const QString level = m_mocRegExp.cap(4); const QString level = match.captured(4);
if (level.compare(QLatin1String("Warning"), Qt::CaseInsensitive) == 0) if (level.compare(QLatin1String("Warning"), Qt::CaseInsensitive) == 0)
type = Task::Warning; type = Task::Warning;
if (level.compare(QLatin1String("Note"), Qt::CaseInsensitive) == 0) if (level.compare(QLatin1String("Note"), Qt::CaseInsensitive) == 0)
type = Task::Unknown; type = Task::Unknown;
LinkSpecs linkSpecs; LinkSpecs linkSpecs;
const Utils::FilePath file const Utils::FilePath file
= absoluteFilePath(Utils::FilePath::fromUserInput(m_mocRegExp.cap(1))); = absoluteFilePath(Utils::FilePath::fromUserInput(match.captured(1)));
addLinkSpecForAbsoluteFilePath(linkSpecs, file, lineno, m_mocRegExp, 1); addLinkSpecForAbsoluteFilePath(linkSpecs, file, lineno, match, 1);
CompileTask task(type, m_mocRegExp.cap(5).trimmed() /* description */, file, lineno); CompileTask task(type, match.captured(5).trimmed() /* description */, file, lineno);
scheduleTask(task, 1); scheduleTask(task, 1);
return {Status::Done, linkSpecs}; return {Status::Done, linkSpecs};
} }
if (m_translationRegExp.indexIn(lne) > -1) { match = m_translationRegExp.match(line);
if (match.hasMatch()) {
Task::TaskType type = Task::Warning; Task::TaskType type = Task::Warning;
if (m_translationRegExp.cap(1) == QLatin1String("Error")) if (match.captured(1) == QLatin1String("Error"))
type = Task::Error; type = Task::Error;
LinkSpecs linkSpecs; LinkSpecs linkSpecs;
const Utils::FilePath file const Utils::FilePath file
= absoluteFilePath(Utils::FilePath::fromUserInput(m_translationRegExp.cap(3))); = absoluteFilePath(Utils::FilePath::fromUserInput(match.captured(3)));
addLinkSpecForAbsoluteFilePath(linkSpecs, file, 0, m_translationRegExp, 3); addLinkSpecForAbsoluteFilePath(linkSpecs, file, 0, match, 3);
CompileTask task(type, m_translationRegExp.cap(2), file); CompileTask task(type, match.captured(2), file);
scheduleTask(task, 1); scheduleTask(task, 1);
return {Status::Done, linkSpecs}; return {Status::Done, linkSpecs};
} }

View File

@@ -25,7 +25,7 @@
#pragma once #pragma once
#include <QRegExp> #include <QRegularExpression>
#include "qtsupport_global.h" #include "qtsupport_global.h"
#include <projectexplorer/ioutputparser.h> #include <projectexplorer/ioutputparser.h>
@@ -44,8 +44,8 @@ public:
private: private:
Result handleLine(const QString &line, Utils::OutputFormat type) override; Result handleLine(const QString &line, Utils::OutputFormat type) override;
QRegExp m_mocRegExp; QRegularExpression m_mocRegExp;
QRegExp m_translationRegExp; QRegularExpression m_translationRegExp;
}; };
} // namespace QtSupport } // namespace QtSupport