FindAdv: Eliminate a corner case in the binary search

Given the regex 'r.*r\b' and a string
"abc regular something cursor currently"
we expect to find "regular something cursor".
But while searching we may be confronted with input
"regular something cursor curr"
and so the searched string would be seen longer.
This commit is contained in:
Kornel Benko 2018-11-27 19:10:27 +01:00
parent d2ea9c44b2
commit 1cd80ff6c8

View File

@ -2684,19 +2684,21 @@ int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match)
// Greedy behaviour while matching regexps
while (maxl > minl) {
int actual_match = match(cur, len);
if (actual_match == max_match) {
if (actual_match >= max_match) {
// actual_match > max_match _can_ happen,
// if the search area splits
// some following word so that the regex
// (e.g. 'r.*r\b' matches 'r' from the middle of the
// splitted word)
// This means, the len value is too big
maxl = len;
len = (int)((maxl + minl)/2);
}
else if (actual_match < max_match) {
else {
// (actual_match < max_match)
minl = len + 1;
len = (int)((maxl + minl)/2);
}
else {
// cannot happen, but in case of
LYXERR0("????");
max_match = actual_match;
}
}
}
return len;