CMakePM: Replace some QRegExp by QRegularExpression

Task-number: QTCREATORBUG-24098
Change-Id: Ib40d97cf2b39105e7db9f886c125a2430119d14d
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2020-06-16 08:54:25 +02:00
parent 328c0cf809
commit d8b1fcb9d3
2 changed files with 22 additions and 21 deletions

View File

@@ -34,18 +34,16 @@ using namespace Utils;
namespace CMakeProjectManager {
const char COMMON_ERROR_PATTERN[] = "^CMake Error at (.*):([0-9]*)( \\((.*)\\))?:";
const char NEXT_SUBERROR_PATTERN[] = "^CMake Error in (.*):";
const char LOCATION_LINE_PATTERN[] = ":(\\d+):(?:(\\d+))?$";
const char COMMON_ERROR_PATTERN[] = "^CMake Error at (.*?):([0-9]*?)( \\((.*?)\\))?:";
const char NEXT_SUBERROR_PATTERN[] = "^CMake Error in (.*?):";
const char LOCATION_LINE_PATTERN[] = ":(\\d+?):(?:(\\d+?))?$";
CMakeParser::CMakeParser()
{
m_commonError.setPattern(QLatin1String(COMMON_ERROR_PATTERN));
m_commonError.setMinimal(true);
QTC_CHECK(m_commonError.isValid());
m_nextSubError.setPattern(QLatin1String(NEXT_SUBERROR_PATTERN));
m_nextSubError.setMinimal(true);
QTC_CHECK(m_nextSubError.isValid());
m_locationLine.setPattern(QLatin1String(LOCATION_LINE_PATTERN));
@@ -65,6 +63,7 @@ OutputLineParser::Result CMakeParser::handleLine(const QString &line, OutputForm
if (type != StdErrFormat)
return Status::NotHandled;
QRegularExpressionMatch match;
QString trimmedLine = rightTrimmed(line);
switch (m_expectTripleLineErrorData) {
case NONE:
@@ -79,25 +78,28 @@ OutputLineParser::Result CMakeParser::handleLine(const QString &line, OutputForm
if (m_skippedFirstEmptyLine)
m_skippedFirstEmptyLine = false;
if (m_commonError.indexIn(trimmedLine) != -1) {
match = m_commonError.match(trimmedLine);
if (match.hasMatch()) {
QString path = m_sourceDirectory ? m_sourceDirectory->absoluteFilePath(
QDir::fromNativeSeparators(m_commonError.cap(1)))
: QDir::fromNativeSeparators(m_commonError.cap(1));
QDir::fromNativeSeparators(match.captured(1)))
: QDir::fromNativeSeparators(match.captured(1));
m_lastTask = BuildSystemTask(Task::Error,
QString(),
absoluteFilePath(FilePath::fromUserInput(path)),
m_commonError.cap(2).toInt());
match.captured(2).toInt());
m_lines = 1;
LinkSpecs linkSpecs;
addLinkSpecForAbsoluteFilePath(linkSpecs, m_lastTask.file, m_lastTask.line,
m_commonError, 1);
match, 1);
return {Status::InProgress, linkSpecs};
} else if (m_nextSubError.indexIn(trimmedLine) != -1) {
}
match = m_nextSubError.match(trimmedLine);
if (match.hasMatch()) {
m_lastTask = BuildSystemTask(Task::Error, QString(),
absoluteFilePath(FilePath::fromUserInput(m_nextSubError.cap(1))));
absoluteFilePath(FilePath::fromUserInput(match.captured(1))));
LinkSpecs linkSpecs;
addLinkSpecForAbsoluteFilePath(linkSpecs, m_lastTask.file, m_lastTask.line,
m_nextSubError, 1);
match, 1);
m_lines = 1;
return {Status::InProgress, linkSpecs};
} else if (trimmedLine.startsWith(QLatin1String(" ")) && !m_lastTask.isNull()) {
@@ -124,15 +126,15 @@ OutputLineParser::Result CMakeParser::handleLine(const QString &line, OutputForm
return Status::NotHandled;
case LINE_LOCATION:
{
QRegularExpressionMatch m = m_locationLine.match(trimmedLine);
QTC_CHECK(m.hasMatch());
match = m_locationLine.match(trimmedLine);
QTC_CHECK(match.hasMatch());
m_lastTask.file = absoluteFilePath(FilePath::fromUserInput(
trimmedLine.mid(0, m.capturedStart())));
m_lastTask.line = m.captured(1).toInt();
trimmedLine.mid(0, match.capturedStart())));
m_lastTask.line = match.captured(1).toInt();
m_expectTripleLineErrorData = LINE_DESCRIPTION;
LinkSpecs linkSpecs;
addLinkSpecForAbsoluteFilePath(linkSpecs, m_lastTask.file, m_lastTask.line, 0,
m.capturedStart());
match.capturedStart());
return {Status::InProgress, linkSpecs};
}
case LINE_DESCRIPTION:

View File

@@ -33,7 +33,6 @@
#include <utils/optional.h>
#include <QDir>
#include <QRegExp>
#include <QRegularExpression>
namespace CMakeProjectManager {
@@ -56,8 +55,8 @@ private:
Utils::optional<QDir> m_sourceDirectory;
ProjectExplorer::Task m_lastTask;
QRegExp m_commonError;
QRegExp m_nextSubError;
QRegularExpression m_commonError;
QRegularExpression m_nextSubError;
QRegularExpression m_locationLine;
bool m_skippedFirstEmptyLine = false;
int m_lines = 0;