Commit 7dbbea4c authored by kylixrd's avatar kylixrd Committed by Commit bot

"Escape" certain characters

Added EscapeString() to convert certain characters into XML escape (&xxx;) sequences

BUG=708705

Review-Url: https://codereview.chromium.org/2803613003
Cr-Commit-Position: refs/heads/master@{#462966}
parent 51cdcbaa
...@@ -37,9 +37,41 @@ ...@@ -37,9 +37,41 @@
namespace { namespace {
std::string EscapeString(const std::string& value) {
std::string result;
for (char c : value) {
switch (c) {
case '\n':
result += "
";
break;
case '\r':
result += "
";
break;
case '\t':
result += "	";
break;
case '"':
result += """;
break;
case '<':
result += "&lt;";
break;
case '>':
result += "&gt;";
break;
case '&':
result += "&amp;";
break;
default:
result += c;
}
}
return result;
}
struct SemicolonSeparatedWriter { struct SemicolonSeparatedWriter {
void operator()(const std::string& value, std::ostream& out) const { void operator()(const std::string& value, std::ostream& out) const {
out << value + ';'; out << EscapeString(value) + ';';
} }
}; };
......
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