summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-10-07 21:24:05 +0800
committerMaxime Coste <mawww@kakoune.org>2017-11-01 14:05:14 +0800
commit578640c8a482389beeaf6c3588663dfd5fa5461a (patch)
treed0f4cb9eb03cabe100c0711a5e49d7d66c1d1b1b
parentf3736a4b48b5fec1cba6d30191d9d7fbacb647ff (diff)
Regex: Fix handling of control escapes inside character classes
-rw-r--r--src/regex_impl.cc31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/regex_impl.cc b/src/regex_impl.cc
index dcc968f6..659a84ec 100644
--- a/src/regex_impl.cc
+++ b/src/regex_impl.cc
@@ -278,9 +278,6 @@ private:
}
// CharacterEscape
- struct { Codepoint name; Codepoint value; } control_escapes[] = {
- { 'f', '\f' }, { 'n', '\n' }, { 'r', '\r' }, { 't', '\t' }, { 'v', '\v' }
- };
for (auto& control : control_escapes)
{
if (control.name == cp)
@@ -337,10 +334,15 @@ private:
}
else // its just an escaped character
{
-
- if (++m_pos == m_regex.end())
- break;
- cp = *m_pos;
+ cp = *m_pos++;
+ for (auto& control : control_escapes)
+ {
+ if (control.name == cp)
+ {
+ cp = control.value;
+ break;
+ }
+ }
}
}
@@ -487,8 +489,10 @@ private:
StringView additional_chars;
bool neg;
};
-
static const CharacterClassEscape character_class_escapes[8];
+
+ struct ControlEscape { Codepoint name; Codepoint value; };
+ static const ControlEscape control_escapes[5];
};
// For some reason Gcc fails to link if this is constexpr
@@ -499,6 +503,11 @@ const RegexParser::CharacterClassEscape RegexParser::character_class_escapes[8]
{ 'h', nullptr, " \t", false },
};
+
+const RegexParser::ControlEscape RegexParser::control_escapes[5] = {
+ { 'f', '\f' }, { 'n', '\n' }, { 'r', '\r' }, { 't', '\t' }, { 'v', '\v' }
+};
+
struct RegexCompiler
{
RegexCompiler(const ParsedRegex& parsed_regex, MatchDirection direction)
@@ -1063,6 +1072,12 @@ auto test_regex = UnitTest{[]{
}
{
+ TestVM<> vm{R"([^:\n]+)"};
+ kak_assert(not vm.exec("\nbc"));
+ kak_assert(vm.exec("abc"));
+ }
+
+ {
TestVM<> vm{R"((?:foo)+)"};
kak_assert(vm.exec("foofoofoo"));
kak_assert(not vm.exec("barbarbar"));