Regex: fix support for - at end of a character class

This commit is contained in:
Maxime Coste 2017-09-26 23:37:21 +09:00
parent e41d228af8
commit c282b699d7

View File

@ -270,10 +270,18 @@ private:
{ {
if (++m_pos == m_regex.end()) if (++m_pos == m_regex.end())
break; break;
if (*m_pos != ']')
{
range.max = *m_pos++; range.max = *m_pos++;
if (range.min > range.max) if (range.min > range.max)
parse_error("invalid range specified"); parse_error("invalid range specified");
} }
else
{
ranges.push_back(range);
range = { '-', '-' };
}
}
ranges.push_back(range); ranges.push_back(range);
} }
if (at_end()) if (at_end())
@ -934,8 +942,8 @@ auto test_regex = UnitTest{[]{
} }
{ {
TestVM vm{R"([àb-dX-Z]{3,5})"}; TestVM vm{R"([àb-dX-Z-]{3,5})"};
kak_assert(vm.exec("Y")); kak_assert(vm.exec("-Y"));
kak_assert(not vm.exec("àeY")); kak_assert(not vm.exec("àeY"));
kak_assert(vm.exec("dcbàX")); kak_assert(vm.exec("dcbàX"));
kak_assert(not vm.exec("efg")); kak_assert(not vm.exec("efg"));