diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-10-02 15:35:21 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-11-01 14:05:14 +0800 |
| commit | b4f923b7fc53a83d0f6243d5b524cc7d4fc58c8f (patch) | |
| tree | 3bf99b6bd3a81b67afa65fbec794f777883d48e9 /src | |
| parent | f02b2645dacc8788d624e94994584e9d4f31204e (diff) | |
Regex: min/max quantifiers can be non greedy as well
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex_impl.cc | 19 |
1 files changed, 18 insertions, 1 deletions
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}; } @@ -921,6 +921,23 @@ auto test_regex = UnitTest{[]{ } { + 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")); kak_assert(not vm.exec("1x3")); |
