PE: Replace some QRegExp by QRegularExpression

Task-number: QTCREATORBUG-24098
Change-Id: I6d9fde23d5d7a1d3fab3723a22ba385ebaee04a0
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2020-06-16 08:57:19 +02:00
parent 8a697cde64
commit ad7f673ad1
2 changed files with 36 additions and 36 deletions

View File

@@ -39,29 +39,25 @@ LinuxIccParser::LinuxIccParser() :
setObjectName(QLatin1String("LinuxIccParser")); setObjectName(QLatin1String("LinuxIccParser"));
// main.cpp(53): error #308: function \"AClass::privatefunc\" (declared at line 4 of \"main.h\") is inaccessible // main.cpp(53): error #308: function \"AClass::privatefunc\" (declared at line 4 of \"main.h\") is inaccessible
m_firstLine.setPattern(QLatin1String("^([^\\(\\)]+)" // filename (cap 1) m_firstLine.setPattern(QLatin1String("^([^\\(\\)]+?)" // filename (cap 1)
"\\((\\d+)\\):" // line number including : (cap 2) "\\((\\d+?)\\):" // line number including : (cap 2)
" ((error|warning)( #\\d+)?: )?" // optional type (cap 4) and optional error number // TODO really optional ? " ((error|warning)( #\\d+?)?: )?" // optional type (cap 4) and optional error number // TODO really optional ?
"(.*)$")); // description (cap 6) "(.*?)$")); // description (cap 6)
//m_firstLine.setMinimal(true);
QTC_CHECK(m_firstLine.isValid()); QTC_CHECK(m_firstLine.isValid());
// Note pattern also matches caret lines // Note pattern also matches caret lines
m_continuationLines.setPattern(QLatin1String("^\\s+" // At least one whitespace m_continuationLines.setPattern(QLatin1String("^\\s+" // At least one whitespace
"(.*)$"));// description "(.*)$"));// description
m_continuationLines.setMinimal(true);
QTC_CHECK(m_continuationLines.isValid()); QTC_CHECK(m_continuationLines.isValid());
m_caretLine.setPattern(QLatin1String("^\\s*" // Whitespaces m_caretLine.setPattern(QLatin1String("^\\s*?" // Whitespaces
"\\^" // a caret "\\^" // a caret
"\\s*$")); // and again whitespaces "\\s*?$")); // and again whitespaces
m_caretLine.setMinimal(true);
QTC_CHECK(m_caretLine.isValid()); QTC_CHECK(m_caretLine.isValid());
// ".pch/Qt5Core.pchi.cpp": creating precompiled header file ".pch/Qt5Core.pchi" // ".pch/Qt5Core.pchi.cpp": creating precompiled header file ".pch/Qt5Core.pchi"
// "animation/qabstractanimation.cpp": using precompiled header file ".pch/Qt5Core.pchi" // "animation/qabstractanimation.cpp": using precompiled header file ".pch/Qt5Core.pchi"
m_pchInfoLine.setPattern(QLatin1String("^\".*\": (creating|using) precompiled header file \".*\"\n$")); m_pchInfoLine.setPattern(QLatin1String("^\".*?\": (creating|using) precompiled header file \".*?\"\n$"));
m_pchInfoLine.setMinimal(true);
QTC_CHECK(m_pchInfoLine.isValid()); QTC_CHECK(m_pchInfoLine.isValid());
} }
@@ -70,28 +66,31 @@ OutputLineParser::Result LinuxIccParser::handleLine(const QString &line, OutputF
if (type != Utils::StdErrFormat) if (type != Utils::StdErrFormat)
return Status::NotHandled; return Status::NotHandled;
if (m_pchInfoLine.indexIn(line) != -1) if (line.indexOf(m_pchInfoLine) != -1)
return Status::Done; // totally ignore this line return Status::Done; // totally ignore this line
if (m_expectFirstLine && m_firstLine.indexIn(line) != -1) { if (m_expectFirstLine) {
const QRegularExpressionMatch match = m_firstLine.match(line);
if (match.hasMatch()) {
// Clear out old task // Clear out old task
Task::TaskType type = Task::Unknown; Task::TaskType type = Task::Unknown;
QString category = m_firstLine.cap(4); QString category = match.captured(4);
if (category == QLatin1String("error")) if (category == QLatin1String("error"))
type = Task::Error; type = Task::Error;
else if (category == QLatin1String("warning")) else if (category == QLatin1String("warning"))
type = Task::Warning; type = Task::Warning;
const FilePath filePath = absoluteFilePath(FilePath::fromUserInput(m_firstLine.cap(1))); const FilePath filePath = absoluteFilePath(FilePath::fromUserInput(match.captured(1)));
const int lineNo = m_firstLine.cap(2).toInt(); const int lineNo = match.captured(2).toInt();
LinkSpecs linkSpecs; LinkSpecs linkSpecs;
addLinkSpecForAbsoluteFilePath(linkSpecs, filePath, lineNo, m_firstLine, 1); addLinkSpecForAbsoluteFilePath(linkSpecs, filePath, lineNo, match, 1);
m_temporary = CompileTask(type, m_firstLine.cap(6).trimmed(), filePath, lineNo); m_temporary = CompileTask(type, match.captured(6).trimmed(), filePath, lineNo);
m_lines = 1; m_lines = 1;
m_expectFirstLine = false; m_expectFirstLine = false;
return Status::InProgress; return Status::InProgress;
} }
if (!m_expectFirstLine && m_caretLine.indexIn(line) != -1) { }
if (!m_expectFirstLine && line.indexOf(m_caretLine) != -1) {
// FIXME: m_temporary.details.append(line); // FIXME: m_temporary.details.append(line);
return Status::InProgress; return Status::InProgress;
} }
@@ -101,8 +100,9 @@ OutputLineParser::Result LinuxIccParser::handleLine(const QString &line, OutputF
m_temporary = Task(); m_temporary = Task();
return Status::Done; return Status::Done;
} }
if (!m_expectFirstLine && m_continuationLines.indexIn(line) != -1) { const QRegularExpressionMatch match = m_continuationLines.match(line);
m_temporary.details.append(m_continuationLines.cap(1).trimmed()); if (!m_expectFirstLine && match.hasMatch()) {
m_temporary.details.append(match.captured(1).trimmed());
++m_lines; ++m_lines;
return Status::InProgress; return Status::InProgress;
} }

View File

@@ -28,7 +28,7 @@
#include "ioutputparser.h" #include "ioutputparser.h"
#include "task.h" #include "task.h"
#include <QRegExp> #include <QRegularExpression>
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -47,10 +47,10 @@ private:
Result handleLine(const QString &line, Utils::OutputFormat type) override; Result handleLine(const QString &line, Utils::OutputFormat type) override;
void flush() override; void flush() override;
QRegExp m_firstLine; QRegularExpression m_firstLine;
QRegExp m_continuationLines; QRegularExpression m_continuationLines;
QRegExp m_caretLine; QRegularExpression m_caretLine;
QRegExp m_pchInfoLine; QRegularExpression m_pchInfoLine;
bool m_expectFirstLine = true; bool m_expectFirstLine = true;
Task m_temporary; Task m_temporary;