diff --git a/src/command_manager.cc b/src/command_manager.cc index 947031c4..a636d852 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -153,16 +153,19 @@ TokenList parse(const String& line, } } else - while (pos != length and not is_horizontal_blank(line[pos]) and - (not is_command_separator(line[pos]) or - (pos != 0 and line[pos-1] == '\\'))) + while (pos != length and + ((not is_command_separator(line[pos]) and + not is_horizontal_blank(line[pos])) + or (pos != 0 and line[pos-1] == '\\'))) ++pos; if (token_start != pos) { if (opt_token_pos_info) opt_token_pos_info->push_back({token_start, pos}); - result.push_back({type, line.substr(token_start, pos - token_start)}); + String token = line.substr(token_start, pos - token_start); + token = token.replace(R"(\\([ \t;\n]))", "\\1"); + result.push_back({type, token}); } if (is_command_separator(line[pos])) diff --git a/src/string.cc b/src/string.cc index 9e2d1507..042bba77 100644 --- a/src/string.cc +++ b/src/string.cc @@ -48,4 +48,11 @@ std::vector split(const String& str, Character separator) return res; } +String String::replace(const String& expression, + const String& replacement) const +{ + boost::regex re(expression.m_content); + return String(boost::regex_replace(m_content, re, replacement.m_content)); +} + } diff --git a/src/string.hh b/src/string.hh index a781b358..8676c5da 100644 --- a/src/string.hh +++ b/src/string.hh @@ -47,6 +47,7 @@ public: const char* c_str() const { return m_content.c_str(); } String substr(CharCount pos, CharCount length = -1) const { return String(m_content.substr((int)pos, (int)length)); } + String replace(const String& expression, const String& replacement) const; class iterator {