diff options
Diffstat (limited to 'atf-report/atf-report.cpp')
| -rw-r--r-- | atf-report/atf-report.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/atf-report/atf-report.cpp b/atf-report/atf-report.cpp index fffe9dd41e91..359b58b2307a 100644 --- a/atf-report/atf-report.cpp +++ b/atf-report/atf-report.cpp @@ -31,6 +31,7 @@ extern "C" { #include <sys/time.h> } +#include <cctype> #include <cstdlib> #include <fstream> #include <iomanip> @@ -381,7 +382,6 @@ public: class xml_writer : public writer { ostream_ptr m_os; - size_t m_curtp, m_ntps; std::string m_tcname, m_tpname; static @@ -395,17 +395,24 @@ class xml_writer : public writer { std::string elemval(const std::string& str) { - std::string ostr; + std::ostringstream buf; for (std::string::const_iterator iter = str.begin(); iter != str.end(); iter++) { - switch (*iter) { - case '&': ostr += "&"; break; - case '<': ostr += "<"; break; - case '>': ostr += ">"; break; - default: ostr += *iter; + const int character = static_cast< unsigned char >(*iter); + if (character == '&') { + buf << "&"; + } else if (character == '<') { + buf << "<"; + } else if (character == '>') { + buf << ">"; + } else if (std::isalnum(character) || std::ispunct(character) || + std::isspace(character)) { + buf << static_cast< char >(character); + } else { + buf << "&#" << character << ";"; } } - return ostr; + return buf.str(); } void |
