Commit 897f854e authored by Kåre Särs's avatar Kåre Särs
Browse files

Review improvement suggestions by Ahmad Samir

const regular expressions
fix typos
better remove() calls
parent 16c2b91d
......@@ -266,20 +266,20 @@ QRegularExpressionMatch MatchModel::rangeTextMatches(const QString &rangeText, c
QRegularExpression tmpReg = regExp;
QString pattern = tmpReg.pattern();
// NOTE: Negative look-ahead/behind i snot a problem as they are not part of the range
static QRegularExpression lookaheadRegex(QStringLiteral(".*(\\(\\?=[^\\)]+\\))"));
static QRegularExpression lookbehindRegex(QStringLiteral("(\\(\\?<=[^\\)]+\\)).*"));
// NOTE: Negative look-ahead/behind are not a problem as they are not part of the range
static const QRegularExpression lookaheadRegex(QStringLiteral(".*(\\(\\?=[^\\)]+\\))"));
static const QRegularExpression lookbehindRegex(QStringLiteral("(\\(\\?<=[^\\)]+\\)).*"));
// Remove possible lookahead as we do not have the tail to compare with
auto lookMatch = lookaheadRegex.match(pattern);
if (lookMatch.hasMatch()) {
pattern.remove(lookMatch.captured(1));
pattern.remove(lookMatch.capturedStart(1), lookMatch.capturedLength(1));
tmpReg.setPattern(pattern);
}
// Remove possible lookbehind as we do not have the prefix
lookMatch = lookbehindRegex.match(pattern);
if (lookMatch.hasMatch()) {
pattern.remove(lookMatch.captured(1));
pattern.remove(lookMatch.capturedStart(1), lookMatch.capturedLength(1));
tmpReg.setPattern(pattern);
}
......
In this file we check that regular expression lookahead and lookbehind works as expected.
The following three lines are test data
The following four lines are test data
1) Foo 123ABC123
2) Foo ABC
3) Foo BARABCDEF
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment