diff options
Diffstat (limited to 'src/utils.h')
-rw-r--r-- | src/utils.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h index 48435844..6bd67146 100644 --- a/src/utils.h +++ b/src/utils.h @@ -646,6 +646,40 @@ inline string to_hex(uint_least32_t * message_digest, const int len = 1) return buf.str(); } +class push_xml +{ + std::ostream& out; + string tag; +public: + push_xml(std::ostream& _out, const string& _tag) : out(_out), tag(_tag) { + out << '<' << tag << '>'; + } + ~push_xml() { + out << "</" << tag << '>'; + } + + string guard(const string& str) { + std::ostringstream buf; + foreach (const char& ch, str) { + switch (ch) { + case '<': + buf << "<"; + break; + case '>': + buf << ">"; + break; + case '&': + buf << "&"; + break; + default: + buf << ch; + break; + } + } + return buf.str(); + } +}; + extern const string version; } // namespace ledger |