diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-09 13:25:45 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-09 13:25:45 -0500 |
commit | 865c0ff828f88ed1d00eea73a3fc55b3e57d21b3 (patch) | |
tree | 5acdfae32811b25fb46271bf349a216bea41fddb /src/utils.h | |
parent | 55c7792c9329f97dd19fc5aeca466cb2de4fbf9c (diff) | |
parent | 9b396b41220646cf73fcd2a8afebcee06dde2a29 (diff) | |
download | fork-ledger-865c0ff828f88ed1d00eea73a3fc55b3e57d21b3.tar.gz fork-ledger-865c0ff828f88ed1d00eea73a3fc55b3e57d21b3.tar.bz2 fork-ledger-865c0ff828f88ed1d00eea73a3fc55b3e57d21b3.zip |
Merge branch 'next'
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 |