#include "common/escape.h"
#include "include/buffer.h"
+#include <algorithm>
#include <iostream>
#include <sstream>
#include <stdarg.h>
#include <boost/format.hpp>
+static char tolower_underscore(const char b) {
+ return ' ' == b ? '_' : std::tolower(b);
+}
// -----------------------
namespace ceph {
const char *XMLFormatter::XML_1_DTD =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
-XMLFormatter::XMLFormatter(bool pretty)
-: m_pretty(pretty)
+XMLFormatter::XMLFormatter(bool pretty, bool lowercased_underscored)
+: m_pretty(pretty),
+ m_lowercased_underscored(lowercased_underscored)
{
reset();
}
finish_pending_string();
std::string section = m_sections.back();
+ if (m_lowercased_underscored) {
+ std::transform(section.begin(), section.end(), section.begin(),
+ tolower_underscore);
+ }
m_sections.pop_back();
print_spaces();
m_ss << "</" << section << ">";
void XMLFormatter::dump_unsigned(const char *name, uint64_t u)
{
std::string e(name);
+ if (m_lowercased_underscored) {
+ std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+ }
print_spaces();
m_ss << "<" << e << ">" << u << "</" << e << ">";
if (m_pretty)
void XMLFormatter::dump_int(const char *name, int64_t u)
{
std::string e(name);
+ if (m_lowercased_underscored) {
+ std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+ }
print_spaces();
m_ss << "<" << e << ">" << u << "</" << e << ">";
if (m_pretty)
void XMLFormatter::dump_float(const char *name, double d)
{
std::string e(name);
+ if (m_lowercased_underscored) {
+ std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+ }
print_spaces();
m_ss << "<" << e << ">" << d << "</" << e << ">";
if (m_pretty)
void XMLFormatter::dump_string(const char *name, const std::string& s)
{
std::string e(name);
+ if (m_lowercased_underscored) {
+ std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+ }
print_spaces();
m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << "</" << e << ">";
if (m_pretty)
void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs)
{
std::string e(name);
+ if (m_lowercased_underscored) {
+ std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+ }
std::string attrs_str;
get_attrs_str(&attrs, attrs_str);
print_spaces();
vsnprintf(buf, LARGE_SIZE, fmt, ap);
std::string e(name);
+ if (m_lowercased_underscored) {
+ std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+ }
print_spaces();
if (ns) {
m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << "</" << e << ">";
get_attrs_str(attrs, attrs_str);
}
+ std::string e(name);
+ if (m_lowercased_underscored) {
+ std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+ }
+
if (ns) {
- m_ss << "<" << name << attrs_str << " xmlns=\"" << ns << "\">";
+ m_ss << "<" << e << attrs_str << " xmlns=\"" << ns << "\">";
} else {
- m_ss << "<" << name << attrs_str << ">";
+ m_ss << "<" << e << attrs_str << ">";
}
if (m_pretty)
m_ss << "\n";