Fix escaped whitespace handling in command manager

This commit is contained in:
Maxime Coste 2012-08-29 21:50:48 +02:00
parent bbce6b22a3
commit 2825bc3d7b
3 changed files with 15 additions and 4 deletions

View File

@ -153,16 +153,19 @@ TokenList parse(const String& line,
} }
} }
else else
while (pos != length and not is_horizontal_blank(line[pos]) and while (pos != length and
(not is_command_separator(line[pos]) or ((not is_command_separator(line[pos]) and
(pos != 0 and line[pos-1] == '\\'))) not is_horizontal_blank(line[pos]))
or (pos != 0 and line[pos-1] == '\\')))
++pos; ++pos;
if (token_start != pos) if (token_start != pos)
{ {
if (opt_token_pos_info) if (opt_token_pos_info)
opt_token_pos_info->push_back({token_start, pos}); 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])) if (is_command_separator(line[pos]))

View File

@ -48,4 +48,11 @@ std::vector<String> split(const String& str, Character separator)
return res; 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));
}
} }

View File

@ -47,6 +47,7 @@ public:
const char* c_str() const { return m_content.c_str(); } 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 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 class iterator
{ {