From 9305fa136918010fab36c09e7174c5a45b422141 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 Oct 2017 11:20:05 +0800 Subject: [PATCH] Regex: Fix lookaround use in moon.kak (?=[A-Z]\w*) is strictly the same as (?=[A-Z]) as \w* will always at least match an empty string. --- src/regex_impl.cc | 4 ++-- src/regex_impl.hh | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 2e3b9ccf..6673695d 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -1067,13 +1067,13 @@ auto test_regex = UnitTest{[]{ } { - TestVM<> vm{R"((?!foo)...)"}; + TestVM<> vm{R"((?!f[oa]o)...)"}; kak_assert(not vm.exec("foo")); kak_assert(vm.exec("qux")); } { - TestVM<> vm{R"(...(?<=foo))"}; + TestVM<> vm{R"(...(?<=f.o))"}; kak_assert(vm.exec("foo")); kak_assert(not vm.exec("qux")); } diff --git a/src/regex_impl.hh b/src/regex_impl.hh index cb5a53be..d18de8a1 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -388,8 +388,11 @@ private: auto cp = (look_direction == MatchDirection::Forward ? *pos : *(pos-1)), ref = *it; if (ref == 0xF000) {} // any character matches - else if (ref > 0xF0000 and ref <= 0xFFFFD and not m_program.matchers[ref - 0xF0001](cp)) - return false; + else if (ref > 0xF0000 and ref <= 0xFFFFD) + { + if (not m_program.matchers[ref - 0xF0001](cp)) + return false; + } else if (ref != cp) return false;