#include "HTMLFormatter.h"
#include "common/escape.h"
+#include "common/StackStringStream.h"
#include "include/buffer.h"
#include <fmt/format.h>
std::string
fixed_u_to_string(uint64_t num, int scale)
{
- std::ostringstream t;
+ CachedStackStringStream css;
- t.fill('0');
- t.width(scale + 1);
- t << num;
- int len = t.str().size();
- return t.str().substr(0,len - scale) + "." + t.str().substr(len - scale);
+ css->fill('0');
+ css->width(scale + 1);
+ *css << num;
+ auto len = css->strv().size();
+
+ CachedStackStringStream css2;
+ *css2 << css->strv().substr(0, len - scale)
+ << "."
+ << css->strv().substr(len - scale);
+ return css2->str();
}
std::string
fixed_to_string(int64_t num, int scale)
{
- std::ostringstream t;
- bool neg = num < 0;
- if (neg) num = -num;
+ CachedStackStringStream css;
+
+ bool neg = num < 0;
+ if (neg) num = -num;
+
+ css->fill('0');
+ css->width(scale + 1);
+ *css << num;
+ auto len = css->strv().size();
- t.fill('0');
- t.width(scale + 1);
- t << num;
- int len = t.str().size();
- return (neg ? "-" : "") + t.str().substr(0,len - scale) + "." + t.str().substr(len - scale);
+ CachedStackStringStream css2;
+ *css2 << (neg ? "-" : "")
+ << css->strv().substr(0, len - scale)
+ << "."
+ << css->strv().substr(len - scale);
+ return css2->str();
}
/*
void Formatter::flush(bufferlist &bl)
{
- std::stringstream os;
- flush(os);
- bl.append(os.str());
+ CachedStackStringStream css;
+ flush(*css);
+ bl.append(css->strv());
}
void Formatter::dump_format(std::string_view name, const char *fmt, ...)
template <class T>
void JSONFormatter::add_value(std::string_view name, T val)
{
- std::stringstream ss;
- ss.precision(std::numeric_limits<T>::max_digits10);
- ss << val;
- add_value(name, ss.str(), false);
+ CachedStackStringStream css;
+ css->precision(std::numeric_limits<T>::max_digits10);
+ *css << val;
+ add_value(name, css->strv(), false);
}
void JSONFormatter::add_value(std::string_view name, std::string_view val, bool quoted)
void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str)
{
- std::stringstream attrs_ss;
+ CachedStackStringStream css;
for (std::list<std::pair<std::string, std::string> >::const_iterator iter = attrs->attrs.begin();
iter != attrs->attrs.end(); ++iter) {
std::pair<std::string, std::string> p = *iter;
- attrs_ss << " " << p.first << "=" << "\"" << p.second << "\"";
+ *css << " " << p.first << "=" << "\"" << p.second << "\"";
}
- attrs_str = attrs_ss.str();
+ attrs_str = css->strv();
}
void XMLFormatter::open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs)
void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str)
{
- std::stringstream attrs_ss;
+ CachedStackStringStream css;
for (std::list<std::pair<std::string, std::string> >::const_iterator iter = attrs->attrs.begin();
iter != attrs->attrs.end(); ++iter) {
std::pair<std::string, std::string> p = *iter;
- attrs_ss << " " << p.first << "=" << "\"" << p.second << "\"";
+ *css << " " << p.first << "=" << "\"" << p.second << "\"";
}
- attrs_str = attrs_ss.str();
+ attrs_str = css->strv();
}
void TableFormatter::finish_pending_string()