summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Aker <brian@tangent.org>2014-02-01 15:29:29 +0100
committerBrian Aker <brian@tangent.org>2014-02-01 15:29:29 +0100
commit8a04c53710520be5a4d37b6acb682045a6c41faf (patch)
treeaab5bca3401820803829e83a4c6f6a0d71c4cb2b
parent7be9389170df33175d87c12f3b6cf48fdf7d0934 (diff)
downloadlibmemcached-8a04c53710520be5a4d37b6acb682045a6c41faf.tar.gz
Just write it myself (so much for coppying).
-rw-r--r--libtest/formatter.cc48
1 files changed, 25 insertions, 23 deletions
diff --git a/libtest/formatter.cc b/libtest/formatter.cc
index a45d9c4f..7cb3ea0a 100644
--- a/libtest/formatter.cc
+++ b/libtest/formatter.cc
@@ -52,39 +52,41 @@ std::string& escape4XML(std::string const& arg, std::string& escaped_string)
for (std::string::const_iterator x= arg.begin(), end= arg.end(); x != end; ++x)
{
unsigned char c= *x;
- if (' ' <= c and c <= '~' and c != '\\' and c != '"' and c != '>' and c != '<')
+ if (c == '&')
{
- escaped_string+= c;
+ escaped_string+= "&amp;";
}
else if (c == '>')
{
- escaped_string+= '&';
- escaped_string+= 'g';
- escaped_string+= 't';
- escaped_string+= ';';
+ escaped_string+= "&gt;";
}
else if (c == '<')
{
- escaped_string+= '&';
- escaped_string+= 'l';
- escaped_string+= 't';
- escaped_string+= ';';
+ escaped_string+= "&lt;";
+ }
+ else if (c == '\'')
+ {
+ escaped_string+= "&apos;"; break;
+ }
+ else if (c == '"')
+ {
+ escaped_string+= "&quot;";
+ }
+ else if (c == ' ')
+ {
+ escaped_string+= ' ';
+ }
+ else if (isalnum(c))
+ {
+ escaped_string+= c;
}
else
{
- escaped_string+= '\\';
- switch (c) {
- case '"': escaped_string+= '"'; break;
- case '\\': escaped_string+= '\\'; break;
- case '\t': escaped_string+='t'; break;
- case '\r': escaped_string+='r'; break;
- case '\n': escaped_string+='n'; break;
- default:
- char const* const hexdig= "0123456789ABCDEF";
- escaped_string+= 'x';
- escaped_string+= hexdig[c >> 4];
- escaped_string+= hexdig[c & 0xF];
- }
+ char const* const hexdig= "0123456789ABCDEF";
+ escaped_string+= "&#x";
+ escaped_string+= hexdig[c >> 4];
+ escaped_string+= hexdig[c & 0xF];
+ escaped_string+= ';';
}
}
escaped_string+= '"';