QtOutputFormatter: Convert to QRegularExpression

The greediness of QT_QML_URL_REGEXP was inverted by the "+?" operator.

Change-Id: I8e53009b85a5c933fdc44ebeddf9c9fb24772a56
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
Andre Hartmann
2019-01-26 21:21:07 +01:00
committed by André Hartmann
parent 597b44d1f5
commit e3522fd718
2 changed files with 62 additions and 61 deletions

View File

@@ -35,7 +35,7 @@
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QPointer> #include <QPointer>
#include <QRegExp> #include <QRegularExpression>
#include <QTextCursor> #include <QTextCursor>
#include <QUrl> #include <QUrl>
@@ -61,19 +61,18 @@ public:
, qtTestFailWin(QT_TEST_FAIL_WIN_REGEXP) , qtTestFailWin(QT_TEST_FAIL_WIN_REGEXP)
, project(proj) , project(proj)
{ {
qmlError.setMinimal(true);
} }
~QtOutputFormatterPrivate() ~QtOutputFormatterPrivate()
{ {
} }
QRegExp qmlError; const QRegularExpression qmlError;
QRegExp qtError; const QRegularExpression qtError;
QRegExp qtAssert; const QRegularExpression qtAssert;
QRegExp qtAssertX; const QRegularExpression qtAssertX;
QRegExp qtTestFailUnix; const QRegularExpression qtTestFailUnix;
QRegExp qtTestFailWin; const QRegularExpression qtTestFailWin;
QPointer<Project> project; QPointer<Project> project;
QString lastLine; QString lastLine;
FileInProjectFinder projectFinder; FileInProjectFinder projectFinder;
@@ -102,34 +101,31 @@ QtOutputFormatter::~QtOutputFormatter()
LinkResult QtOutputFormatter::matchLine(const QString &line) const LinkResult QtOutputFormatter::matchLine(const QString &line) const
{ {
LinkResult lr; LinkResult lr;
lr.start = -1;
lr.end = -1;
if (d->qmlError.indexIn(line) != -1) { auto hasMatch = [&lr, line](const QRegularExpression &regex) {
lr.href = d->qmlError.cap(1); const QRegularExpressionMatch match = regex.match(line);
lr.start = d->qmlError.pos(1); if (!match.hasMatch())
return false;
lr.href = match.captured(1);
lr.start = match.capturedStart(1);
lr.end = lr.start + lr.href.length(); lr.end = lr.start + lr.href.length();
} else if (d->qtError.indexIn(line) != -1) { return true;
lr.href = d->qtError.cap(1); };
lr.start = d->qtError.pos(1);
lr.end = lr.start + lr.href.length(); if (hasMatch(d->qmlError))
} else if (d->qtAssert.indexIn(line) != -1) { return lr;
lr.href = d->qtAssert.cap(1); if (hasMatch(d->qtError))
lr.start = d->qtAssert.pos(1); return lr;
lr.end = lr.start + lr.href.length(); if (hasMatch(d->qtAssert))
} else if (d->qtAssertX.indexIn(line) != -1) { return lr;
lr.href = d->qtAssertX.cap(1); if (hasMatch(d->qtAssertX))
lr.start = d->qtAssertX.pos(1); return lr;
lr.end = lr.start + lr.href.length(); if (hasMatch(d->qtTestFailUnix))
} else if (d->qtTestFailUnix.indexIn(line) != -1) { return lr;
lr.href = d->qtTestFailUnix.cap(1); if (hasMatch(d->qtTestFailWin))
lr.start = d->qtTestFailUnix.pos(1); return lr;
lr.end = lr.start + lr.href.length();
} else if (d->qtTestFailWin.indexIn(line) != -1) {
lr.href = d->qtTestFailWin.cap(1);
lr.start = d->qtTestFailWin.pos(1);
lr.end = lr.start + lr.href.length();
}
return lr; return lr;
} }
@@ -210,26 +206,28 @@ void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line,
void QtOutputFormatter::handleLink(const QString &href) void QtOutputFormatter::handleLink(const QString &href)
{ {
if (!href.isEmpty()) { if (!href.isEmpty()) {
QRegExp qmlLineColumnLink("^(" QT_QML_URL_REGEXP ")" // url static const QRegularExpression qmlLineColumnLink("^(" QT_QML_URL_REGEXP ")" // url
":(\\d+)" // line ":(\\d+)" // line
":(\\d+)$"); // column ":(\\d+)$"); // column
const QRegularExpressionMatch qmlLineColumnMatch = qmlLineColumnLink.match(href);
if (qmlLineColumnLink.indexIn(href) != -1) { if (qmlLineColumnMatch.hasMatch()) {
const QUrl fileUrl = QUrl(qmlLineColumnLink.cap(1)); const QUrl fileUrl = QUrl(qmlLineColumnMatch.captured(1));
const int line = qmlLineColumnLink.cap(2).toInt(); const int line = qmlLineColumnMatch.captured(2).toInt();
const int column = qmlLineColumnLink.cap(3).toInt(); const int column = qmlLineColumnMatch.captured(3).toInt();
openEditor(d->projectFinder.findFile(fileUrl), line, column - 1); openEditor(d->projectFinder.findFile(fileUrl), line, column - 1);
return; return;
} }
QRegExp qmlLineLink("^(" QT_QML_URL_REGEXP ")" // url static const QRegularExpression qmlLineLink("^(" QT_QML_URL_REGEXP ")" // url
":(\\d+)$"); // line ":(\\d+)$"); // line
const QRegularExpressionMatch qmlLineMatch = qmlLineLink.match(href);
if (qmlLineLink.indexIn(href) != -1) { if (qmlLineMatch.hasMatch()) {
const QUrl fileUrl = QUrl(qmlLineLink.cap(1)); const QUrl fileUrl = QUrl(qmlLineMatch.captured(1));
const int line = qmlLineLink.cap(2).toInt(); const int line = qmlLineMatch.captured(2).toInt();
openEditor(d->projectFinder.findFile(d->projectFinder.findFile(fileUrl)), line); openEditor(d->projectFinder.findFile(d->projectFinder.findFile(fileUrl)), line);
return; return;
} }
@@ -237,22 +235,25 @@ void QtOutputFormatter::handleLink(const QString &href)
QString fileName; QString fileName;
int line = -1; int line = -1;
QRegExp qtErrorLink("^(.*):(\\d+)$"); static const QRegularExpression qtErrorLink("^(.*):(\\d+)$");
if (qtErrorLink.indexIn(href) != -1) { const QRegularExpressionMatch qtErrorMatch = qtErrorLink.match(href);
fileName = qtErrorLink.cap(1); if (qtErrorMatch.hasMatch()) {
line = qtErrorLink.cap(2).toInt(); fileName = qtErrorMatch.captured(1);
line = qtErrorMatch.captured(2).toInt();
} }
QRegExp qtAssertLink("^(.+), line (\\d+)$"); static const QRegularExpression qtAssertLink("^(.+), line (\\d+)$");
if (qtAssertLink.indexIn(href) != -1) { const QRegularExpressionMatch qtAssertMatch = qtAssertLink.match(href);
fileName = qtAssertLink.cap(1); if (qtAssertMatch.hasMatch()) {
line = qtAssertLink.cap(2).toInt(); fileName = qtAssertMatch.captured(1);
line = qtAssertMatch.captured(2).toInt();
} }
QRegExp qtTestFailLink("^(.*)\\((\\d+)\\)$"); static const QRegularExpression qtTestFailLink("^(.*)\\((\\d+)\\)$");
if (qtTestFailLink.indexIn(href) != -1) { const QRegularExpressionMatch qtTestFailMatch = qtTestFailLink.match(href);
fileName = qtTestFailLink.cap(1); if (qtTestFailMatch.hasMatch()) {
line = qtTestFailLink.cap(2).toInt(); fileName = qtTestFailMatch.captured(1);
line = qtTestFailMatch.captured(2).toInt();
} }
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {

View File

@@ -30,7 +30,7 @@
#include <utils/outputformatter.h> #include <utils/outputformatter.h>
// "file" or "qrc", colon, optional '//', '/' and further characters // "file" or "qrc", colon, optional '//', '/' and further characters
#define QT_QML_URL_REGEXP "(?:file|qrc):(?://)?/.+" #define QT_QML_URL_REGEXP "(?:file|qrc):(?://)?/.+?"
#define QT_ASSERT_REGEXP "ASSERT: .* in file (.+, line \\d+)" #define QT_ASSERT_REGEXP "ASSERT: .* in file (.+, line \\d+)"
#define QT_ASSERT_X_REGEXP "ASSERT failure in .*: \".*\", file (.+, line \\d+)" #define QT_ASSERT_X_REGEXP "ASSERT failure in .*: \".*\", file (.+, line \\d+)"
#define QT_TEST_FAIL_UNIX_REGEXP "^ Loc: \\[(.*)\\]$" #define QT_TEST_FAIL_UNIX_REGEXP "^ Loc: \\[(.*)\\]$"
@@ -42,8 +42,8 @@ namespace QtSupport {
struct LinkResult struct LinkResult
{ {
int start; int start = -1;
int end; int end = -1;
QString href; QString href;
}; };