Replace operator<< with write function
This commit is contained in:
+13
-6
@@ -193,9 +193,12 @@ void format_error_code(writer &out, int error_code,
|
||||
++error_code_size;
|
||||
}
|
||||
error_code_size += internal::count_digits(abs_value);
|
||||
if (message.size() <= internal::INLINE_BUFFER_SIZE - error_code_size)
|
||||
out << message << SEP;
|
||||
out << ERROR_STR << error_code;
|
||||
if (message.size() <= internal::INLINE_BUFFER_SIZE - error_code_size) {
|
||||
out.write(message);
|
||||
out.write(SEP);
|
||||
}
|
||||
out.write(ERROR_STR);
|
||||
out.write(error_code);
|
||||
assert(out.size() <= internal::INLINE_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
@@ -367,7 +370,9 @@ FMT_FUNC void internal::format_windows_error(
|
||||
if (result != 0) {
|
||||
UTF16ToUTF8 utf8_message;
|
||||
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
|
||||
out << message << ": " << utf8_message;
|
||||
out.write(message);
|
||||
out.write(": ");
|
||||
out.write(utf8_message);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -391,7 +396,9 @@ FMT_FUNC void format_system_error(
|
||||
char *system_message = &buffer[0];
|
||||
int result = safe_strerror(error_code, system_message, buffer.size());
|
||||
if (result == 0) {
|
||||
out << message << ": " << system_message;
|
||||
out.write(message);
|
||||
out.write(": ");
|
||||
out.write(system_message);
|
||||
return;
|
||||
}
|
||||
if (result != ERANGE)
|
||||
@@ -423,7 +430,7 @@ FMT_FUNC void report_windows_error(
|
||||
|
||||
FMT_FUNC void vprint(std::FILE *f, CStringRef format_str, format_args args) {
|
||||
MemoryWriter w;
|
||||
w.vwrite(format_str, args);
|
||||
w.vformat(format_str, args);
|
||||
std::fwrite(w.data(), 1, w.size(), f);
|
||||
}
|
||||
|
||||
|
||||
+28
-39
@@ -1535,7 +1535,7 @@ class format_arg_store {
|
||||
static const uint64_t TYPES = internal::make_type<Args..., void>();
|
||||
|
||||
format_arg_store(const Args &... args)
|
||||
: data_(Array{internal::make_arg<IS_PACKED, Context>(args)...}) {}
|
||||
: data_(Array{{internal::make_arg<IS_PACKED, Context>(args)...}}) {}
|
||||
|
||||
const value_type *data() const { return data_.data(); }
|
||||
};
|
||||
@@ -2043,7 +2043,7 @@ class ArgFormatterBase {
|
||||
template <typename Char>
|
||||
inline void write(basic_writer<Char> &w, const Char *start, const Char *end) {
|
||||
if (start != end)
|
||||
w << BasicStringRef<Char>(start, internal::to_unsigned(end - start));
|
||||
w.write(BasicStringRef<Char>(start, internal::to_unsigned(end - start)));
|
||||
}
|
||||
|
||||
template <typename Char, typename Context>
|
||||
@@ -2392,8 +2392,8 @@ class basic_writer {
|
||||
return std::basic_string<Char>(&buffer_[0], buffer_.size());
|
||||
}
|
||||
|
||||
void vwrite(BasicCStringRef<Char> format,
|
||||
basic_format_args<basic_format_context<Char>> args);
|
||||
void vformat(BasicCStringRef<Char> format,
|
||||
basic_format_args<basic_format_context<Char>> args);
|
||||
/**
|
||||
\rst
|
||||
Writes formatted data.
|
||||
@@ -2403,8 +2403,8 @@ class basic_writer {
|
||||
**Example**::
|
||||
|
||||
MemoryWriter out;
|
||||
out.write("Current point:\n");
|
||||
out.write("({:+f}, {:+f})", -3.14, 3.14);
|
||||
out.format("Current point:\n");
|
||||
out.format("({:+f}, {:+f})", -3.14, 3.14);
|
||||
|
||||
This will write the following output to the ``out`` object:
|
||||
|
||||
@@ -2420,27 +2420,24 @@ class basic_writer {
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
void write(BasicCStringRef<Char> format, const Args & ... args) {
|
||||
vwrite(format, make_xformat_args<basic_format_context<Char>>(args...));
|
||||
void format(BasicCStringRef<Char> format, const Args & ... args) {
|
||||
vformat(format, make_xformat_args<basic_format_context<Char>>(args...));
|
||||
}
|
||||
|
||||
basic_writer &operator<<(int value) {
|
||||
void write(int value) {
|
||||
write_decimal(value);
|
||||
return *this;
|
||||
}
|
||||
basic_writer &operator<<(unsigned value) {
|
||||
return *this << IntFormatSpec<unsigned>(value);
|
||||
void write(unsigned value) {
|
||||
*this << IntFormatSpec<unsigned>(value);
|
||||
}
|
||||
basic_writer &operator<<(long value) {
|
||||
void write(long value) {
|
||||
write_decimal(value);
|
||||
return *this;
|
||||
}
|
||||
basic_writer &operator<<(unsigned long value) {
|
||||
return *this << IntFormatSpec<unsigned long>(value);
|
||||
void write(unsigned long value) {
|
||||
*this << IntFormatSpec<unsigned long>(value);
|
||||
}
|
||||
basic_writer &operator<<(LongLong value) {
|
||||
void write(LongLong value) {
|
||||
write_decimal(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2448,13 +2445,12 @@ class basic_writer {
|
||||
Formats *value* and writes it to the stream.
|
||||
\endrst
|
||||
*/
|
||||
basic_writer &operator<<(ULongLong value) {
|
||||
return *this << IntFormatSpec<ULongLong>(value);
|
||||
void write(ULongLong value) {
|
||||
*this << IntFormatSpec<ULongLong>(value);
|
||||
}
|
||||
|
||||
basic_writer &operator<<(double value) {
|
||||
void write(double value) {
|
||||
write_double(value, FormatSpec());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2463,23 +2459,19 @@ class basic_writer {
|
||||
(``'g'``) and writes it to the stream.
|
||||
\endrst
|
||||
*/
|
||||
basic_writer &operator<<(long double value) {
|
||||
void write(long double value) {
|
||||
write_double(value, FormatSpec());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
Writes a character to the stream.
|
||||
*/
|
||||
basic_writer &operator<<(char value) {
|
||||
void write(char value) {
|
||||
buffer_.push_back(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_writer &operator<<(
|
||||
typename internal::WCharHelper<wchar_t, Char>::Supported value) {
|
||||
void write(typename internal::WCharHelper<wchar_t, Char>::Supported value) {
|
||||
buffer_.push_back(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2487,17 +2479,14 @@ class basic_writer {
|
||||
Writes *value* to the stream.
|
||||
\endrst
|
||||
*/
|
||||
basic_writer &operator<<(fmt::BasicStringRef<Char> value) {
|
||||
void write(fmt::BasicStringRef<Char> value) {
|
||||
const Char *str = value.data();
|
||||
buffer_.append(str, str + value.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_writer &operator<<(
|
||||
typename internal::WCharHelper<StringRef, Char>::Supported value) {
|
||||
void write(typename internal::WCharHelper<StringRef, Char>::Supported value) {
|
||||
const char *str = value.data();
|
||||
buffer_.append(str, str + value.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, typename Spec, typename FillChar>
|
||||
@@ -3076,7 +3065,7 @@ inline void print_colored(Color c, CStringRef format_str,
|
||||
|
||||
inline std::string vformat(CStringRef format_str, format_args args) {
|
||||
MemoryWriter w;
|
||||
w.vwrite(format_str, args);
|
||||
w.vformat(format_str, args);
|
||||
return w.str();
|
||||
}
|
||||
|
||||
@@ -3096,7 +3085,7 @@ inline std::string format(CStringRef format_str, const Args & ... args) {
|
||||
|
||||
inline std::wstring vformat(WCStringRef format_str, wformat_args args) {
|
||||
WMemoryWriter w;
|
||||
w.vwrite(format_str, args);
|
||||
w.vformat(format_str, args);
|
||||
return w.str();
|
||||
}
|
||||
|
||||
@@ -3574,7 +3563,7 @@ void do_format_arg(basic_writer<Char> &writer, basic_format_arg<Context> arg,
|
||||
|
||||
/** Formats arguments and writes the output to the writer. */
|
||||
template <typename ArgFormatter, typename Char, typename Context>
|
||||
void vformat(basic_writer<Char> &writer, BasicCStringRef<Char> format_str,
|
||||
void vwrite(basic_writer<Char> &writer, BasicCStringRef<Char> format_str,
|
||||
basic_format_args<Context> args) {
|
||||
basic_format_context<Char> ctx(format_str.c_str(), args);
|
||||
const Char *&s = ctx.ptr();
|
||||
@@ -3599,10 +3588,10 @@ void vformat(basic_writer<Char> &writer, BasicCStringRef<Char> format_str,
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
inline void basic_writer<Char>::vwrite(
|
||||
inline void basic_writer<Char>::vformat(
|
||||
BasicCStringRef<Char> format,
|
||||
basic_format_args<basic_format_context<Char>> args) {
|
||||
vformat<ArgFormatter<Char>>(*this, format, args);
|
||||
vwrite<ArgFormatter<Char>>(*this, format, args);
|
||||
}
|
||||
} // namespace fmt
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ FMT_FUNC void write(std::ostream &os, writer &w) {
|
||||
FMT_FUNC void vprint(std::ostream &os, CStringRef format_str,
|
||||
format_args args) {
|
||||
MemoryWriter w;
|
||||
w.vwrite(format_str, args);
|
||||
w.vformat(format_str, args);
|
||||
internal::write(os, w);
|
||||
}
|
||||
} // namespace fmt
|
||||
|
||||
+1
-1
@@ -505,7 +505,7 @@ template <typename Char, typename T>
|
||||
void format_value(basic_writer<Char> &w, const T &value,
|
||||
printf_context<Char>& ctx) {
|
||||
internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
|
||||
w << internal::format_value(buffer, value);
|
||||
w.write(internal::format_value(buffer, value));
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ typedef BasicStringWriter<wchar_t> WStringWriter;
|
||||
template <typename T>
|
||||
std::string to_string(const T &value) {
|
||||
fmt::MemoryWriter w;
|
||||
w << value;
|
||||
w.write(value);
|
||||
return w.str();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user