Commit 5069443f authored by Dominik Charousset's avatar Dominik Charousset

Fix escaping of \r and other special characters

parent b51414da
...@@ -26,17 +26,33 @@ void print_escaped(Buffer& buf, string_view str) { ...@@ -26,17 +26,33 @@ void print_escaped(Buffer& buf, string_view str) {
default: default:
buf.push_back(c); buf.push_back(c);
break; break;
case '\\':
buf.push_back('\\');
buf.push_back('\\');
break;
case '\b':
buf.push_back('\\');
buf.push_back('b');
break;
case '\f':
buf.push_back('\\');
buf.push_back('f');
break;
case '\n': case '\n':
buf.push_back('\\'); buf.push_back('\\');
buf.push_back('n'); buf.push_back('n');
break; break;
case '\r':
buf.push_back('\\');
buf.push_back('r');
break;
case '\t': case '\t':
buf.push_back('\\'); buf.push_back('\\');
buf.push_back('t'); buf.push_back('t');
break; break;
case '\\': case '\v':
buf.push_back('\\');
buf.push_back('\\'); buf.push_back('\\');
buf.push_back('v');
break; break;
case '"': case '"':
buf.push_back('\\'); buf.push_back('\\');
......
...@@ -9,30 +9,6 @@ ...@@ -9,30 +9,6 @@
#include <algorithm> #include <algorithm>
#include <ctime> #include <ctime>
namespace {
void escape(std::string& result, char c) {
switch (c) {
default:
result += c;
break;
case '\n':
result += R"(\n)";
break;
case '\t':
result += R"(\t)";
break;
case '\\':
result += R"(\\)";
break;
case '"':
result += R"(\")";
break;
}
}
} // namespace
namespace caf::detail { namespace caf::detail {
bool stringification_inspector::begin_object(type_id_t, string_view name) { bool stringification_inspector::begin_object(type_id_t, string_view name) {
...@@ -181,8 +157,7 @@ bool stringification_inspector::value(string_view str) { ...@@ -181,8 +157,7 @@ bool stringification_inspector::value(string_view str) {
if (always_quote_strings if (always_quote_strings
|| std::any_of(str.begin(), str.end(), needs_escaping)) { || std::any_of(str.begin(), str.end(), needs_escaping)) {
result_ += '"'; result_ += '"';
for (char c : str) detail::print_escaped(result_, str);
escape(result_, c);
result_ += '"'; result_ += '"';
} else { } else {
result_.insert(result_.end(), str.begin(), str.end()); result_.insert(result_.end(), str.begin(), str.end());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment