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) {
default:
buf.push_back(c);
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':
buf.push_back('\\');
buf.push_back('n');
break;
case '\r':
buf.push_back('\\');
buf.push_back('r');
break;
case '\t':
buf.push_back('\\');
buf.push_back('t');
break;
case '\\':
buf.push_back('\\');
case '\v':
buf.push_back('\\');
buf.push_back('v');
break;
case '"':
buf.push_back('\\');
......
......@@ -9,30 +9,6 @@
#include <algorithm>
#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 {
bool stringification_inspector::begin_object(type_id_t, string_view name) {
......@@ -181,8 +157,7 @@ bool stringification_inspector::value(string_view str) {
if (always_quote_strings
|| std::any_of(str.begin(), str.end(), needs_escaping)) {
result_ += '"';
for (char c : str)
escape(result_, c);
detail::print_escaped(result_, str);
result_ += '"';
} else {
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