From b4f923b7fc53a83d0f6243d5b524cc7d4fc58c8f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 2 Oct 2017 15:35:21 +0800 Subject: [PATCH] Regex: min/max quantifiers can be non greedy as well --- src/regex_impl.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index c8c5bc05..26bbcb7e 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -441,7 +441,7 @@ private: if (*it++ != '}') parse_error("expected closing bracket"); m_pos = it; - return {ParsedRegex::Quantifier::RepeatMinMax, true, min, max}; + return {ParsedRegex::Quantifier::RepeatMinMax, check_greedy(), min, max}; } default: return {ParsedRegex::Quantifier::One}; } @@ -920,6 +920,23 @@ auto test_regex = UnitTest{[]{ kak_assert(not vm.exec("efg")); } + { + TestVM vm{R"((a{3,5})a+)"}; + kak_assert(vm.exec("aaaaaa", true, true)); + kak_assert(StringView{vm.m_captures[2], vm.m_captures[3]} == "aaaaa"); + } + + { + TestVM vm{R"((a{3,5}?)a+)"}; + kak_assert(vm.exec("aaaaaa", true, true)); + kak_assert(StringView{vm.m_captures[2], vm.m_captures[3]} == "aaa"); + } + + { + TestVM vm{R"((a{3,5}?)a)"}; + kak_assert(vm.exec("aaaa")); + } + { TestVM vm{R"(\d{3})"}; kak_assert(vm.exec("123"));