diff options
Diffstat (limited to 'src/utils.h')
-rw-r--r-- | src/utils.h | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/utils.h b/src/utils.h index a8784a66..bfdee0b2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -165,8 +165,6 @@ void report_memory(std::ostream& out, bool report_all = false); #if defined(STRING_VERIFY_ON) /** - * @brief Brief - * * This string type is a wrapper around std::string that allows us to * trace constructor and destructor calls. */ @@ -648,6 +646,51 @@ inline string to_hex(uint_least32_t * message_digest, const int len = 1) return buf.str(); } +class push_xml +{ + std::ostream& out; + string tag; + bool leave_open; + +public: + push_xml(std::ostream& _out, const string& _tag, bool has_attrs = false, + bool _leave_open = false) + : out(_out), tag(_tag), leave_open(_leave_open) { + out << '<' << tag; + if (! has_attrs) + out << '>'; + } + ~push_xml() { + if (! leave_open) + out << "</" << tag << '>'; + } + + void close_attrs() { + out << '>'; + } + + static 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 |