assert(!m_sections.empty());
finish_pending_string();
- print_spaces(false);
- m_ss << "</" << m_sections.back() << ">";
+ std::string section = m_sections.back();
m_sections.pop_back();
+ print_spaces();
+ m_ss << "</" << section << ">";
+ if (m_pretty)
+ m_ss << "\n";
}
void XMLFormatter::dump_unsigned(const char *name, uint64_t u)
{
std::string e(name);
- print_spaces(true);
+ print_spaces();
m_ss << "<" << e << ">" << u << "</" << e << ">";
if (m_pretty)
m_ss << "\n";
void XMLFormatter::dump_int(const char *name, int64_t u)
{
std::string e(name);
- print_spaces(true);
+ print_spaces();
m_ss << "<" << e << ">" << u << "</" << e << ">";
if (m_pretty)
m_ss << "\n";
void XMLFormatter::dump_float(const char *name, double d)
{
std::string e(name);
- print_spaces(true);
+ print_spaces();
m_ss << "<" << e << ">" << d << "</" << e << ">";
if (m_pretty)
m_ss << "\n";
void XMLFormatter::dump_string(const char *name, std::string s)
{
std::string e(name);
- print_spaces(true);
+ print_spaces();
m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << "</" << e << ">";
if (m_pretty)
m_ss << "\n";
std::ostream& XMLFormatter::dump_stream(const char *name)
{
assert(m_pending_string_name.empty());
+ print_spaces();
m_pending_string_name = name;
m_ss << "<" << m_pending_string_name << ">";
return m_pending_string;
va_end(ap);
std::string e(name);
- print_spaces(true);
+ print_spaces();
m_ss << "<" << e << ">" << escape_xml_str(buf) << "</" << e << ">";
if (m_pretty)
m_ss << "\n";
void XMLFormatter::open_section_in_ns(const char *name, const char *ns)
{
- print_spaces(false);
+ print_spaces();
if (ns) {
m_ss << "<" << name << " xmlns=\"" << ns << "\">";
}
else {
m_ss << "<" << name << ">";
}
+ if (m_pretty)
+ m_ss << "\n";
m_sections.push_back(name);
}
}
}
-void XMLFormatter::print_spaces(bool extra_space)
+void XMLFormatter::print_spaces()
{
finish_pending_string();
if (m_pretty) {
- std::vector<char> spaces(m_sections.size(), ' ');
- if (extra_space)
- spaces.push_back(' ');
- spaces.push_back('\0');
- m_ss << &spaces[0];
+ std::string spaces(m_sections.size(), ' ');
+ m_ss << spaces;
}
}
private:
void open_section_in_ns(const char *name, const char *ns);
void finish_pending_string();
- void print_spaces(bool extra_space);
+ void print_spaces();
static std::string escape_xml_str(const char *str);
std::stringstream m_ss, m_pending_string;