diff options
author | Sage Weil <sage@inktank.com> | 2013-07-26 21:41:27 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-07-26 21:47:33 -0700 |
commit | a8c1a2a28be426f030a50822d8b335d8a3bbb3a0 (patch) | |
tree | 7cb01cb6fb92308519eb080b08ea39f153a78010 | |
parent | 0041e9f8ffeb4354740f2ab34b674f9acac86273 (diff) | |
download | ceph-a8c1a2a28be426f030a50822d8b335d8a3bbb3a0.tar.gz |
common/Formatter: add dump_format_unquoted()
Sometimes a savvy caller wants to format the output but doesn't want it
quoted.
Signed-off-by: Sage Weil <sage@inktank.com>
-rw-r--r-- | src/common/Formatter.cc | 27 | ||||
-rw-r--r-- | src/common/Formatter.h | 3 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 7362684c070..c08ea5b9a20 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -254,6 +254,18 @@ void JSONFormatter::dump_format(const char *name, const char *fmt, ...) print_quoted_string(buf); } +void JSONFormatter::dump_format_unquoted(const char *name, const char *fmt, ...) +{ + char buf[LARGE_SIZE]; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, LARGE_SIZE, fmt, ap); + va_end(ap); + + print_name(name); + m_ss << buf; +} + int JSONFormatter::get_len() const { return m_ss.str().size(); @@ -404,6 +416,21 @@ void XMLFormatter::dump_format(const char *name, const char *fmt, ...) m_ss << "\n"; } +void XMLFormatter::dump_format_unquoted(const char *name, const char *fmt, ...) +{ + char buf[LARGE_SIZE]; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, LARGE_SIZE, fmt, ap); + va_end(ap); + + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << buf << "</" << e << ">"; + if (m_pretty) + m_ss << "\n"; +} + int XMLFormatter::get_len() const { return m_ss.str().size(); diff --git a/src/common/Formatter.h b/src/common/Formatter.h index c62a8303ce1..da730103f41 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -45,6 +45,7 @@ class Formatter { virtual void dump_string(const char *name, std::string s) = 0; virtual std::ostream& dump_stream(const char *name) = 0; virtual void dump_format(const char *name, const char *fmt, ...) = 0; + virtual void dump_format_unquoted(const char *name, const char *fmt, ...) = 0; virtual int get_len() const = 0; virtual void write_raw_data(const char *data) = 0; @@ -79,6 +80,7 @@ class JSONFormatter : public Formatter { void dump_string(const char *name, std::string s); std::ostream& dump_stream(const char *name); void dump_format(const char *name, const char *fmt, ...); + void dump_format_unquoted(const char *name, const char *fmt, ...); int get_len() const; void write_raw_data(const char *data); @@ -119,6 +121,7 @@ class XMLFormatter : public Formatter { void dump_string(const char *name, std::string s); std::ostream& dump_stream(const char *name); void dump_format(const char *name, const char *fmt, ...); + void dump_format_unquoted(const char *name, const char *fmt, ...); int get_len() const; void write_raw_data(const char *data); |