Updated to latest cppformat lib
This commit is contained in:
parent
cadd181d8d
commit
77acf29c4d
@ -207,8 +207,8 @@ int safe_strerror(
|
||||
}
|
||||
|
||||
public:
|
||||
StrError(int error_code, char *&buffer, std::size_t buffer_size)
|
||||
: error_code_(error_code), buffer_(buffer), buffer_size_(buffer_size) {}
|
||||
StrError(int err_code, char *&buf, std::size_t buf_size)
|
||||
: error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
|
||||
|
||||
int run() {
|
||||
strerror_r(0, 0, ""); // Suppress a warning about unused strerror_r.
|
||||
@ -521,25 +521,25 @@ public:
|
||||
: BasicArgFormatter<PrintfArgFormatter<Char>, Char>(w, s) {}
|
||||
|
||||
void visit_char(int value) {
|
||||
const FormatSpec &spec = this->spec();
|
||||
BasicWriter<Char> &writer = this->writer();
|
||||
if (spec.type_ && spec.type_ != 'c')
|
||||
writer.write_int(value, spec);
|
||||
const FormatSpec &fmt_spec = this->spec();
|
||||
BasicWriter<Char> &w = this->writer();
|
||||
if (fmt_spec.type_ && fmt_spec.type_ != 'c')
|
||||
w.write_int(value, fmt_spec);
|
||||
typedef typename BasicWriter<Char>::CharPtr CharPtr;
|
||||
CharPtr out = CharPtr();
|
||||
if (spec.width_ > 1) {
|
||||
if (fmt_spec.width_ > 1) {
|
||||
Char fill = ' ';
|
||||
out = writer.grow_buffer(spec.width_);
|
||||
if (spec.align_ != ALIGN_LEFT) {
|
||||
std::fill_n(out, spec.width_ - 1, fill);
|
||||
out += spec.width_ - 1;
|
||||
out = w.grow_buffer(fmt_spec.width_);
|
||||
if (fmt_spec.align_ != ALIGN_LEFT) {
|
||||
std::fill_n(out, fmt_spec.width_ - 1, fill);
|
||||
out += fmt_spec.width_ - 1;
|
||||
}
|
||||
else {
|
||||
std::fill_n(out + 1, spec.width_ - 1, fill);
|
||||
std::fill_n(out + 1, fmt_spec.width_ - 1, fill);
|
||||
}
|
||||
}
|
||||
else {
|
||||
out = writer.grow_buffer(1);
|
||||
out = w.grow_buffer(1);
|
||||
}
|
||||
*out = static_cast<Char>(value);
|
||||
}
|
||||
@ -959,10 +959,8 @@ unsigned fmt::internal::PrintfFormatter<Char>::parse_header(
|
||||
|
||||
template <typename Char>
|
||||
void fmt::internal::PrintfFormatter<Char>::format(
|
||||
BasicWriter<Char> &writer, BasicCStringRef<Char> format_str,
|
||||
const ArgList &args) {
|
||||
BasicWriter<Char> &writer, BasicCStringRef<Char> format_str) {
|
||||
const Char *start = format_str.c_str();
|
||||
set_args(args);
|
||||
const Char *s = start;
|
||||
while (*s) {
|
||||
Char c = *s++;
|
||||
@ -1227,7 +1225,6 @@ const Char *fmt::BasicFormatter<Char>::format(
|
||||
|
||||
if (*s++ != '}')
|
||||
FMT_THROW(FormatError("missing '}' in format string"));
|
||||
start_ = s;
|
||||
|
||||
// Format argument.
|
||||
internal::ArgFormatter<Char>(*this, spec, s - 1).visit(arg);
|
||||
@ -1235,25 +1232,24 @@ const Char *fmt::BasicFormatter<Char>::format(
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
void fmt::BasicFormatter<Char>::format(
|
||||
BasicCStringRef<Char> format_str, const ArgList &args) {
|
||||
const Char *s = start_ = format_str.c_str();
|
||||
set_args(args);
|
||||
void fmt::BasicFormatter<Char>::format(BasicCStringRef<Char> format_str) {
|
||||
const Char *s = format_str.c_str();
|
||||
const Char *start = s;
|
||||
while (*s) {
|
||||
Char c = *s++;
|
||||
if (c != '{' && c != '}') continue;
|
||||
if (*s == c) {
|
||||
write(writer_, start_, s);
|
||||
start_ = ++s;
|
||||
write(writer_, start, s);
|
||||
start = ++s;
|
||||
continue;
|
||||
}
|
||||
if (c == '}')
|
||||
FMT_THROW(FormatError("unmatched '}' in format string"));
|
||||
write(writer_, start_, s - 1);
|
||||
write(writer_, start, s - 1);
|
||||
Arg arg = is_name_start(*s) ? parse_arg_name(s) : parse_arg_index(s);
|
||||
s = format(s, arg);
|
||||
start = s = format(s, arg);
|
||||
}
|
||||
write(writer_, start_, s);
|
||||
write(writer_, start, s);
|
||||
}
|
||||
|
||||
FMT_FUNC void fmt::report_system_error(
|
||||
@ -1310,11 +1306,10 @@ template void fmt::internal::FixedBuffer<char>::grow(std::size_t);
|
||||
template const char *fmt::BasicFormatter<char>::format(
|
||||
const char *&format_str, const fmt::internal::Arg &arg);
|
||||
|
||||
template void fmt::BasicFormatter<char>::format(
|
||||
CStringRef format, const ArgList &args);
|
||||
template void fmt::BasicFormatter<char>::format(CStringRef format);
|
||||
|
||||
template void fmt::internal::PrintfFormatter<char>::format(
|
||||
BasicWriter<char> &writer, CStringRef format, const ArgList &args);
|
||||
BasicWriter<char> &writer, CStringRef format);
|
||||
|
||||
template int fmt::internal::CharTraits<char>::format_float(
|
||||
char *buffer, std::size_t size, const char *format,
|
||||
@ -1332,11 +1327,10 @@ template const wchar_t *fmt::BasicFormatter<wchar_t>::format(
|
||||
const wchar_t *&format_str, const fmt::internal::Arg &arg);
|
||||
|
||||
template void fmt::BasicFormatter<wchar_t>::format(
|
||||
BasicCStringRef<wchar_t> format, const ArgList &args);
|
||||
BasicCStringRef<wchar_t> format);
|
||||
|
||||
template void fmt::internal::PrintfFormatter<wchar_t>::format(
|
||||
BasicWriter<wchar_t> &writer, WCStringRef format,
|
||||
const ArgList &args);
|
||||
BasicWriter<wchar_t> &writer, WCStringRef format);
|
||||
|
||||
template int fmt::internal::CharTraits<wchar_t>::format_float(
|
||||
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
||||
|
@ -27,7 +27,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef FMT_FORMAT_H_
|
||||
#define FMT_FORMAT_H_
|
||||
|
||||
#define FMT_HEADER_ONLY
|
||||
|
||||
#include <stdint.h>
|
||||
@ -763,24 +762,23 @@ inline unsigned count_digits(uint32_t n) {
|
||||
// Formats a decimal unsigned integer value writing into buffer.
|
||||
template <typename UInt, typename Char>
|
||||
inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
|
||||
--num_digits;
|
||||
buffer += num_digits;
|
||||
while (value >= 100) {
|
||||
// Integer division is slow so do it for a group of two digits instead
|
||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||
unsigned index = (value % 100) * 2;
|
||||
value /= 100;
|
||||
buffer[num_digits] = Data::DIGITS[index + 1];
|
||||
buffer[num_digits - 1] = Data::DIGITS[index];
|
||||
num_digits -= 2;
|
||||
*--buffer = Data::DIGITS[index + 1];
|
||||
*--buffer = Data::DIGITS[index];
|
||||
}
|
||||
if (value < 10) {
|
||||
*buffer = static_cast<char>('0' + value);
|
||||
*--buffer = static_cast<char>('0' + value);
|
||||
return;
|
||||
}
|
||||
unsigned index = static_cast<unsigned>(value * 2);
|
||||
buffer[1] = Data::DIGITS[index + 1];
|
||||
buffer[0] = Data::DIGITS[index];
|
||||
*--buffer = Data::DIGITS[index + 1];
|
||||
*--buffer = Data::DIGITS[index];
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
@ -924,11 +922,11 @@ private:
|
||||
|
||||
static const T &get();
|
||||
|
||||
static yes &check(fmt::ULongLong);
|
||||
static no &check(...);
|
||||
static yes &convert(fmt::ULongLong);
|
||||
static no &convert(...);
|
||||
|
||||
public:
|
||||
enum { value = (sizeof(check(get())) == sizeof(yes)) };
|
||||
enum { value = (sizeof(convert(get())) == sizeof(yes)) };
|
||||
};
|
||||
|
||||
#define FMT_CONVERTIBLE_TO_INT(Type) \
|
||||
@ -1127,8 +1125,8 @@ struct NamedArg : Arg {
|
||||
BasicStringRef<Char> name;
|
||||
|
||||
template <typename T>
|
||||
NamedArg(BasicStringRef<Char> name, const T &value)
|
||||
: name(name), Arg(MakeValue<Char>(value)) {
|
||||
NamedArg(BasicStringRef<Char> argname, const T &value)
|
||||
: name(argname), Arg(MakeValue<Char>(value)) {
|
||||
type = static_cast<internal::Arg::Type>(MakeValue<Char>::type(value));
|
||||
}
|
||||
};
|
||||
@ -1363,7 +1361,7 @@ protected:
|
||||
return args_;
|
||||
}
|
||||
|
||||
void set_args(const ArgList &args) {
|
||||
explicit FormatterBase(const ArgList &args) {
|
||||
args_ = args;
|
||||
next_arg_index_ = 0;
|
||||
}
|
||||
@ -1399,8 +1397,8 @@ private:
|
||||
unsigned parse_header(const Char *&s, FormatSpec &spec);
|
||||
|
||||
public:
|
||||
void format(BasicWriter<Char> &writer,
|
||||
BasicCStringRef<Char> format_str, const ArgList &args);
|
||||
explicit PrintfFormatter(const ArgList &args) : FormatterBase(args) {}
|
||||
void format(BasicWriter<Char> &writer, BasicCStringRef<Char> format_str);
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
@ -1409,7 +1407,6 @@ template <typename Char>
|
||||
class BasicFormatter : private internal::FormatterBase {
|
||||
private:
|
||||
BasicWriter<Char> &writer_;
|
||||
const Char *start_;
|
||||
internal::ArgMap<Char> map_;
|
||||
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(BasicFormatter);
|
||||
@ -1427,13 +1424,14 @@ private:
|
||||
internal::Arg parse_arg_name(const Char *&s);
|
||||
|
||||
public:
|
||||
explicit BasicFormatter(BasicWriter<Char> &w) : writer_(w) {}
|
||||
BasicFormatter(const ArgList &args, BasicWriter<Char> &w)
|
||||
: FormatterBase(args), writer_(w) {}
|
||||
|
||||
BasicWriter<Char> &writer() {
|
||||
return writer_;
|
||||
}
|
||||
|
||||
void format(BasicCStringRef<Char> format_str, const ArgList &args);
|
||||
void format(BasicCStringRef<Char> format_str);
|
||||
|
||||
const Char *format(const Char *&format_str, const internal::Arg &arg);
|
||||
};
|
||||
@ -1996,6 +1994,28 @@ private:
|
||||
return internal::make_ptr(&buffer_[size], n);
|
||||
}
|
||||
|
||||
// Writes an unsigned decimal integer.
|
||||
template <typename UInt>
|
||||
Char *write_unsigned_decimal(UInt value, unsigned prefix_size = 0) {
|
||||
unsigned num_digits = internal::count_digits(value);
|
||||
Char *ptr = get(grow_buffer(prefix_size + num_digits));
|
||||
internal::format_decimal(ptr + prefix_size, value, num_digits);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Writes a decimal integer.
|
||||
template <typename Int>
|
||||
void write_decimal(Int value) {
|
||||
typename internal::IntTraits<Int>::MainType abs_value = value;
|
||||
if (internal::is_negative(value)) {
|
||||
abs_value = 0 - abs_value;
|
||||
*write_unsigned_decimal(abs_value, 1) = '-';
|
||||
}
|
||||
else {
|
||||
write_unsigned_decimal(abs_value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare a buffer for integer formatting.
|
||||
CharPtr prepare_int_buffer(unsigned num_digits,
|
||||
const EmptySpec &, const char *prefix, unsigned prefix_size) {
|
||||
@ -2123,24 +2143,27 @@ public:
|
||||
\endrst
|
||||
*/
|
||||
void write(BasicCStringRef<Char> format, ArgList args) {
|
||||
BasicFormatter<Char>(*this).format(format, args);
|
||||
BasicFormatter<Char>(args, *this).format(format);
|
||||
}
|
||||
FMT_VARIADIC_VOID(write, BasicCStringRef<Char>)
|
||||
|
||||
BasicWriter &operator<<(int value) {
|
||||
return *this << IntFormatSpec<int>(value);
|
||||
write_decimal(value);
|
||||
return *this;
|
||||
}
|
||||
BasicWriter &operator<<(unsigned value) {
|
||||
return *this << IntFormatSpec<unsigned>(value);
|
||||
}
|
||||
BasicWriter &operator<<(long value) {
|
||||
return *this << IntFormatSpec<long>(value);
|
||||
write_decimal(value);
|
||||
return *this;
|
||||
}
|
||||
BasicWriter &operator<<(unsigned long value) {
|
||||
return *this << IntFormatSpec<unsigned long>(value);
|
||||
}
|
||||
BasicWriter &operator<<(LongLong value) {
|
||||
return *this << IntFormatSpec<LongLong>(value);
|
||||
write_decimal(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2638,12 +2661,6 @@ public:
|
||||
typedef BasicMemoryWriter<char> MemoryWriter;
|
||||
typedef BasicMemoryWriter<wchar_t> WMemoryWriter;
|
||||
|
||||
#if defined(WIN32) && defined(SPDLOG_USE_WCHAR)
|
||||
#define TMemoryWriter WMemoryWriter
|
||||
#else
|
||||
#define TMemoryWriter MemoryWriter
|
||||
#endif
|
||||
|
||||
/**
|
||||
\rst
|
||||
This class template provides operations for formatting and writing data
|
||||
@ -2823,7 +2840,7 @@ void print(std::ostream &os, CStringRef format_str, ArgList args);
|
||||
|
||||
template <typename Char>
|
||||
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) {
|
||||
internal::PrintfFormatter<Char>().format(w, format, args);
|
||||
internal::PrintfFormatter<Char>(args).format(w, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3158,4 +3175,4 @@ FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef)
|
||||
# include "format.cc"
|
||||
#endif
|
||||
|
||||
#endif // FMT_FORMAT_H_
|
||||
#endif // FMT_FORMAT_H_
|
Loading…
Reference in New Issue
Block a user