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