Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
897f854e
Commit
897f854e
authored
Feb 08, 2022
by
Kåre Särs
Browse files
Review improvement suggestions by Ahmad Samir
const regular expressions fix typos better remove() calls
parent
16c2b91d
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/search/MatchModel.cpp
View file @
897f854e
...
...
@@ -266,20 +266,20 @@ QRegularExpressionMatch MatchModel::rangeTextMatches(const QString &rangeText, c
QRegularExpression
tmpReg
=
regExp
;
QString
pattern
=
tmpReg
.
pattern
();
// NOTE: Negative look-ahead/behind
i s
not 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
.
captured
Start
(
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
.
captured
Start
(
1
),
lookMatch
.
capturedLength
(
1
));
tmpReg
.
setPattern
(
pattern
);
}
...
...
addons/search/autotest/input/LookaheadLookbehindTestFile.txt
View file @
897f854e
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment