47 #if defined(_SECURE_SCL) && _SECURE_SCL 52 # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) 53 # define FMT_GCC_EXTENSION __extension__ 56 # if FMT_GCC_VERSION >= 406 57 # pragma GCC diagnostic push 58 # pragma GCC diagnostic ignored "-Wlong-long" 61 # define FMT_GCC_EXTENSION 64 #ifdef __GNUC_LIBSTD__ 65 # define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__) 69 # define FMT_HAS_FEATURE(x) __has_feature(x) 71 # define FMT_HAS_FEATURE(x) 0 75 # define FMT_HAS_BUILTIN(x) __has_builtin(x) 77 # define FMT_HAS_BUILTIN(x) 0 80 #ifndef FMT_USE_VARIADIC_TEMPLATES 84 # define FMT_USE_VARIADIC_TEMPLATES \ 85 (FMT_HAS_FEATURE(cxx_variadic_templates) || \ 86 (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || (defined(_MSC_VER) && _MSC_VER >= 1800)) 89 #ifndef FMT_USE_RVALUE_REFERENCES 92 # if defined(FMT_GNUC_LIBSTD_VERSION) && FMT_GNUC_LIBSTD_VERSION <= 402 93 # define FMT_USE_RVALUE_REFERENCES 0 95 # define FMT_USE_RVALUE_REFERENCES \ 96 (FMT_HAS_FEATURE(cxx_rvalue_references) || \ 97 (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || (defined(_MSC_VER) && _MSC_VER >= 1600)) 101 #if FMT_USE_RVALUE_REFERENCES 106 #if (defined(FMT_USE_NOEXCEPT) && FMT_USE_NOEXCEPT) || FMT_HAS_FEATURE(cxx_noexcept) || \ 107 (FMT_GCC_VERSION >= 408 && __cplusplus >= 201103) 108 # define FMT_NOEXCEPT(expr) noexcept(expr) 110 # define FMT_NOEXCEPT(expr) 115 #define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 116 TypeName(const TypeName&); \ 117 void operator=(const TypeName&) 126 #if FMT_USE_RVALUE_REFERENCES 130 template <
typename Char>
136 template <
typename Char>
139 template <
typename Char,
typename T>
167 template <
typename Char>
190 operator std::basic_string<Char>()
const {
191 return std::basic_string<Char>(
data_,
size());
203 if (size_ == 0 && data_) size_ = std::char_traits<Char>::length(data_);
224 :
std::runtime_error(message) {}
233 #if defined(_SECURE_SCL) && _SECURE_SCL 235 template <
typename T>
236 inline stdext::checked_array_iterator<T*>
make_ptr(
T *ptr, std::size_t
size) {
237 return stdext::checked_array_iterator<T*>(ptr,
size);
240 template <
typename T>
246 template <
typename T, std::
size_t SIZE>
254 void grow(std::size_t size);
258 if (ptr_ != data_)
delete [] ptr_;
279 explicit Array(std::size_t size = 0)
280 : size_(size), capacity_(SIZE), ptr_(data_) {}
283 #if FMT_USE_RVALUE_REFERENCES 289 assert(
this != &other);
304 if (new_size > capacity_)
311 if (capacity > capacity_)
318 if (size_ == capacity_)
320 ptr_[size_++] = value;
324 void append(
const T *begin,
const T *end);
327 const T &
operator[](std::size_t index)
const {
return ptr_[index]; }
330 template <
typename T, std::
size_t SIZE>
332 capacity_ = (std::max)(size, capacity_ + capacity_ / 2);
333 T *p =
new T[capacity_];
340 template <
typename T, std::
size_t SIZE>
342 std::ptrdiff_t num_elements = end - begin;
343 if (
size_ + num_elements > capacity_)
344 grow(
size_ + num_elements);
346 size_ += num_elements;
349 template <
typename Char>
352 #if defined(_SECURE_SCL) && _SECURE_SCL 353 typedef stdext::checked_array_iterator<Char*>
CharPtr;
359 template <
typename Char>
366 static char convert(
wchar_t);
371 static char convert(
char value) {
return value; }
374 template <
typename T>
375 static int format_float(
char *buffer, std::size_t size,
376 const char *
format,
unsigned width,
int precision,
T value);
384 static wchar_t convert(
char value) {
return value; }
385 static wchar_t convert(
wchar_t value) {
return value; }
387 template <
typename T>
388 static int format_float(
wchar_t *buffer, std::size_t size,
389 const wchar_t *
format,
unsigned width,
int precision,
T value);
393 template <
bool FitsIn32Bits>
400 template <
bool IsSigned>
402 template <
typename T>
408 template <
typename T>
414 template <
typename T>
419 template <
typename T>
428 template <
typename T>
431 #define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \ 433 struct MakeUnsigned<T> { typedef U Type; } 447 #if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) 453 unsigned t = (64 - __builtin_clzll(n | 1)) * 1233 >> 12;
454 return t - (n < POWERS_OF_10_64[t]) + 1;
456 # if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) 459 uint32_t t = (32 - __builtin_clz(n | 1)) * 1233 >> 12;
460 return t - (n < POWERS_OF_10_32[t]) + 1;
471 if (n < 10)
return count;
472 if (n < 100)
return count + 1;
473 if (n < 1000)
return count + 2;
474 if (n < 10000)
return count + 3;
481 extern const char DIGITS[];
484 template <
typename UInt,
typename Char>
487 while (value >= 100) {
491 unsigned index = (value % 100) * 2;
493 buffer[num_digits] = DIGITS[index + 1];
494 buffer[num_digits - 1] = DIGITS[index];
498 *buffer =
static_cast<char>(
'0' + value);
501 unsigned index =
static_cast<unsigned>(value * 2);
502 buffer[1] = DIGITS[index + 1];
503 buffer[0] = DIGITS[index];
514 explicit UTF8ToUTF16(StringRef s);
516 size_t size()
const {
return buffer_.
size() - 1; }
517 const wchar_t *
c_str()
const {
return &buffer_[0]; }
518 std::wstring str()
const {
return std::wstring(&buffer_[0],
size()); }
529 explicit UTF16ToUTF8(WStringRef s);
531 size_t size()
const {
return buffer_.
size() - 1; }
532 const char *
c_str()
const {
return &buffer_[0]; }
533 std::string str()
const {
return std::string(&buffer_[0],
size()); }
537 int convert(WStringRef s);
551 char *&buffer, std::size_t buffer_size)
FMT_NOEXCEPT(
true);
557 void format_windows_error(
564 template <
typename Char>
572 template <
unsigned Arg>
593 template <
typename Char>
600 void *formatter,
const void *arg,
const void *format_str);
622 template <
typename Char>
630 template <
typename T>
632 template <
typename T>
637 string.value = str.
c_str();
638 string.size = str.
size();
644 wstring.value = str.
c_str();
645 wstring.size = str.
size();
649 template <
typename T>
651 void *formatter,
const void *arg,
const void *format_str) {
653 static_cast<const Char*>(format_str), *static_cast<const T*>(arg));
660 MakeArg(
unsigned short value) { type =
UINT; uint_value = value; }
666 if (
sizeof(
long) ==
sizeof(
int)) {
668 int_value =
static_cast<int>(value);
671 long_long_value = value;
675 if (
sizeof(
unsigned long) ==
sizeof(
unsigned)) {
677 uint_value =
static_cast<unsigned>(value);
680 ulong_long_value = value;
683 MakeArg(LongLong value) { type = LONG_LONG; long_long_value = value; }
684 MakeArg(ULongLong value) { type = ULONG_LONG; ulong_long_value = value; }
685 MakeArg(
float value) { type = DOUBLE; double_value = value; }
686 MakeArg(
double value) { type = DOUBLE; double_value = value; }
687 MakeArg(
long double value) { type = LONG_DOUBLE; long_double_value = value; }
697 MakeArg(
const char *value) { set_string(value); }
698 MakeArg(
const std::string &value) { set_string(value); }
699 MakeArg(StringRef value) { set_string(value); }
701 MakeArg(
wchar_t *value) { set_string(value); }
702 MakeArg(
const wchar_t *value) { set_string(value); }
703 MakeArg(
const std::wstring &value) { set_string(value); }
704 MakeArg(WStringRef value) { set_string(value); }
706 MakeArg(
void *value) { type = POINTER; pointer_value = value; }
707 MakeArg(
const void *value) { type = POINTER; pointer_value = value; }
713 template <
typename T>
716 custom.value = &value;
717 custom.format = &format_custom_arg<T>;
722 #define FMT_DISPATCH(call) static_cast<Impl*>(this)->call 744 template <
typename Impl,
typename Result>
764 template <
typename T>
775 template <
typename T>
804 case Arg::ULONG_LONG:
808 case Arg::LONG_DOUBLE:
829 template <
typename Char>
844 : args_(args), size_(size) {}
871 const Arg &next_arg();
873 const Arg &handle_arg_index(
unsigned arg_index);
875 template <
typename Char>
878 w << BasicStringRef<Char>(start, end - start);
885 template <
typename Char>
888 void parse_flags(
FormatSpec &spec,
const Char *&s);
892 unsigned parse_header(
const Char *&s,
FormatSpec &spec);
901 template <
typename Char>
940 unsigned width()
const {
return 0; }
942 bool flag(
unsigned)
const {
return false; }
944 char fill()
const {
return ' '; }
954 WidthSpec(
unsigned width,
wchar_t fill) : width_(width), fill_(fill) {}
956 unsigned width()
const {
return width_; }
957 wchar_t fill()
const {
return fill_; }
965 :
WidthSpec(width, fill), align_(align) {}
977 bool flag(
unsigned)
const {
return false; }
988 unsigned width = 0,
char type = 0,
wchar_t fill =
' ')
989 :
AlignSpec(width, fill), flags_(0), precision_(-1), type_(type) {}
991 bool flag(
unsigned f)
const {
return (flags_ & f) != 0; }
993 char type()
const {
return type_; }
997 template <
typename T,
typename SpecT = TypeSpec<0>,
typename Char =
char>
1004 : SpecT(spec), value_(value) {}
1010 template <
typename T>
1019 const T *
str()
const {
return str_; }
1058 template <
char TYPE_CODE,
typename Char>
1060 int value,
unsigned width, Char fill =
' ');
1062 #define FMT_DEFINE_INT_FORMATTERS(TYPE) \ 1063 inline IntFormatSpec<TYPE, TypeSpec<'b'> > bin(TYPE value) { \ 1064 return IntFormatSpec<TYPE, TypeSpec<'b'> >(value, TypeSpec<'b'>()); \ 1067 inline IntFormatSpec<TYPE, TypeSpec<'o'> > oct(TYPE value) { \ 1068 return IntFormatSpec<TYPE, TypeSpec<'o'> >(value, TypeSpec<'o'>()); \ 1071 inline IntFormatSpec<TYPE, TypeSpec<'x'> > hex(TYPE value) { \ 1072 return IntFormatSpec<TYPE, TypeSpec<'x'> >(value, TypeSpec<'x'>()); \ 1075 inline IntFormatSpec<TYPE, TypeSpec<'X'> > hexu(TYPE value) { \ 1076 return IntFormatSpec<TYPE, TypeSpec<'X'> >(value, TypeSpec<'X'>()); \ 1079 template <char TYPE_CODE> \ 1080 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> > pad( \ 1081 IntFormatSpec<TYPE, TypeSpec<TYPE_CODE> > f, unsigned width) { \ 1082 return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> >( \ 1083 f.value(), AlignTypeSpec<TYPE_CODE>(width, ' ')); \ 1090 template <char TYPE_CODE, typename Char> \ 1091 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char> pad( \ 1092 IntFormatSpec<TYPE, TypeSpec<TYPE_CODE>, Char> f, \ 1093 unsigned width, Char fill) { \ 1094 return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char>( \ 1095 f.value(), AlignTypeSpec<TYPE_CODE>(width, fill)); \ 1098 inline IntFormatSpec<TYPE, AlignTypeSpec<0> > pad( \ 1099 TYPE value, unsigned width) { \ 1100 return IntFormatSpec<TYPE, AlignTypeSpec<0> >( \ 1101 value, AlignTypeSpec<0>(width, ' ')); \ 1104 template <typename Char> \ 1105 inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \ 1106 TYPE value, unsigned width, Char fill) { \ 1107 return IntFormatSpec<TYPE, AlignTypeSpec<0>, Char>( \ 1108 value, AlignTypeSpec<0>(width, fill)); \ 1130 template <typename Char>
1132 const Char *str,
unsigned width, Char fill = ' ') {
1137 const wchar_t *str,
unsigned width,
char fill =
' ') {
1142 # define FMT_GEN(n, f) FMT_GEN##n(f) 1143 # define FMT_GEN1(f) f(0) 1144 # define FMT_GEN2(f) FMT_GEN1(f), f(1) 1145 # define FMT_GEN3(f) FMT_GEN2(f), f(2) 1146 # define FMT_GEN4(f) FMT_GEN3(f), f(3) 1147 # define FMT_GEN5(f) FMT_GEN4(f), f(4) 1148 # define FMT_GEN6(f) FMT_GEN5(f), f(5) 1149 # define FMT_GEN7(f) FMT_GEN6(f), f(6) 1150 # define FMT_GEN8(f) FMT_GEN7(f), f(7) 1151 # define FMT_GEN9(f) FMT_GEN8(f), f(8) 1152 # define FMT_GEN10(f) FMT_GEN9(f), f(9) 1154 # define FMT_MAKE_TEMPLATE_ARG(n) typename T##n 1155 # define FMT_MAKE_ARG(n) const T##n &v##n 1156 # define FMT_MAKE_REF_char(n) fmt::internal::MakeArg<char>(v##n) 1157 # define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeArg<wchar_t>(v##n) 1159 #if FMT_USE_VARIADIC_TEMPLATES 1161 # define FMT_VARIADIC_VOID(func, arg_type) \ 1162 template<typename... Args> \ 1163 void func(arg_type arg1, const Args & ... args) { \ 1164 using fmt::internal::Arg; \ 1165 const Arg arg_array[fmt::internal::NonZero<sizeof...(Args)>::VALUE] = { \ 1166 fmt::internal::MakeArg<Char>(args)... \ 1168 func(arg1, ArgList(arg_array, sizeof...(Args))); \ 1172 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ 1173 template<typename... Args> \ 1174 ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \ 1175 using fmt::internal::Arg; \ 1176 const Arg arg_array[fmt::internal::NonZero<sizeof...(Args)>::VALUE] = { \ 1177 fmt::internal::MakeArg<Char>(args)... \ 1179 func(arg0, arg1, ArgList(arg_array, sizeof...(Args))); \ 1184 # define FMT_MAKE_REF(n) fmt::internal::MakeArg<Char>(v##n) 1187 # define FMT_WRAP1(func, arg_type, n) \ 1188 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ 1189 inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ 1190 const fmt::internal::Arg args[] = {FMT_GEN(n, FMT_MAKE_REF)}; \ 1191 func(arg1, fmt::ArgList(args, sizeof(args) / sizeof(*args))); \ 1195 # define FMT_VARIADIC_VOID(func, arg_type) \ 1196 FMT_WRAP1(func, arg_type, 1) FMT_WRAP1(func, arg_type, 2) \ 1197 FMT_WRAP1(func, arg_type, 3) FMT_WRAP1(func, arg_type, 4) \ 1198 FMT_WRAP1(func, arg_type, 5) FMT_WRAP1(func, arg_type, 6) \ 1199 FMT_WRAP1(func, arg_type, 7) FMT_WRAP1(func, arg_type, 8) \ 1200 FMT_WRAP1(func, arg_type, 9) FMT_WRAP1(func, arg_type, 10) 1202 # define FMT_CTOR(ctor, func, arg0_type, arg1_type, n) \ 1203 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ 1204 ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ 1205 const fmt::internal::Arg args[] = {FMT_GEN(n, FMT_MAKE_REF)}; \ 1206 func(arg0, arg1, fmt::ArgList(args, sizeof(args) / sizeof(*args))); \ 1210 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ 1211 FMT_CTOR(ctor, func, arg0_type, arg1_type, 1) \ 1212 FMT_CTOR(ctor, func, arg0_type, arg1_type, 2) \ 1213 FMT_CTOR(ctor, func, arg0_type, arg1_type, 3) \ 1214 FMT_CTOR(ctor, func, arg0_type, arg1_type, 4) \ 1215 FMT_CTOR(ctor, func, arg0_type, arg1_type, 5) \ 1216 FMT_CTOR(ctor, func, arg0_type, arg1_type, 6) \ 1217 FMT_CTOR(ctor, func, arg0_type, arg1_type, 7) \ 1218 FMT_CTOR(ctor, func, arg0_type, arg1_type, 8) \ 1219 FMT_CTOR(ctor, func, arg0_type, arg1_type, 9) \ 1220 FMT_CTOR(ctor, func, arg0_type, arg1_type, 10) 1225 #define FMT_FOR_EACH1(f, x0) f(x0, 0) 1226 #define FMT_FOR_EACH2(f, x0, x1) \ 1227 FMT_FOR_EACH1(f, x0), f(x1, 1) 1228 #define FMT_FOR_EACH3(f, x0, x1, x2) \ 1229 FMT_FOR_EACH2(f, x0 ,x1), f(x2, 2) 1230 #define FMT_FOR_EACH4(f, x0, x1, x2, x3) \ 1231 FMT_FOR_EACH3(f, x0, x1, x2), f(x3, 3) 1232 #define FMT_FOR_EACH5(f, x0, x1, x2, x3, x4) \ 1233 FMT_FOR_EACH4(f, x0, x1, x2, x3), f(x4, 4) 1234 #define FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5) \ 1235 FMT_FOR_EACH5(f, x0, x1, x2, x3, x4), f(x5, 5) 1236 #define FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6) \ 1237 FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5), f(x6, 6) 1238 #define FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7) \ 1239 FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6), f(x7, 7) 1240 #define FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8) \ 1241 FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7), f(x8, 8) 1242 #define FMT_FOR_EACH10(f, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) \ 1243 FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8), f(x9, 9) 1251 void init(
int error_code, StringRef format_str,
const ArgList &args);
1275 int error_code()
const {
return error_code_; }
1311 template <
typename Char>
1319 #if defined(_SECURE_SCL) && _SECURE_SCL 1321 static Char *
get(CharPtr p) {
return p.base(); }
1323 static Char *
get(Char *p) {
return p; }
1326 static CharPtr fill_padding(CharPtr buffer,
1327 unsigned total_size, std::size_t content_size,
wchar_t fill);
1333 buffer_.
resize(size + n);
1340 unsigned size = prefix_size + num_digits;
1341 CharPtr p = grow_buffer(size);
1342 std::copy(prefix, prefix + prefix_size, p);
1343 return p + size - 1;
1346 template <
typename Spec>
1347 CharPtr prepare_int_buffer(
unsigned num_digits,
1348 const Spec &spec,
const char *
prefix,
unsigned prefix_size);
1351 template <
typename T,
typename Spec>
1352 void write_int(
T value,
const Spec &spec);
1355 template <
typename T>
1356 void write_double(
T value,
const FormatSpec &spec);
1359 template <
typename StrChar>
1363 template <
typename StrChar>
1371 void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType);
1382 #if FMT_USE_RVALUE_REFERENCES 1393 assert(
this != &other);
1394 buffer_ = std::move(other.buffer_);
1408 const Char *
data()
const {
return &buffer_[0]; }
1415 std::size_t size = buffer_.
size();
1417 buffer_[
size] =
'\0';
1424 std::basic_string<Char>
str()
const {
1425 return std::basic_string<Char>(&buffer_[0], buffer_.
size());
1459 return *this << IntFormatSpec<int>(value);
1462 return *this << IntFormatSpec<unsigned>(value);
1465 return *this << IntFormatSpec<long>(value);
1468 return *this << IntFormatSpec<unsigned long>(value);
1471 return *this << IntFormatSpec<LongLong>(value);
1478 return *this << IntFormatSpec<ULongLong>(value);
1499 buffer_.push_back(value);
1512 const Char *str = value.
c_str();
1513 buffer_.append(str, str + value.size());
1517 template <
typename T,
typename Spec,
typename FillChar>
1518 BasicWriter &operator<<(const IntFormatSpec<T, Spec, FillChar> &spec) {
1520 write_int(spec.value(), spec);
1524 template <
typename StrChar>
1526 const StrChar *s = spec.
str();
1528 write_str(s, std::char_traits<Char>::length(s), spec);
1535 template <
typename Char>
1536 template <
typename StrChar>
1538 const StrChar *s, std::size_t
size,
const AlignSpec &spec) {
1541 out = grow_buffer(spec.
width());
1542 Char fill =
static_cast<Char
>(spec.
fill());
1544 std::fill_n(out, spec.
width() -
size, fill);
1547 out = fill_padding(out, spec.
width(),
size, fill);
1549 std::fill_n(out + size, spec.
width() -
size, fill);
1552 out = grow_buffer(size);
1558 template <
typename Char>
1559 template <
typename Spec>
1562 unsigned num_digits,
const Spec &spec,
1563 const char *
prefix,
unsigned prefix_size) {
1564 unsigned width = spec.width();
1566 Char fill =
static_cast<Char
>(spec.fill());
1567 if (spec.precision() >
static_cast<int>(num_digits)) {
1570 if (prefix_size > 0 && prefix[prefix_size - 1] ==
'0')
1572 unsigned number_size = prefix_size + spec.precision();
1574 if (number_size >= width)
1575 return prepare_int_buffer(num_digits, subspec, prefix, prefix_size);
1576 buffer_.reserve(width);
1577 unsigned fill_size = width - number_size;
1579 CharPtr p = grow_buffer(fill_size);
1580 std::fill(p, p + fill_size, fill);
1582 CharPtr result = prepare_int_buffer(
1583 num_digits, subspec, prefix, prefix_size);
1585 CharPtr p = grow_buffer(fill_size);
1586 std::fill(p, p + fill_size, fill);
1590 unsigned size = prefix_size + num_digits;
1591 if (width <= size) {
1592 CharPtr p = grow_buffer(size);
1593 std::copy(prefix, prefix + prefix_size, p);
1594 return p + size - 1;
1596 CharPtr p = grow_buffer(width);
1599 std::copy(prefix, prefix + prefix_size, p);
1601 std::fill(p, end, fill);
1603 p = fill_padding(p, width, size, fill);
1604 std::copy(prefix, prefix + prefix_size, p);
1608 if (prefix_size != 0) {
1609 p =
std::copy(prefix, prefix + prefix_size, p);
1610 size -= prefix_size;
1613 std::copy(prefix, prefix + prefix_size, end - size);
1615 std::fill(p, end - size, fill);
1621 template <
typename Char>
1622 template <
typename T,
typename Spec>
1624 unsigned prefix_size = 0;
1626 UnsignedType abs_value = value;
1631 abs_value = 0 - abs_value;
1633 prefix[0] = spec.flag(
PLUS_FLAG) ?
'+' :
' ';
1636 switch (spec.type()) {
1639 CharPtr p = prepare_int_buffer(
1640 num_digits, spec, prefix, prefix_size) + 1 - num_digits;
1644 case 'x':
case 'X': {
1645 UnsignedType n = abs_value;
1647 prefix[prefix_size++] =
'0';
1648 prefix[prefix_size++] = spec.type();
1650 unsigned num_digits = 0;
1653 }
while ((n >>= 4) != 0);
1654 Char *p =
get(prepare_int_buffer(
1655 num_digits, spec, prefix, prefix_size));
1657 const char *digits = spec.type() ==
'x' ?
1658 "0123456789abcdef" :
"0123456789ABCDEF";
1660 *p-- = digits[n & 0xf];
1661 }
while ((n >>= 4) != 0);
1664 case 'b':
case 'B': {
1665 UnsignedType n = abs_value;
1667 prefix[prefix_size++] =
'0';
1668 prefix[prefix_size++] = spec.type();
1670 unsigned num_digits = 0;
1673 }
while ((n >>= 1) != 0);
1674 Char *p =
get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
1677 *p-- =
'0' + (n & 1);
1678 }
while ((n >>= 1) != 0);
1682 UnsignedType n = abs_value;
1684 prefix[prefix_size++] =
'0';
1685 unsigned num_digits = 0;
1688 }
while ((n >>= 3) != 0);
1689 Char *p =
get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
1692 *p-- =
'0' + (n & 7);
1693 }
while ((n >>= 3) != 0);
1698 spec.type(), spec.flag(
CHAR_FLAG) ?
"char" :
"integer");
1704 template <
typename Char,
typename T>
1706 std::basic_ostringstream<Char> os;
1734 WindowsError(
int error_code,
StringRef message) {
1767 w.
write(format_str, args);
1773 w.
write(format_str, args);
1798 print(stdout, format_str, args);
1812 template <
typename Char>
1854 return fprintf(stdout, format, args);
1864 enum {BUFFER_SIZE = std::numeric_limits<ULongLong>::digits10 + 3};
1865 mutable char buffer_[BUFFER_SIZE];
1870 char *buffer_end = buffer_ + BUFFER_SIZE - 1;
1871 while (value >= 100) {
1875 unsigned index = (value % 100) * 2;
1881 *--buffer_end =
static_cast<char>(
'0' + value);
1884 unsigned index =
static_cast<unsigned>(value * 2);
1892 bool negative = value < 0;
1894 abs_value = 0 - abs_value;
1911 std::size_t
size()
const {
return buffer_ - str_ + BUFFER_SIZE - 1; }
1917 const char *
data()
const {
return str_; }
1924 buffer_[BUFFER_SIZE - 1] =
'\0';
1931 std::string
str()
const {
return std::string(str_,
size()); }
1937 template <
typename T>
1942 abs_value = 0 - abs_value;
1944 if (abs_value < 100) {
1945 if (abs_value < 10) {
1946 *buffer++ =
static_cast<char>(
'0' + abs_value);
1949 unsigned index =
static_cast<unsigned>(abs_value * 2);
1956 buffer += num_digits;
1965 # pragma GCC system_header 1969 #define FMT_EXPAND(args) args 1973 #define FMT_NARG(...) FMT_NARG_(__VA_ARGS__, FMT_RSEQ_N()) 1974 #define FMT_NARG_(...) FMT_EXPAND(FMT_ARG_N(__VA_ARGS__)) 1975 #define FMT_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N 1976 #define FMT_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 1978 #define FMT_CONCAT(a, b) a##b 1979 #define FMT_FOR_EACH_(N, f, ...) \ 1980 FMT_EXPAND(FMT_CONCAT(FMT_FOR_EACH, N)(f, __VA_ARGS__)) 1981 #define FMT_FOR_EACH(f, ...) \ 1982 FMT_EXPAND(FMT_FOR_EACH_(FMT_NARG(__VA_ARGS__), f, __VA_ARGS__)) 1984 #define FMT_ADD_ARG_NAME(type, index) type arg##index 1985 #define FMT_GET_ARG_NAME(type, index) arg##index 1987 #if FMT_USE_VARIADIC_TEMPLATES 1988 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \ 1989 template<typename... Args> \ 1990 ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ 1991 const Args & ... args) { \ 1992 using fmt::internal::Arg; \ 1993 const Arg array[fmt::internal::NonZero<sizeof...(Args)>::VALUE] = { \ 1994 fmt::internal::MakeArg<Char>(args)... \ 1996 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \ 1997 fmt::ArgList(array, sizeof...(Args))); \ 2002 # define FMT_WRAP(Char, ReturnType, func, call, n, ...) \ 2003 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ 2004 inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ 2005 FMT_GEN(n, FMT_MAKE_ARG)) { \ 2006 const fmt::internal::Arg args[] = {FMT_GEN(n, FMT_MAKE_REF_##Char)}; \ 2007 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \ 2008 fmt::ArgList(args, sizeof(args) / sizeof(*args))); \ 2011 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \ 2012 inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__)) { \ 2013 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList()); \ 2015 FMT_WRAP(Char, ReturnType, func, call, 1, __VA_ARGS__) \ 2016 FMT_WRAP(Char, ReturnType, func, call, 2, __VA_ARGS__) \ 2017 FMT_WRAP(Char, ReturnType, func, call, 3, __VA_ARGS__) \ 2018 FMT_WRAP(Char, ReturnType, func, call, 4, __VA_ARGS__) \ 2019 FMT_WRAP(Char, ReturnType, func, call, 5, __VA_ARGS__) \ 2020 FMT_WRAP(Char, ReturnType, func, call, 6, __VA_ARGS__) \ 2021 FMT_WRAP(Char, ReturnType, func, call, 7, __VA_ARGS__) \ 2022 FMT_WRAP(Char, ReturnType, func, call, 8, __VA_ARGS__) \ 2023 FMT_WRAP(Char, ReturnType, func, call, 9, __VA_ARGS__) \ 2024 FMT_WRAP(Char, ReturnType, func, call, 10, __VA_ARGS__) 2025 #endif // FMT_USE_VARIADIC_TEMPLATES 2054 #define FMT_VARIADIC(ReturnType, func, ...) \ 2055 FMT_VARIADIC_(char, ReturnType, func, return func, __VA_ARGS__) 2057 #define FMT_VARIADIC_W(ReturnType, func, ...) \ 2058 FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__) 2073 #if FMT_GCC_VERSION >= 406 2074 # pragma GCC diagnostic pop 2077 #endif // FMT_FORMAT_H_ CharPtr prepare_int_buffer(unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size)
Definition: format.h:1338
MakeArg(bool value)
Definition: format.h:658
AlignTypeSpec(unsigned width, wchar_t fill)
Definition: format.h:975
MakeArg(unsigned char value)
Definition: format.h:689
static void format_custom_arg(void *formatter, const void *arg, const void *format_str)
Definition: format.h:650
uint64_t Type
Definition: format.h:397
MakeArg(wchar_t *value)
Definition: format.h:701
void clear()
Definition: format.h:315
void format_system_error(fmt::Writer &out, int error_code, fmt::StringRef message)
Definition: format.cpp:458
void printf(BasicWriter< Char > &w, BasicStringRef< Char > format, const ArgList &args)
Definition: format.h:1813
MakeArg(signed char value)
Definition: format.h:688
bool is_negative(T value)
Definition: format.h:415
int safe_strerror(int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT(true)
Definition: format.cpp:430
Alignment align_
Definition: format.h:962
void print(std::FILE *f, StringRef format_str, const ArgList &args)
Prints formatted data to the file f.
Definition: format.cpp:1261
MakeArg()
Definition: format.h:657
MakeArg(short value)
Definition: format.h:659
Alignment align() const
Definition: format.h:939
friend bool operator!=(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:210
int precision() const
Definition: format.h:969
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
Returns an integer format specifier to pad the formatted argument with the fill character to the spec...
wchar_t fill_
Definition: format.h:952
IntFormatSpec< int, TypeSpec<'x'> > hex(int value)
Returns an integer format specifier to format the value in base 16 using lower-case letters for the d...
long double long_double_value
Definition: format.h:613
void set_string(WStringRef str)
Definition: format.h:641
Result visit_wstring(Arg::StringValue< wchar_t >)
Definition: format.h:783
Definition: format.h:1746
T Type
Definition: format.h:429
IntFormatSpec< int, TypeSpec<'o'> > oct(int value)
Returns an integer format specifier to format the value in base 8.
void reserve(std::size_t capacity)
Definition: format.h:310
WidthSpec(unsigned width, wchar_t fill)
Definition: format.h:954
void free()
Definition: format.h:257
T * make_ptr(T *ptr, std::size_t)
Definition: format.h:241
internal::Array< Char, internal::INLINE_BUFFER_SIZE > buffer_
Definition: format.h:1315
MakeArg(const char *value)
Definition: format.h:697
const Char * data() const
Returns a pointer to the output buffer content.
Definition: format.h:1408
std::size_t size() const
Returns the list size (the number of arguments).
Definition: format.h:849
const uint32_t POWERS_OF_10_32[]
Definition: format.cpp:365
double double_value
Definition: format.h:612
MakeArg(char value)
Definition: format.h:690
const T & operator[](std::size_t index) const
Definition: format.h:327
static CStr prefix
Definition: DllLoader.cpp:46
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:419
char Char
Definition: format.h:1256
Definition: format.h:1746
static wchar_t convert(char value)
Definition: format.h:384
StringValue< char > string
Definition: format.h:615
const char DIGITS[]
Definition: format.cpp:347
BasicWriter & operator<<(unsigned long value)
Definition: format.h:1467
void set_string(StringRef str)
Definition: format.h:635
unsigned width_
Definition: format.h:949
int INT
Definition: wgl.h:53
const Char * c_str() const
Returns the pointer to a C string.
Definition: format.h:197
FMT_GCC_EXTENSION typedef unsigned long long ULongLong
Definition: format.h:124
Result visit_long_long(LongLong value)
Definition: format.h:752
BasicWriter()
Constructs a BasicWriter object.
Definition: format.h:1380
MakeArg(unsigned short value)
Definition: format.h:660
Definition: format.h:1746
Definition: unique_range.h:196
Alignment align() const
Definition: format.h:967
std::size_t capacity() const
Definition: format.h:300
FormatFunc format
Definition: format.h:604
void write(BasicStringRef< Char > format, const ArgList &args)
Writes formatted data.
Definition: format.h:1453
std::basic_string< Char > str() const
Returns the content of the output buffer as an std::string.
Definition: format.h:1424
bool flag(unsigned) const
Definition: format.h:942
LongLong long_long_value
Definition: format.h:610
BasicWriter & operator<<(ULongLong value)
Formats value and writes it to the stream.
Definition: format.h:1477
MakeArg(const std::wstring &value)
Definition: format.h:703
BasicWriter & operator<<(double value)
Definition: format.h:1481
static wchar_t convert(wchar_t value)
Definition: format.h:385
uint32_t Type
Definition: format.h:394
int int_value
Definition: format.h:608
MakeArg(unsigned long value)
Definition: format.h:674
Result visit_string(Arg::StringValue< char >)
Definition: format.h:780
Result visit_ulong_long(ULongLong value)
Definition: format.h:758
char CHAR
Definition: wgl.h:60
void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT(true)
Definition: format.cpp:1247
Type
Definition: format.h:584
Result visit_uint(unsigned value)
Definition: format.h:755
Result visit_char(int value)
Definition: format.h:761
MakeArg(long double value)
Definition: format.h:687
wchar_t fill() const
Definition: format.h:957
BasicStringRef< wchar_t > WStringRef
Definition: format.h:216
void format(BasicFormatter< Char > &f, const Char *format_str, const T &value)
Definition: format.h:1705
unsigned width() const
Definition: format.h:940
unsigned long long uint64_t
Definition: wposix_types.h:57
BasicStringRef< char > StringRef
Definition: format.h:215
MakeArg(char *value)
Definition: format.h:696
std::size_t capacity_
Definition: format.h:250
ArgList(const internal::Arg *args, std::size_t size)
Definition: format.h:843
Result visit(const Arg &arg)
Definition: format.h:793
std::size_t size_
Definition: format.h:249
const wchar_t * UnsupportedStrType
Definition: format.h:369
BasicWriter & operator<<(long value)
Definition: format.h:1464
void print_colored(Color c, StringRef format, const ArgList &args)
Formats a string and prints it to stdout using ANSI escape sequences to specify color (experimental)...
Definition: format.cpp:1273
Alignment
Definition: format.h:923
void resize(std::size_t new_size)
Definition: format.h:303
MakeArg(float value)
Definition: format.h:685
Definition: format.h:1746
RuntimeError()
Definition: format.h:826
CharPtr grow_buffer(std::size_t n)
Definition: format.h:1331
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec)
Definition: format.h:1537
IntFormatSpec< int, TypeSpec<'X'> > hexu(int value)
Returns an integer formatter format specifier to format in base 16 using upper-case letters for the d...
BasicWriter & operator<<(LongLong value)
Definition: format.h:1470
An argument list.
Definition: format.h:836
SystemError()
Definition: format.h:1258
ULongLong ulong_long_value
Definition: format.h:611
Result visit_double(double value)
Definition: format.h:769
const void * value
Definition: format.h:603
friend bool operator==(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:207
BasicWriter< char > Writer
Definition: format.h:131
std::size_t size() const
Definition: format.h:297
Result visit_custom(Arg::CustomValue)
Definition: format.h:789
MakeArg(const void *value)
Definition: format.h:707
std::size_t size() const
Returns the total number of characters written.
Definition: format.h:1402
ArgList()
Definition: format.h:842
void move(Array &other)
Definition: format.h:262
Config::Array_type Array
Definition: json_spirit_value.h:184
BasicWriter & operator<<(char value)
Writes a character to the stream.
Definition: format.h:1498
#define TYPE(T)
Definition: GUIutil.cpp:419
const char * UnsupportedStrType
Definition: format.h:382
unsigned uint_value
Definition: format.h:609
The MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: LICENSE.txt:8
const internal::Arg & operator[](std::size_t index) const
Returns the argument at specified index.
Definition: format.h:854
std::size_t size() const
Returns the string size.
Definition: format.h:202
#define T(string_literal)
Definition: secure_crt.cpp:76
const internal::Arg * args_
Definition: format.h:838
Result visit_any_double(T)
Definition: format.h:776
Definition: format.h:1746
Char * CharPtr
Definition: format.h:355
BasicWriter< wchar_t > WWriter
Definition: format.h:134
BasicWriter & operator<<(wchar_t value)
Definition: format.h:1503
BasicWriter & operator<<(long double value)
Formats value using the general format for floating-point numbers ('g') and writes it to the stream...
Definition: format.h:1490
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:1317
Definition: format.h:1746
CustomValue custom
Definition: format.h:617
MakeArg(unsigned value)
Definition: format.h:662
Color
Definition: format.h:1746
T * ptr_
Definition: format.h:251
StringValue< wchar_t > wstring
Definition: format.h:616
char type() const
Definition: format.h:943
void report_unknown_type(char code, const char *type)
Definition: format.cpp:375
~Array()
Definition: format.h:281
static char convert(char value)
Definition: format.h:371
Result visit_long_double(long double value)
Definition: format.h:772
const void * pointer_value
Definition: format.h:614
BasicWriter & operator<<(unsigned value)
Definition: format.h:1461
std::string sprintf(StringRef format, const ArgList &args)
Formats arguments and returns the result as a string.
Definition: format.h:1827
unsigned short wchar_t
Definition: wgl.h:78
unsigned count_digits(uint64_t n)
Definition: format.h:465
int precision() const
Definition: format.h:941
This template provides operations for formatting and writing data into a character stream...
Definition: format.h:131
MakeArg(double value)
Definition: format.h:686
unsigned int uint32_t
Definition: wposix_types.h:53
Result visit_int(int value)
Definition: format.h:749
Array(std::size_t size=0)
Definition: format.h:279
BasicStringRef(const Char *s, std::size_t size=0)
Constructs a string reference object from a C string and a size.
Definition: format.h:179
static bool is_negative(T value)
Definition: format.h:409
Result visit_any_int(T)
Definition: format.h:765
void write(OutputCB &output, const T &data)
Outputs a structure, using sizeof to get the size.
Definition: CommonConvert.h:128
Definition: format.h:1746
BasicStringRef(const std::basic_string< Char > &s)
Constructs a string reference from an std::string object.
Definition: format.h:184
char fill() const
Definition: format.h:944
Definition: format.h:1746
MakeArg(int value)
Definition: format.h:661
MakeArg(long value)
Definition: format.h:663
IntFormatSpec< int, TypeSpec<'b'> > bin(int value)
Returns an integer format specifier to format the value in base 2.
unsigned int UINT
Definition: wgl.h:54
MakeArg(const std::string &value)
Definition: format.h:698
A string reference.
Definition: format.h:168
void push_back(const T &value)
Definition: format.h:317
void write_int(T value, const Spec &spec)
Definition: format.h:1623
Result visit_unhandled_arg()
Definition: format.h:747
std::size_t size_
Definition: format.h:839
bool flag(unsigned) const
Definition: format.h:977
MakeArg(const wchar_t *value)
Definition: format.h:702
Type type
Definition: format.h:591
An error returned by an operating system or a language runtime, for example a file opening error...
Definition: format.h:1249
AlignSpec(unsigned width, wchar_t fill, Alignment align=ALIGN_DEFAULT)
Definition: format.h:964
unsigned width() const
Definition: format.h:956
int fprintf(std::FILE *f, StringRef format, const ArgList &args)
Prints formatted data to the file f.
Definition: format.cpp:1281
const Char * c_str() const
Returns a pointer to the output buffer content with terminating null character appended.
Definition: format.h:1414
void format_decimal(Char *buffer, UInt value, unsigned num_digits)
Definition: format.h:485
MakeArg(WStringRef value)
Definition: format.h:704
MakeArg(ULongLong value)
Definition: format.h:684
const uint64_t POWERS_OF_10_64[]
Definition: format.cpp:366
MakeArg(LongLong value)
Definition: format.h:683
char type() const
Definition: format.h:978
void init(ScriptInterface &scriptInterface)
Definition: JSInterface_GUITypes.cpp:260
Result visit_pointer(const void *)
Definition: format.h:786
void clear()
Definition: format.h:1532
SystemError(int error_code, StringRef message)
Constructs a :cpp:class:fmt::SystemError object with the description of the form "*<message>*: *<syst...
Definition: format.h:1270
MakeArg(StringRef value)
Definition: format.h:699
MakeArg(void *value)
Definition: format.h:706
MakeArg(wchar_t value)
Definition: format.h:691
const Char * value
Definition: format.h:595
void format_decimal(char *&buffer, T value)
Definition: format.h:1938
T data_[SIZE]
Definition: format.h:252
T & operator[](std::size_t index)
Definition: format.h:326
int error_code_
Definition: format.h:1254
std::size_t size
Definition: format.h:596
FMT_GCC_EXTENSION typedef long long LongLong
Definition: format.h:123
const Char * data_
Definition: format.h:170
static bool is_negative(T)
Definition: format.h:403
std::size_t size_
Definition: format.h:171