Fix regex not always selecting the leftmost longest match

(Actually the rightmost longest match when searching backwards)

Fixes #2710
This commit is contained in:
Maxime Coste 2019-02-04 17:33:29 +11:00
parent 4cb402ac1a
commit d9d2140ea2
2 changed files with 7 additions and 1 deletions

View File

@ -1489,6 +1489,12 @@ auto test_regex = UnitTest{[]{
kak_assert(StringView{vm.captures()[0], vm.captures()[1]} == "baz");
}
{
TestVM<RegexMode::Backward | RegexMode::Search> vm{R"(a[^\n]*\n|\n)"};
kak_assert(vm.exec("foo\nbar\nb", RegexExecFlags::None));
kak_assert(StringView{vm.captures()[0], vm.captures()[1]} == "ar\n");
}
{
TestVM<> vm{R"(()*)"};
kak_assert(not vm.exec(" "));

View File

@ -510,7 +510,7 @@ private:
forward ? utf8::to_next(pos, config.subject_end)
: utf8::to_previous(pos, config.subject_begin);
if (search)
if (search and not m_found_match)
{
if (start_desc and m_threads.next_is_empty())
to_next_start(pos, config, *start_desc);