From 536fa29ed5b53ea68a0f634a7fbef130ae544dd9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 18 Feb 2018 14:56:52 +1100 Subject: [PATCH] CommandManager: unescape % while parsing the string --- src/command_manager.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index cbc18954..899203b2 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -66,8 +66,9 @@ bool is_command_separator(Codepoint c) return c == ';' or c == '\n'; } -template -String get_until_delimiter(Reader& reader, Func is_delimiter) +template +String get_until_delimiter(Reader& reader, Func is_delimiter, + UnescapeFunc unescape = [](Codepoint) { return false; }) { auto beg = reader.pos; String str; @@ -76,7 +77,7 @@ String get_until_delimiter(Reader& reader, Func is_delimiter) while (reader) { const Codepoint c = *reader; - if (is_delimiter(c)) + if (is_delimiter(c) or (was_antislash and unescape(c))) { str += reader.substr_from(beg); if (was_antislash) @@ -98,7 +99,7 @@ String get_until_delimiter(Reader& reader, Func is_delimiter) [[gnu::always_inline]] inline String get_until_delimiter(Reader& reader, Codepoint c) { - return get_until_delimiter(reader, [c](Codepoint ch) { return c == ch; }); + return get_until_delimiter(reader, [c](Codepoint ch) { return c == ch; }, [](Codepoint) { return false; }); } StringView get_until_closing_delimiter(Reader& reader, Codepoint opening_delimiter, @@ -317,9 +318,9 @@ Optional CommandParser::read_token(bool throw_on_unterminated) { String str = get_until_delimiter(m_reader, [](Codepoint c) { return is_command_separator(c) or is_horizontal_blank(c); - }); + }, [](Codepoint c) { return c == '%'; }); return Token{Token::Type::Raw, start - line.begin(), - coord, unescape(str, "%", '\\')}; + coord, std::move(str)}; } return {}; }