some minor QRegularExpression usage optimizations and cleanups (#3999)

This commit is contained in:
Oliver Stöneberg 2022-04-11 19:15:42 +02:00 committed by GitHub
parent 375df3a6af
commit 902f46bae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 9 deletions

View File

@ -307,8 +307,8 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
{
QList<ErrorItem> errorItems;
ErrorItem errorItem;
const QRegularExpression r1("^(.+):([0-9]+):([0-9]+): (note|warning|error|fatal error): (.*)$");
const QRegularExpression r2("^(.*)\\[([a-zA-Z0-9\\-_\\.]+)\\]$");
static const QRegularExpression r1("^(.+):([0-9]+):([0-9]+): (note|warning|error|fatal error): (.*)$");
static const QRegularExpression r2("^(.*)\\[([a-zA-Z0-9\\-_\\.]+)\\]$");
QTextStream in(&err, QIODevice::ReadOnly);
while (!in.atEnd()) {
QString line = in.readLine();

View File

@ -28,7 +28,7 @@ LibraryAddFunctionDialog::LibraryAddFunctionDialog(QWidget *parent) :
mUi(new Ui::LibraryAddFunctionDialog)
{
mUi->setupUi(this);
const QRegularExpression rx(NAMES);
static const QRegularExpression rx(NAMES);
QValidator *validator = new QRegularExpressionValidator(rx, this);
mUi->functionName->setValidator(validator);
}

View File

@ -262,9 +262,9 @@ void MainWindow::handleCLIParams(const QStringList &params)
} else {
loadResults(logFile);
}
} else if ((index = params.indexOf(QRegularExpression(".*\\.cppcheck$", QRegularExpression::CaseInsensitiveOption), 0)) >= 0 && index < params.length() && QFile(params[index]).exists()) {
} else if ((index = params.indexOf(QRegularExpression(".*\\.cppcheck$", QRegularExpression::CaseInsensitiveOption))) >= 0 && index < params.length() && QFile(params[index]).exists()) {
loadProjectFile(params[index]);
} else if ((index = params.indexOf(QRegularExpression(".*\\.xml$", QRegularExpression::CaseInsensitiveOption), 0)) >= 0 && index < params.length() && QFile(params[index]).exists()) {
} else if ((index = params.indexOf(QRegularExpression(".*\\.xml$", QRegularExpression::CaseInsensitiveOption))) >= 0 && index < params.length() && QFile(params[index]).exists()) {
loadResults(params[index],QDir::currentPath());
} else
doAnalyzeFiles(params);
@ -1142,8 +1142,11 @@ void MainWindow::clearResults()
if (mProjectFile && !mProjectFile->getBuildDir().isEmpty()) {
QDir dir(QFileInfo(mProjectFile->getFilename()).absolutePath() + '/' + mProjectFile->getBuildDir());
for (const QString& f: dir.entryList(QDir::Files)) {
if (!f.endsWith("files.txt") && !QRegularExpression("^.*.s[0-9]+$").match(f).hasMatch())
dir.remove(f);
if (!f.endsWith("files.txt")) {
static const QRegularExpression rx("^.*.s[0-9]+$");
if (!rx.match(f).hasMatch())
dir.remove(f);
}
}
}
mUI->mResults->clear(true);

View File

@ -406,7 +406,7 @@ QLineSeries *StatsDialog::numberOfReports(const QString &fileName, const QString
QTextStream in(&f);
while (!in.atEnd()) {
QString line = in.readLine();
const QRegularExpression rxdate("^\\[(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)\\]$");
static const QRegularExpression rxdate("^\\[(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)\\]$");
const QRegularExpressionMatch matchRes = rxdate.match(line);
if (matchRes.hasMatch()) {
int y = matchRes.captured(3).toInt();

View File

@ -111,7 +111,10 @@ void MainWindow::load(QTextStream &textStream)
if (!errorMessage.isEmpty())
mAllErrors << errorMessage;
errorMessage.clear();
} else if (!url.isEmpty() && QRegularExpression("^.*: (error|warning|style|note):.*$").match(line).hasMatch()) {
} else if (!url.isEmpty()) {
static const QRegularExpression severityRe("^.*: (error|warning|style|note):.*$");
if (severityRe.match(line).hasMatch())
continue;
const QRegularExpressionMatch matchRes = mVersionRe.match(line);
if (matchRes.hasMatch()) {
const QString version = matchRes.captured(1);