44 # define FMT_SECURE_SCL _SECURE_SCL 46 # define FMT_SECURE_SCL 0 54 # define FMT_MSC_VER _MSC_VER 56 # define FMT_MSC_VER 0 59 #if FMT_MSC_VER && FMT_MSC_VER <= 1500 60 typedef unsigned __int32 uint32_t;
61 typedef unsigned __int64 uint64_t;
62 typedef __int64 intmax_t;
67 #if !defined(FMT_HEADER_ONLY) && defined(_WIN32) 69 # define FMT_API __declspec(dllexport) 70 # elif defined(FMT_SHARED) 71 # define FMT_API __declspec(dllimport) 79 # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) 80 # define FMT_GCC_EXTENSION __extension__ 81 # if FMT_GCC_VERSION >= 406 82 # pragma GCC diagnostic push 85 # pragma GCC diagnostic ignored "-Wlong-long" 88 # pragma GCC diagnostic ignored "-Wshadow" 91 # pragma GCC diagnostic ignored "-Wsign-conversion" 93 # if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ 94 # define FMT_HAS_GXX_CXX11 1 97 # define FMT_GCC_EXTENSION 100 #if defined(__INTEL_COMPILER) 101 # define FMT_ICC_VERSION __INTEL_COMPILER 103 # define FMT_ICC_VERSION __ICL 106 #if defined(__clang__) && !defined(FMT_ICC_VERSION) 107 # pragma clang diagnostic push 108 # pragma clang diagnostic ignored "-Wdocumentation-unknown-command" 109 # pragma clang diagnostic ignored "-Wpadded" 112 #ifdef __GNUC_LIBSTD__ 113 # define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__) 117 # define FMT_HAS_FEATURE(x) __has_feature(x) 119 # define FMT_HAS_FEATURE(x) 0 123 # define FMT_HAS_BUILTIN(x) __has_builtin(x) 125 # define FMT_HAS_BUILTIN(x) 0 128 #ifdef __has_cpp_attribute 129 # define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) 131 # define FMT_HAS_CPP_ATTRIBUTE(x) 0 134 #ifndef FMT_USE_VARIADIC_TEMPLATES 138 # define FMT_USE_VARIADIC_TEMPLATES \ 139 (FMT_HAS_FEATURE(cxx_variadic_templates) || \ 140 (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1800) 143 #ifndef FMT_USE_RVALUE_REFERENCES 146 # if defined(FMT_GNUC_LIBSTD_VERSION) && FMT_GNUC_LIBSTD_VERSION <= 402 147 # define FMT_USE_RVALUE_REFERENCES 0 149 # define FMT_USE_RVALUE_REFERENCES \ 150 (FMT_HAS_FEATURE(cxx_rvalue_references) || \ 151 (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600) 155 #if FMT_USE_RVALUE_REFERENCES 160 #if defined(__GNUC__) && !defined(__EXCEPTIONS) 161 # define FMT_EXCEPTIONS 0 163 #if FMT_MSC_VER && !_HAS_EXCEPTIONS 164 # define FMT_EXCEPTIONS 0 166 #ifndef FMT_EXCEPTIONS 167 # define FMT_EXCEPTIONS 1 172 # define FMT_THROW(x) throw x 174 # define FMT_THROW(x) assert(false) 179 #ifndef FMT_USE_NOEXCEPT 180 # define FMT_USE_NOEXCEPT 0 185 # if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ 186 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \ 188 # define FMT_NOEXCEPT noexcept 190 # define FMT_NOEXCEPT throw() 193 # define FMT_NOEXCEPT 198 # if FMT_USE_OVERRIDE || FMT_HAS_FEATURE(cxx_override) || \ 199 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \ 201 # define FMT_OVERRIDE override 203 # define FMT_OVERRIDE 210 #ifndef FMT_USE_DELETED_FUNCTIONS 211 # define FMT_USE_DELETED_FUNCTIONS 0 214 #if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \ 215 (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1800 216 # define FMT_DELETED_OR_UNDEFINED = delete 217 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 218 TypeName(const TypeName&) = delete; \ 219 TypeName& operator=(const TypeName&) = delete 221 # define FMT_DELETED_OR_UNDEFINED 222 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 223 TypeName(const TypeName&); \ 224 TypeName& operator=(const TypeName&) 227 #ifndef FMT_USE_USER_DEFINED_LITERALS 232 # define FMT_USE_USER_DEFINED_LITERALS \ 233 FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES && \ 234 (FMT_HAS_FEATURE(cxx_user_literals) || \ 235 (FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900) && \ 236 (!defined(FMT_ICC_VERSION) || FMT_ICC_VERSION >= 1500) 240 # define FMT_ASSERT(condition, message) assert((condition) && message) 243 #if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) 244 # define FMT_BUILTIN_CLZ(n) __builtin_clz(n) 247 #if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) 248 # define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) 255 #if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) 262 # pragma intrinsic(_BitScanReverse) 263 inline uint32_t clz(uint32_t x)
266 _BitScanReverse(&r, x);
272 # pragma warning(suppress: 6102) 275 # define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n) 278 # pragma intrinsic(_BitScanReverse64) 281 inline uint32_t clzll(uint64_t x)
285 _BitScanReverse64(&r, x);
288 if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32)))
289 return 63 - (r + 32);
292 _BitScanReverse(&r, static_cast<uint32_t>(x));
299 # pragma warning(suppress: 6102) 302 # define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n) 350 template <
typename T>
365 class numeric_limits<
fmt::internal::DummyInt> :
366 public std::numeric_limits<int>
370 template <
typename T>
377 sizeof(
isinf(x)) ==
sizeof(
int)))
379 return isinf(x) != 0;
381 return !
_finite(static_cast<double>(x));
385 template <
typename T>
390 sizeof(
isnan(x)) ==
sizeof(
int)))
392 return isnan(x) != 0;
394 return _isnan(static_cast<double>(x)) != 0;
403 if (x < 0)
return true;
404 if (!isnotanumber(x))
return false;
405 int dec = 0, sign = 0;
407 _ecvt_s(buffer,
sizeof(buffer), x, 0, &dec, &sign);
421 #if FMT_USE_RVALUE_REFERENCES 425 template <
typename Char>
431 template <
typename Char>
434 template <
typename CharType,
462 template <
typename Char>
480 : data_(s), size_(
std::char_traits<
Char>::length(s)) {}
488 : data_(s.c_str()), size_(s.size()) {}
497 return std::basic_string<Char>(data_, size_);
515 std::size_t size = size_ < other.
size_ ? size_ : other.
size_;
516 int result = std::char_traits<Char>::compare(data_, other.
data_, size);
518 result = size_ == other.
size_ ? 0 : (size_ < other.
size_ ? -1 : 1);
576 template <
typename Char>
608 :
std::runtime_error(message.c_str()) {}
616 template <
typename T>
622 #define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \ 624 struct MakeUnsigned<T> { typedef U Type; } 634 template <
typename Int>
647 template <
typename T>
648 inline stdext::checked_array_iterator<T*>
make_ptr(T *ptr, std::size_t size)
650 return stdext::checked_array_iterator<T*>(ptr, size);
653 template <
typename T>
666 template <
typename T>
677 Buffer(T *ptr = 0, std::size_t capacity = 0)
678 : ptr_(ptr), size_(0), capacity_(capacity) {}
686 virtual void grow(std::size_t size) = 0;
708 if (new_size > capacity_)
720 if (capacity > capacity_)
728 if (size_ == capacity_)
730 ptr_[size_++] = value;
734 template <
typename U>
735 void append(
const U *begin,
const U *
end);
747 template <
typename T>
748 template <
typename U>
752 if (new_size > capacity_)
754 std::uninitialized_copy(begin, end,
764 template <
typename T, std::
size_t SIZE,
typename Allocator = std::allocator<T> >
773 if (this->ptr_ != data_) Allocator::deallocate(this->ptr_, this->capacity_);
781 : Allocator(alloc),
Buffer<T>(data_, SIZE) {}
787 #if FMT_USE_RVALUE_REFERENCES 792 Allocator &this_alloc = *
this, &other_alloc = other;
794 this->size_ = other.
size_;
799 std::uninitialized_copy(other.
data_, other.
data_ + this->size_,
804 this->ptr_ = other.
ptr_;
819 assert(
this != &other);
833 template <
typename T, std::
size_t SIZE,
typename Allocator>
836 std::size_t new_capacity = this->capacity_ + this->capacity_ / 2;
837 if (size > new_capacity)
839 T *new_ptr = this->allocate(new_capacity);
841 std::uninitialized_copy(this->ptr_, this->ptr_ + this->size_,
843 std::size_t old_capacity = this->capacity_;
844 T *old_ptr = this->ptr_;
845 this->capacity_ = new_capacity;
846 this->ptr_ = new_ptr;
850 if (old_ptr != data_)
851 Allocator::deallocate(old_ptr, old_capacity);
855 template <
typename Char>
862 FMT_API void grow(std::size_t size);
865 template <
typename Char>
870 typedef stdext::checked_array_iterator<Char*>
CharPtr;
876 return static_cast<Char>(value);
880 template <
typename Char>
897 template <
typename T>
898 FMT_API static int format_float(
char *buffer, std::size_t size,
899 const char *
format,
unsigned width,
int precision, T value);
915 template <
typename T>
916 FMT_API static int format_float(
wchar_t *buffer, std::size_t size,
917 const wchar_t *
format,
unsigned width,
int precision, T value);
921 template <
bool IsSigned>
924 template <
typename T>
934 template <
typename T>
943 template <
typename T>
950 template <
bool FitsIn32Bits>
962 template <
typename T>
975 template <
typename T =
void>
978 static const uint32_t POWERS_OF_10_32[];
979 static const uint64_t POWERS_OF_10_64[];
980 static const char DIGITS[];
983 #ifndef FMT_USE_EXTERN_TEMPLATES 986 # define FMT_USE_EXTERN_TEMPLATES (__clang__ && FMT_USE_VARIADIC_TEMPLATES) 989 #if FMT_USE_EXTERN_TEMPLATES && !defined(FMT_HEADER_ONLY) 995 #ifdef FMT_BUILTIN_CLZLL 1002 int t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12;
1015 if (n < 10)
return count;
1016 if (n < 100)
return count + 1;
1017 if (n < 1000)
return count + 2;
1018 if (n < 10000)
return count + 3;
1025 #ifdef FMT_BUILTIN_CLZ 1029 int t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12;
1037 template <
typename Char>
1053 template <
typename Char>
1056 if (++digit_index_ % 3 != 0)
1058 buffer -= sep_.
size();
1059 std::uninitialized_copy(sep_.
data(), sep_.
data() + sep_.
size(),
1067 template <
typename UInt,
typename Char,
typename ThousandsSep>
1071 buffer += num_digits;
1072 while (value >= 100)
1077 unsigned index =
static_cast<unsigned>((value % 100) * 2);
1086 *--buffer =
static_cast<char>(
'0' + value);
1089 unsigned index =
static_cast<unsigned>(value * 2);
1095 template <
typename UInt,
typename Char>
1102 # define FMT_USE_WINDOWS_H 0 1103 #elif !defined(FMT_USE_WINDOWS_H) 1104 # define FMT_USE_WINDOWS_H 1 1109 #if FMT_USE_WINDOWS_H 1118 FMT_API explicit UTF8ToUTF16(StringRef
s);
1125 return buffer_.
size() - 1;
1127 const wchar_t *c_str()
const 1146 FMT_API explicit UTF16ToUTF8(WStringRef
s);
1153 return buffer_.
size() - 1;
1155 const char *c_str()
const 1180 template <
typename Char>
1187 typedef void (*FormatFunc)(
1188 void *formatter,
const void *
arg,
void *format_str_ptr);
1216 INT, UINT, LONG_LONG,
ULONG_LONG, BOOL, CHAR, LAST_INTEGER_TYPE = CHAR,
1230 template <
typename Char>
1233 template <
typename T =
void>
1238 template <
typename T,
typename Char>
1245 template <
typename T>
1255 template <
typename T>
1262 template<
typename T,
bool ENABLE_CONVERSION>
1265 enum { value = ENABLE_CONVERSION };
1268 template<
typename T,
bool ENABLE_CONVERSION>
1271 enum { value =
false };
1274 template<
typename T>
1284 template<
typename T>
1287 enum { enable_conversion =
sizeof(
convert(get<T>())) ==
sizeof(Yes) };
1291 #define FMT_DISABLE_CONVERSION_TO_INT(Type) \ 1293 struct ConvertToInt<Type> { enum { value = 0 }; } 1300 template<
bool B,
class T =
void>
1309 template<
bool B,
class T,
class F>
1315 template<
class T,
class F>
1342 template <
typename LConv>
1346 return lc->thousands_sep;
1355 template <
typename Formatter>
1367 template <
typename T>
1369 template <
typename T>
1376 #if !FMT_MSC_VER || defined(_NATIVE_WCHAR_T_DEFINED) 1386 string.value = str.
data();
1387 string.size = str.
size();
1397 template <
typename T>
1399 void *formatter,
const void *
arg,
void *format_str_ptr)
1401 format(*static_cast<Formatter*>(formatter),
1402 *static_cast<const Char**>(format_str_ptr),
1403 *static_cast<const T*>(arg));
1409 #define FMT_MAKE_VALUE_(Type, field, TYPE, rhs) \ 1410 MakeValue(Type value) { field = rhs; } \ 1411 static uint64_t type(Type) { return Arg::TYPE; } 1413 #define FMT_MAKE_VALUE(Type, field, TYPE) \ 1414 FMT_MAKE_VALUE_(Type, field, TYPE, value) 1427 int_value =
static_cast<int>(value);
1429 long_long_value = value;
1438 if (
const_check(
sizeof(
unsigned long) ==
sizeof(
unsigned)))
1439 uint_value =
static_cast<unsigned>(value);
1441 ulong_long_value = value;
1443 static uint64_t
type(
unsigned long)
1445 return sizeof(
unsigned long) ==
sizeof(
unsigned) ?
1458 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) 1469 #define FMT_MAKE_STR_VALUE(Type, TYPE) \ 1470 MakeValue(Type value) { set_string(value); } \ 1471 static uint64_t type(Type) { return Arg::TYPE; } 1483 #define FMT_MAKE_WSTR_VALUE(Type, TYPE) \ 1484 MakeValue(typename WCharHelper<Type, Char>::Supported value) { \ 1485 set_string(value); \ 1487 static uint64_t type(Type) { return Arg::TYPE; } 1497 template <typename T>
1502 custom.value = &value;
1503 custom.format = &format_custom_arg<T>;
1506 template <
typename T>
1513 template <
typename T>
1521 template <
typename Char_>
1527 template <
typename Char_>
1534 template <
typename Formatter>
1543 template <
typename T>
1551 template <
typename Char>
1556 template <
typename T>
1568 template <
typename Char>
1571 template <
typename Char>
1595 unsigned shift = index * 4;
1596 uint64_t mask = 0xf;
1598 (types_ & (mask << shift)) >> shift);
1601 template <
typename Char>
1606 enum { MAX_PACKED_ARGS = 16 };
1611 : types_(types), values_(values) {}
1613 : types_(types), args_(args) {}
1620 bool use_values = type(MAX_PACKED_ARGS - 1) ==
Arg::NONE;
1621 if (index < MAX_PACKED_ARGS)
1626 val = use_values ? values_[index] : args_[index];
1627 arg.
type = arg_type;
1637 for (
unsigned i = MAX_PACKED_ARGS; i <= index; ++i)
1642 return args_[index];
1646 #define FMT_DISPATCH(call) static_cast<Impl*>(this)->call 1672 template <
typename Impl,
typename Result>
1724 template <
typename T>
1743 template <
typename T>
1842 template <
char TYPE>
1879 WidthSpec(
unsigned width,
wchar_t fill) : width_(width), fill_(fill) {}
1897 :
WidthSpec(width, fill), align_(align) {}
1911 template <
char TYPE>
1934 unsigned width = 0,
char type = 0,
wchar_t fill =
' ')
1935 :
AlignSpec(width, fill), flags_(0), precision_(-1), type_(type) {}
1939 return (flags_ & f) != 0;
1952 template <
typename T,
typename SpecT = TypeSpec<0>,
typename Char =
char>
1960 : SpecT(spec), value_(val) {}
1969 template <
typename Char>
1976 template <
typename FillChar>
2025 template <
char TYPE_CODE,
typename Char>
2027 int value,
unsigned width,
Char fill =
' ');
2029 #define FMT_DEFINE_INT_FORMATTERS(TYPE) \ 2030 inline IntFormatSpec<TYPE, TypeSpec<'b'> > bin(TYPE value) { \ 2031 return IntFormatSpec<TYPE, TypeSpec<'b'> >(value, TypeSpec<'b'>()); \ 2034 inline IntFormatSpec<TYPE, TypeSpec<'o'> > oct(TYPE value) { \ 2035 return IntFormatSpec<TYPE, TypeSpec<'o'> >(value, TypeSpec<'o'>()); \ 2038 inline IntFormatSpec<TYPE, TypeSpec<'x'> > hex(TYPE value) { \ 2039 return IntFormatSpec<TYPE, TypeSpec<'x'> >(value, TypeSpec<'x'>()); \ 2042 inline IntFormatSpec<TYPE, TypeSpec<'X'> > hexu(TYPE value) { \ 2043 return IntFormatSpec<TYPE, TypeSpec<'X'> >(value, TypeSpec<'X'>()); \ 2046 template <char TYPE_CODE> \ 2047 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> > pad( \ 2048 IntFormatSpec<TYPE, TypeSpec<TYPE_CODE> > f, unsigned width) { \ 2049 return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> >( \ 2050 f.value(), AlignTypeSpec<TYPE_CODE>(width, ' ')); \ 2057 template <char TYPE_CODE, typename Char> \ 2058 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char> pad( \ 2059 IntFormatSpec<TYPE, TypeSpec<TYPE_CODE>, Char> f, \ 2060 unsigned width, Char fill) { \ 2061 return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char>( \ 2062 f.value(), AlignTypeSpec<TYPE_CODE>(width, fill)); \ 2065 inline IntFormatSpec<TYPE, AlignTypeSpec<0> > pad( \ 2066 TYPE value, unsigned width) { \ 2067 return IntFormatSpec<TYPE, AlignTypeSpec<0> >( \ 2068 value, AlignTypeSpec<0>(width, ' ')); \ 2071 template <typename Char> \ 2072 inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \ 2073 TYPE value, unsigned width, Char fill) { \ 2074 return IntFormatSpec<TYPE, AlignTypeSpec<0>, Char>( \ 2075 value, AlignTypeSpec<0>(width, fill)); \ 2097 template <typename
Char>
2099 const
Char *str,
unsigned width,
Char fill = ' ')
2105 const wchar_t *str,
unsigned width,
char fill =
' ')
2113 template <
typename Char>
2117 typedef std::vector<
2119 typedef typename MapType::value_type
Pair;
2129 for (
typename MapType::const_iterator it = map_.begin(),
end = map_.end();
2132 if (it->first == name)
2139 template <
typename Impl,
typename Char>
2152 writer_.
write_int(reinterpret_cast<uintptr_t>(p), spec_);
2167 const char *str_value = value ?
"true" :
"false";
2180 : writer_(w), spec_(s) {}
2182 template <
typename T>
2188 template <
typename T>
2197 return visit_any_int(value);
2209 if (spec_.
align_ == ALIGN_NUMERIC || spec_.
flags_ != 0)
2214 const unsigned CHAR_SIZE = 1;
2215 if (spec_.
width_ > CHAR_SIZE)
2220 std::uninitialized_fill_n(out, spec_.
width_ - CHAR_SIZE, fill);
2221 out += spec_.
width_ - CHAR_SIZE;
2230 std::uninitialized_fill_n(out + CHAR_SIZE,
2231 spec_.
width_ - CHAR_SIZE, fill);
2243 if (spec_.
type_ ==
'p')
2244 return write_pointer(value);
2264 write_pointer(value);
2275 FMT_API Arg do_get_arg(
unsigned arg_index,
const char *&error);
2286 next_arg_index_ = 0;
2292 if (next_arg_index_ >= 0)
2294 error =
"cannot switch from manual to automatic argument indexing";
2302 return check_no_auto_index(error) ? do_get_arg(arg_index, error) :
Arg();
2307 if (next_arg_index_ > 0)
2309 error =
"cannot switch from automatic to manual argument indexing";
2312 next_arg_index_ = -1;
2316 template <
typename Char>
2325 template <
typename Char>
2334 unsigned arg_index = (std::numeric_limits<unsigned>::max)());
2363 template <
typename Impl,
typename Char>
2382 formatter_(formatter), format_(fmt) {}
2392 template <
typename Char>
2403 template <
typename CharType,
typename ArgFormatter>
2454 # define FMT_GEN(n, f) FMT_GEN##n(f) 2455 # define FMT_GEN1(f) f(0) 2456 # define FMT_GEN2(f) FMT_GEN1(f), f(1) 2457 # define FMT_GEN3(f) FMT_GEN2(f), f(2) 2458 # define FMT_GEN4(f) FMT_GEN3(f), f(3) 2459 # define FMT_GEN5(f) FMT_GEN4(f), f(4) 2460 # define FMT_GEN6(f) FMT_GEN5(f), f(5) 2461 # define FMT_GEN7(f) FMT_GEN6(f), f(6) 2462 # define FMT_GEN8(f) FMT_GEN7(f), f(7) 2463 # define FMT_GEN9(f) FMT_GEN8(f), f(8) 2464 # define FMT_GEN10(f) FMT_GEN9(f), f(9) 2465 # define FMT_GEN11(f) FMT_GEN10(f), f(10) 2466 # define FMT_GEN12(f) FMT_GEN11(f), f(11) 2467 # define FMT_GEN13(f) FMT_GEN12(f), f(12) 2468 # define FMT_GEN14(f) FMT_GEN13(f), f(13) 2469 # define FMT_GEN15(f) FMT_GEN14(f), f(14) 2478 template <
typename T>
2484 template <
unsigned N,
bool= (N < ArgList::MAX_PACKED_ARGS)>
2487 template <
unsigned N>
2492 template <
typename Formatter,
typename T>
2507 template <
unsigned N>
2512 template <
typename Formatter,
typename T>
2519 #if FMT_USE_VARIADIC_TEMPLATES 2520 template <
typename Arg,
typename...
Args>
2534 template <
typename T>
2538 # define FMT_ARG_TYPE_DEFAULT(n) ArgType t##n = ArgType() 2542 return t0.type | (t1.type << 4) | (t2.type << 8) | (t3.type << 12) |
2543 (t4.type << 16) | (t5.type << 20) | (t6.type << 24) | (t7.type << 28) |
2544 (t8.type << 32) | (t9.type << 36) | (t10.type << 40) | (t11.type << 44) |
2545 (t12.type << 48) | (t13.type << 52) | (t14.type << 56);
2550 # define FMT_MAKE_TEMPLATE_ARG(n) typename T##n 2551 # define FMT_MAKE_ARG_TYPE(n) T##n 2552 # define FMT_MAKE_ARG(n) const T##n &v##n 2553 # define FMT_ASSIGN_char(n) \ 2554 arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<char> >(v##n) 2555 # define FMT_ASSIGN_wchar_t(n) \ 2556 arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<wchar_t> >(v##n) 2558 #if FMT_USE_VARIADIC_TEMPLATES 2560 # define FMT_VARIADIC_VOID(func, arg_type) \ 2561 template <typename... Args> \ 2562 void func(arg_type arg0, const Args & ... args) { \ 2563 typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \ 2564 typename ArgArray::Type array{ \ 2565 ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \ 2566 func(arg0, fmt::ArgList(fmt::internal::make_type(args...), array)); \ 2570 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ 2571 template <typename... Args> \ 2572 ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \ 2573 typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \ 2574 typename ArgArray::Type array{ \ 2575 ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \ 2576 func(arg0, arg1, fmt::ArgList(fmt::internal::make_type(args...), array)); \ 2581 # define FMT_MAKE_REF(n) \ 2582 fmt::internal::MakeValue< fmt::BasicFormatter<Char> >(v##n) 2583 # define FMT_MAKE_REF2(n) v##n 2587 # define FMT_WRAP1(func, arg_type, n) \ 2588 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ 2589 inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ 2590 const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \ 2591 func(arg1, fmt::ArgList( \ 2592 fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \ 2596 # define FMT_VARIADIC_VOID(func, arg_type) \ 2597 inline void func(arg_type arg) { func(arg, fmt::ArgList()); } \ 2598 FMT_WRAP1(func, arg_type, 1) FMT_WRAP1(func, arg_type, 2) \ 2599 FMT_WRAP1(func, arg_type, 3) FMT_WRAP1(func, arg_type, 4) \ 2600 FMT_WRAP1(func, arg_type, 5) FMT_WRAP1(func, arg_type, 6) \ 2601 FMT_WRAP1(func, arg_type, 7) FMT_WRAP1(func, arg_type, 8) \ 2602 FMT_WRAP1(func, arg_type, 9) FMT_WRAP1(func, arg_type, 10) 2604 # define FMT_CTOR(ctor, func, arg0_type, arg1_type, n) \ 2605 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ 2606 ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ 2607 const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \ 2608 func(arg0, arg1, fmt::ArgList( \ 2609 fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \ 2613 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ 2614 FMT_CTOR(ctor, func, arg0_type, arg1_type, 1) \ 2615 FMT_CTOR(ctor, func, arg0_type, arg1_type, 2) \ 2616 FMT_CTOR(ctor, func, arg0_type, arg1_type, 3) \ 2617 FMT_CTOR(ctor, func, arg0_type, arg1_type, 4) \ 2618 FMT_CTOR(ctor, func, arg0_type, arg1_type, 5) \ 2619 FMT_CTOR(ctor, func, arg0_type, arg1_type, 6) \ 2620 FMT_CTOR(ctor, func, arg0_type, arg1_type, 7) \ 2621 FMT_CTOR(ctor, func, arg0_type, arg1_type, 8) \ 2622 FMT_CTOR(ctor, func, arg0_type, arg1_type, 9) \ 2623 FMT_CTOR(ctor, func, arg0_type, arg1_type, 10) 2628 #define FMT_FOR_EACH1(f, x0) f(x0, 0) 2629 #define FMT_FOR_EACH2(f, x0, x1) \ 2630 FMT_FOR_EACH1(f, x0), f(x1, 1) 2631 #define FMT_FOR_EACH3(f, x0, x1, x2) \ 2632 FMT_FOR_EACH2(f, x0 ,x1), f(x2, 2) 2633 #define FMT_FOR_EACH4(f, x0, x1, x2, x3) \ 2634 FMT_FOR_EACH3(f, x0, x1, x2), f(x3, 3) 2635 #define FMT_FOR_EACH5(f, x0, x1, x2, x3, x4) \ 2636 FMT_FOR_EACH4(f, x0, x1, x2, x3), f(x4, 4) 2637 #define FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5) \ 2638 FMT_FOR_EACH5(f, x0, x1, x2, x3, x4), f(x5, 5) 2639 #define FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6) \ 2640 FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5), f(x6, 6) 2641 #define FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7) \ 2642 FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6), f(x7, 7) 2643 #define FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8) \ 2644 FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7), f(x8, 8) 2645 #define FMT_FOR_EACH10(f, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) \ 2646 FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8), f(x9, 9) 2655 void init(
int err_code, CStringRef format_str,
ArgList args);
2692 init(error_code, message,
ArgList());
2722 template <
typename Char>
2735 static Char *
get(CharPtr p)
2748 static CharPtr fill_padding(CharPtr buffer,
2749 unsigned total_size, std::size_t content_size,
wchar_t fill);
2755 std::size_t size = buffer_.
size();
2756 buffer_.
resize(size + n);
2761 template <
typename UInt>
2765 Char *ptr =
get(grow_buffer(prefix_size + num_digits));
2771 template <
typename Int>
2775 MainType abs_value =
static_cast<MainType
>(value);
2778 abs_value = 0 - abs_value;
2779 *write_unsigned_decimal(abs_value, 1) =
'-';
2783 write_unsigned_decimal(abs_value, 0);
2789 const EmptySpec &,
const char *prefix,
unsigned prefix_size)
2791 unsigned size = prefix_size + num_digits;
2792 CharPtr p = grow_buffer(size);
2793 std::uninitialized_copy(prefix, prefix + prefix_size, p);
2794 return p + size - 1;
2797 template <
typename Spec>
2798 CharPtr prepare_int_buffer(
unsigned num_digits,
2799 const Spec &spec,
const char *prefix,
unsigned prefix_size);
2802 template <
typename T,
typename Spec>
2803 void write_int(T value, Spec spec);
2806 template <
typename T>
2807 void write_double(T value,
const FormatSpec &spec);
2810 template <
typename StrChar>
2811 CharPtr write_str(
const StrChar *
s, std::size_t size,
const AlignSpec &spec);
2813 template <
typename StrChar>
2821 void operator<<(typename internal::WCharHelper<wchar_t, Char>::Unsupported);
2829 *format_ptr++ =
'L';
2832 template<
typename T>
2835 template <
typename Impl,
typename Char_>
2859 return buffer_.
size();
2877 std::size_t size = buffer_.
size();
2879 buffer_[size] =
'\0';
2888 std::basic_string<Char>
str()
const 2890 return std::basic_string<Char>(&buffer_[0], buffer_.
size());
2926 write_decimal(value);
2931 return *this << IntFormatSpec<unsigned>(value);
2935 write_decimal(value);
2940 return *this << IntFormatSpec<unsigned long>(value);
2944 write_decimal(value);
2955 return *this << IntFormatSpec<ULongLong>(value);
2981 buffer_.push_back(value);
2988 buffer_.push_back(value);
2999 const Char *str = value.data();
3000 buffer_.append(str, str + value.size());
3007 const char *str = value.data();
3008 buffer_.append(str, str + value.size());
3012 template <
typename T,
typename Spec,
typename FillChar>
3016 write_int(spec.value(), spec);
3020 template <
typename StrChar>
3023 const StrChar *
s = spec.str();
3024 write_str(s, std::char_traits<Char>::length(s), spec);
3028 void clear() FMT_NOEXCEPT { buffer_.clear(); }
3033 template <
typename Char>
3034 template <
typename StrChar>
3036 const StrChar *s, std::size_t size,
const AlignSpec &spec)
3039 if (spec.
width() > size)
3041 out = grow_buffer(spec.
width());
3045 std::uninitialized_fill_n(out, spec.
width() - size, fill);
3046 out += spec.
width() - size;
3050 out = fill_padding(out, spec.
width(), size, fill);
3054 std::uninitialized_fill_n(out + size, spec.
width() - size, fill);
3059 out = grow_buffer(size);
3061 std::uninitialized_copy(s, s + size, out);
3065 template <
typename Char>
3066 template <
typename StrChar>
3074 const StrChar *str_value = s.
value;
3075 std::size_t str_size = s.
size;
3083 std::size_t precision =
static_cast<std::size_t
>(spec.
precision_);
3084 if (spec.
precision_ >= 0 && precision < str_size)
3085 str_size = precision;
3086 write_str(str_value, str_size, spec);
3089 template <
typename Char>
3092 CharPtr buffer,
unsigned total_size,
3093 std::size_t content_size,
wchar_t fill)
3095 std::size_t padding = total_size - content_size;
3096 std::size_t left_padding = padding / 2;
3098 std::uninitialized_fill_n(buffer, left_padding, fill_char);
3099 buffer += left_padding;
3101 std::uninitialized_fill_n(buffer + content_size,
3102 padding - left_padding, fill_char);
3106 template <
typename Char>
3107 template <
typename Spec>
3110 unsigned num_digits,
const Spec &spec,
3111 const char *prefix,
unsigned prefix_size)
3113 unsigned width = spec.width();
3116 if (spec.precision() >
static_cast<int>(num_digits))
3120 if (prefix_size > 0 && prefix[prefix_size - 1] ==
'0')
3122 unsigned number_size =
3124 AlignSpec subspec(number_size,
'0', ALIGN_NUMERIC);
3125 if (number_size >= width)
3126 return prepare_int_buffer(num_digits, subspec, prefix, prefix_size);
3127 buffer_.reserve(width);
3128 unsigned fill_size = width - number_size;
3131 CharPtr p = grow_buffer(fill_size);
3132 std::uninitialized_fill(p, p + fill_size, fill);
3134 CharPtr result = prepare_int_buffer(
3135 num_digits, subspec, prefix, prefix_size);
3138 CharPtr p = grow_buffer(fill_size);
3139 std::uninitialized_fill(p, p + fill_size, fill);
3143 unsigned size = prefix_size + num_digits;
3146 CharPtr p = grow_buffer(size);
3147 std::uninitialized_copy(prefix, prefix + prefix_size, p);
3148 return p + size - 1;
3150 CharPtr p = grow_buffer(width);
3154 std::uninitialized_copy(prefix, prefix + prefix_size, p);
3156 std::uninitialized_fill(p, end, fill);
3160 p = fill_padding(p, width, size, fill);
3161 std::uninitialized_copy(prefix, prefix + prefix_size, p);
3166 if (align == ALIGN_NUMERIC)
3168 if (prefix_size != 0)
3170 p = std::uninitialized_copy(prefix, prefix + prefix_size, p);
3171 size -= prefix_size;
3176 std::uninitialized_copy(prefix, prefix + prefix_size, end - size);
3178 std::uninitialized_fill(p, end - size, fill);
3184 template <
typename Char>
3185 template <
typename T,
typename Spec>
3188 unsigned prefix_size = 0;
3190 UnsignedType abs_value =
static_cast<UnsignedType
>(value);
3191 char prefix[4] =
"";
3196 abs_value = 0 - abs_value;
3200 prefix[0] = spec.flag(
PLUS_FLAG) ?
'+' :
' ';
3203 switch (spec.type())
3209 CharPtr p = prepare_int_buffer(num_digits, spec, prefix, prefix_size) + 1;
3216 UnsignedType n = abs_value;
3219 prefix[prefix_size++] =
'0';
3220 prefix[prefix_size++] = spec.type();
3222 unsigned num_digits = 0;
3227 while ((n >>= 4) != 0);
3228 Char *p =
get(prepare_int_buffer(
3229 num_digits, spec, prefix, prefix_size));
3231 const char *digits = spec.type() ==
'x' ?
3232 "0123456789abcdef" :
"0123456789ABCDEF";
3235 *p-- = digits[n & 0xf];
3237 while ((n >>= 4) != 0);
3243 UnsignedType n = abs_value;
3246 prefix[prefix_size++] =
'0';
3247 prefix[prefix_size++] = spec.type();
3249 unsigned num_digits = 0;
3254 while ((n >>= 1) != 0);
3255 Char *p =
get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
3259 *p-- =
static_cast<Char>(
'0' + (n & 1));
3261 while ((n >>= 1) != 0);
3266 UnsignedType n = abs_value;
3268 prefix[prefix_size++] =
'0';
3269 unsigned num_digits = 0;
3274 while ((n >>= 3) != 0);
3275 Char *p =
get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
3279 *p-- =
static_cast<Char>(
'0' + (n & 7));
3281 while ((n >>= 3) != 0);
3291 unsigned size =
static_cast<unsigned>(
3292 num_digits + sep.
size() * ((num_digits - 1) / 3));
3293 CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1;
3299 spec.type(), spec.flag(
CHAR_FLAG) ?
"char" :
"integer");
3304 template <
typename Char>
3305 template <
typename T>
3309 char type = spec.
type();
3354 std::size_t nan_size = 4;
3355 const char *nan = upper ?
" NAN" :
" nan";
3361 CharPtr out = write_str(nan, nan_size, spec);
3371 std::size_t inf_size = 4;
3372 const char *inf = upper ?
" INF" :
" inf";
3378 CharPtr out = write_str(inf, inf_size, spec);
3384 std::size_t offset = buffer_.size();
3385 unsigned width = spec.
width();
3388 buffer_.reserve(buffer_.size() + (width > 1u ? width : 1u));
3395 enum { MAX_FORMAT_SIZE = 10};
3398 *format_ptr++ =
'%';
3399 unsigned width_for_sprintf = width;
3401 *format_ptr++ =
'#';
3404 width_for_sprintf = 0;
3409 *format_ptr++ =
'-';
3411 *format_ptr++ =
'*';
3415 *format_ptr++ =
'.';
3416 *format_ptr++ =
'*';
3419 append_float_length(format_ptr, value);
3420 *format_ptr++ = type;
3429 std::size_t
buffer_size = buffer_.capacity() - offset;
3434 if (buffer_size == 0)
3436 buffer_.reserve(offset + 1);
3437 buffer_size = buffer_.capacity() - offset;
3440 start = &buffer_[offset];
3442 start, buffer_size, format, width_for_sprintf, spec.
precision(), value);
3446 if (offset + n < buffer_.capacity())
3448 buffer_.reserve(offset + n + 1);
3454 buffer_.reserve(buffer_.capacity() + 1);
3462 *(start - 1) = sign;
3467 *(start - 1) = fill;
3473 width = spec.
width();
3474 CharPtr p = grow_buffer(width);
3475 std::memmove(
get(p) + (width - n) / 2,
get(p), n *
sizeof(
Char));
3476 fill_padding(p, spec.
width(), n, fill);
3479 if (spec.
fill() !=
' ' || sign)
3481 while (*start ==
' ')
3484 *(start - 1) = sign;
3523 template <
typename Char,
typename Allocator = std::allocator<Char> >
3533 #if FMT_USE_RVALUE_REFERENCES 3581 template <
typename Char>
3603 template <std::
size_t SIZE>
3616 #if FMT_USE_WINDOWS_H 3653 WindowsError(
int error_code, CStringRef message)
3655 init(error_code, message,
ArgList());
3662 FMT_API void report_windows_error(
int error_code,
3689 w.
write(format_str, args);
3696 w.
write(format_str, args);
3722 template <
typename Char>
3773 return fprintf(stdout, format, args);
3784 enum {BUFFER_SIZE = std::numeric_limits<ULongLong>::digits10 + 3};
3785 mutable char buffer_[BUFFER_SIZE];
3791 char *buffer_end = buffer_ + BUFFER_SIZE - 1;
3792 while (value >= 100)
3797 unsigned index =
static_cast<unsigned>((value % 100) * 2);
3804 *--buffer_end =
static_cast<char>(
'0' + value);
3807 unsigned index =
static_cast<unsigned>(value * 2);
3815 ULongLong abs_value =
static_cast<ULongLong
>(value);
3816 bool negative = value < 0;
3818 abs_value = 0 - abs_value;
3827 FormatSigned(value);
3831 FormatSigned(value);
3835 FormatSigned(value);
3862 buffer_[BUFFER_SIZE - 1] =
'\0';
3880 template <
typename T>
3884 MainType abs_value =
static_cast<MainType
>(value);
3888 abs_value = 0 - abs_value;
3890 if (abs_value < 100)
3894 *buffer++ =
static_cast<char>(
'0' + abs_value);
3897 unsigned index =
static_cast<unsigned>(abs_value * 2);
3904 buffer += num_digits;
3917 template <
typename T>
3923 template <
typename T>
3931 template <
typename Char>
3933 template <
typename Char>
3942 # pragma GCC system_header 3946 #define FMT_EXPAND(args) args 3950 #define FMT_NARG(...) FMT_NARG_(__VA_ARGS__, FMT_RSEQ_N()) 3951 #define FMT_NARG_(...) FMT_EXPAND(FMT_ARG_N(__VA_ARGS__)) 3952 #define FMT_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N 3953 #define FMT_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 3955 #define FMT_CONCAT(a, b) a##b 3956 #define FMT_FOR_EACH_(N, f, ...) \ 3957 FMT_EXPAND(FMT_CONCAT(FMT_FOR_EACH, N)(f, __VA_ARGS__)) 3958 #define FMT_FOR_EACH(f, ...) \ 3959 FMT_EXPAND(FMT_FOR_EACH_(FMT_NARG(__VA_ARGS__), f, __VA_ARGS__)) 3961 #define FMT_ADD_ARG_NAME(type, index) type arg##index 3962 #define FMT_GET_ARG_NAME(type, index) arg##index 3964 #if FMT_USE_VARIADIC_TEMPLATES 3965 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \ 3966 template <typename... Args> \ 3967 ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ 3968 const Args & ... args) { \ 3969 typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \ 3970 typename ArgArray::Type array{ \ 3971 ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \ 3972 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \ 3973 fmt::ArgList(fmt::internal::make_type(args...), array)); \ 3978 # define FMT_WRAP(Char, ReturnType, func, call, n, ...) \ 3979 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ 3980 inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ 3981 FMT_GEN(n, FMT_MAKE_ARG)) { \ 3982 fmt::internal::ArgArray<n>::Type arr; \ 3983 FMT_GEN(n, FMT_ASSIGN_##Char); \ 3984 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList( \ 3985 fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), arr)); \ 3988 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \ 3989 inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__)) { \ 3990 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList()); \ 3992 FMT_WRAP(Char, ReturnType, func, call, 1, __VA_ARGS__) \ 3993 FMT_WRAP(Char, ReturnType, func, call, 2, __VA_ARGS__) \ 3994 FMT_WRAP(Char, ReturnType, func, call, 3, __VA_ARGS__) \ 3995 FMT_WRAP(Char, ReturnType, func, call, 4, __VA_ARGS__) \ 3996 FMT_WRAP(Char, ReturnType, func, call, 5, __VA_ARGS__) \ 3997 FMT_WRAP(Char, ReturnType, func, call, 6, __VA_ARGS__) \ 3998 FMT_WRAP(Char, ReturnType, func, call, 7, __VA_ARGS__) \ 3999 FMT_WRAP(Char, ReturnType, func, call, 8, __VA_ARGS__) \ 4000 FMT_WRAP(Char, ReturnType, func, call, 9, __VA_ARGS__) \ 4001 FMT_WRAP(Char, ReturnType, func, call, 10, __VA_ARGS__) \ 4002 FMT_WRAP(Char, ReturnType, func, call, 11, __VA_ARGS__) \ 4003 FMT_WRAP(Char, ReturnType, func, call, 12, __VA_ARGS__) \ 4004 FMT_WRAP(Char, ReturnType, func, call, 13, __VA_ARGS__) \ 4005 FMT_WRAP(Char, ReturnType, func, call, 14, __VA_ARGS__) \ 4006 FMT_WRAP(Char, ReturnType, func, call, 15, __VA_ARGS__) 4007 #endif // FMT_USE_VARIADIC_TEMPLATES 4036 #define FMT_VARIADIC(ReturnType, func, ...) \ 4037 FMT_VARIADIC_(char, ReturnType, func, return func, __VA_ARGS__) 4039 #define FMT_VARIADIC_W(ReturnType, func, ...) \ 4040 FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__) 4042 #define FMT_CAPTURE_ARG_(id, index) ::fmt::arg(#id, id) 4044 #define FMT_CAPTURE_ARG_W_(id, index) ::fmt::arg(L###id, id) 4060 #define FMT_CAPTURE(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_, __VA_ARGS__) 4062 #define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__) 4079 template <
typename Char>
4082 return (
'a' <= c && c <=
'z') || (
'A' <= c && c <=
'Z') ||
'_' == c;
4087 template <
typename Char>
4090 assert(
'0' <= *s && *s <=
'9');
4094 unsigned new_value = value * 10 + (*s++ -
'0');
4096 if (new_value < value)
4098 value = (std::numeric_limits<unsigned>::max)();
4103 while (
'0' <= *s && *s <=
'9');
4105 unsigned max_int = (std::numeric_limits<int>::max)();
4106 if (value > max_int)
4116 fmt::format(
"format specifier '{}' requires numeric argument", spec);
4121 template <
typename Char>
4124 char sign =
static_cast<char>(*s);
4129 "format specifier '{}' requires signed argument", sign)));
4135 template <
typename Char,
typename AF>
4139 if (check_no_auto_index(error))
4145 error =
"argument not found";
4150 template <
typename Char,
typename AF>
4153 const char *error = 0;
4159 *s !=
'}' && *s !=
':' ?
"invalid format string" : error));
4164 template <
typename Char,
typename AF>
4175 const char *error = 0;
4182 template <
typename Char,
typename ArgFormatter>
4187 const Char *
s = format_str;
4200 const Char *p = s + 1;
4223 if (
c ==
'}')
break;
4230 if (spec.
align_ == ALIGN_NUMERIC)
4272 if (
'0' <= *s && *s <=
'9')
4280 parse_arg_name(s) : parse_arg_index(s);
4283 ULongLong value = 0;
4284 switch (width_arg.
type)
4305 if (value > (std::numeric_limits<int>::max)())
4307 spec.
width_ =
static_cast<int>(value);
4315 if (
'0' <= *s && *s <=
'9')
4323 parse_arg_name(s) : parse_arg_index(s);
4326 ULongLong value = 0;
4327 switch (precision_arg.
type)
4348 if (value > (std::numeric_limits<int>::max)())
4359 fmt::format(
"precision not allowed in {} format specifier",
4365 if (*s !=
'}' && *s)
4366 spec.
type_ =
static_cast<char>(*s++);
4373 ArgFormatter(*
this, spec, s - 1).visit(arg);
4377 template <
typename Char,
typename AF>
4385 if (c !=
'{' && c !=
'}')
continue;
4388 write(writer_, start, s);
4394 write(writer_, start, s - 1);
4396 parse_arg_name(s) : parse_arg_index(s);
4397 start = s =
format(s, arg);
4399 write(writer_, start, s);
4403 #if FMT_USE_USER_DEFINED_LITERALS 4409 template <
typename Char>
4414 template <
typename...
Args>
4415 auto operator()(
Args && ... args)
const 4416 -> decltype(
format(str, std::forward<Args>(args)...))
4418 return format(str, std::forward<Args>(args)...);
4422 template <
typename Char>
4427 template <
typename T>
4430 return {str, std::forward<T>(value)};
4436 inline namespace literals
4449 inline internal::UdlFormat<char>
4450 operator"" _format(
const char *
s, std::size_t)
4454 inline internal::UdlFormat<wchar_t>
4455 operator"" _format(
const wchar_t *s, std::size_t)
4470 inline internal::UdlArg<char>
4471 operator"" _a(
const char *s, std::size_t)
4475 inline internal::UdlArg<wchar_t>
4476 operator"" _a(
const wchar_t *s, std::size_t)
4483 #endif // FMT_USE_USER_DEFINED_LITERALS 4486 #if FMT_GCC_VERSION >= 406 4487 # pragma GCC diagnostic pop 4490 #if defined(__clang__) && !defined(FMT_ICC_VERSION) 4491 # pragma clang diagnostic pop 4494 #ifdef FMT_HEADER_ONLY 4495 # define FMT_FUNC inline 4501 #endif // FMT_FORMAT_H_ CharPtr prepare_int_buffer(unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size)
BasicCStringRef(const Char *s)
void format_decimal(Char *buffer, UInt value, unsigned num_digits, ThousandsSep thousands_sep)
Result visit_bool(bool value)
AlignTypeSpec(unsigned width, wchar_t fill)
static const char DIGITS[]
MakeValue(typename WCharHelper< wchar_t, Char >::Supported value)
BasicStringRef(const Char *s)
StringRef thousands_sep(LConv *lc, LConvCheck< char *LConv::*,&LConv::thousands_sep >=0)
const T & operator[](std::size_t index) const
static const uint32_t POWERS_OF_10_32[]
bool is_negative(T value)
const Char * data() const
FMT_API void format_system_error(fmt::Writer &out, int error_code, fmt::StringRef message) FMT_NOEXCEPT
static void format_custom_arg(void *formatter, const void *arg, void *format_str_ptr)
static bool is_negative(T value)
void resize(std::size_t new_size)
friend bool operator!=(BasicStringRef lhs, BasicStringRef rhs)
friend bool operator<=(BasicStringRef lhs, BasicStringRef rhs)
Result visit_ulong_long(ULongLong value)
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
IntFormatSpec< int, TypeSpec<'x'> > hex(int value)
BasicWriter(Buffer< Char > &b)
Result visit_pointer(const void *)
FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args)
IntFormatSpec< int, TypeSpec<'o'> > oct(int value)
WidthSpec(unsigned width, wchar_t fill)
T * make_ptr(T *ptr, std::size_t)
FMT_API void report_unknown_type(char code, const char *type)
friend bool operator<(BasicStringRef lhs, BasicStringRef rhs)
void init(const M_string &remappings)
internal::FixedBuffer< Char > buffer_
Result visit_any_double(T)
void operator()(Char *&buffer)
void write(BasicCStringRef< Char > format, ArgList args)
static wchar_t convert(char value)
std::string format(CStringRef format_str, ArgList args)
BasicWriter & operator<<(unsigned long value)
std::size_t capacity() const
BasicArrayWriter(Char *array, std::size_t size)
const Char * c_str() const
FMT_GCC_EXTENSION typedef unsigned long long ULongLong
static uint64_t type(long)
Result visit_custom(Arg::CustomValue)
MakeValue(const NamedArg< Char_ > &value)
std::basic_string< Char > str() const
Char * write_unsigned_decimal(UInt value, unsigned prefix_size=0)
bool flag(unsigned) const
BasicWriter & operator<<(ULongLong value)
BasicWriter & operator<<(double value)
NamedArg(BasicStringRef< Char > argname, const T &value)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
static wchar_t convert(wchar_t value)
BasicStringRef< Char > name
unsigned parse_nonnegative_int(const Char *&s)
BasicStringRef(const Char *s, std::size_t size)
const Char * data() const FMT_NOEXCEPT
StringValue< signed char > sstring
ThousandsSep(fmt::StringRef sep)
BasicCStringRef(const std::basic_string< Char > &s)
Yes & convert(fmt::ULongLong)
T & operator[](std::size_t index)
FMT_API void print_colored(Color c, CStringRef format, ArgList args)
friend bool operator>(BasicStringRef lhs, BasicStringRef rhs)
void set_string(StringRef str)
static uint64_t type(unsigned long)
void append(const U *begin, const U *end)
static const uint64_t POWERS_OF_10_64[]
static uint64_t type(const T &)
FixedBuffer(Char *array, std::size_t size)
bool write(ros_opcua_srvs::Write::Request &req, ros_opcua_srvs::Write::Response &res)
std::basic_string< Char > to_string() const
BasicStringRef< wchar_t > WStringRef
void append_float_length(Char *&, T)
static uint64_t type(wchar_t)
void clear() FMT_NOEXCEPT
BasicStringRef< char > StringRef
BasicWriter & operator<<(long value)
fmt::BufferedFile & move(fmt::BufferedFile &f)
void clear() FMT_NOEXCEPT
FMT_DISABLE_CONVERSION_TO_INT(float)
void write_decimal(Int value)
BasicMemoryWriter< char > MemoryWriter
CharPtr grow_buffer(std::size_t n)
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec)
Result visit_long_long(LongLong value)
MakeValue(unsigned long value)
Result visit_double(double value)
IntFormatSpec< int, TypeSpec<'X'> > hexu(int value)
BasicWriter & operator<<(LongLong value)
BasicWriter & operator<<(typename internal::WCharHelper< StringRef, Char >::Supported value)
std::string sprintf(CStringRef format, ArgList args)
BasicCStringRef< char > CStringRef
friend bool operator==(BasicStringRef lhs, BasicStringRef rhs)
Result visit_uint(unsigned value)
static bool isinfinity(T x)
BasicWriter< char > Writer
void append_float_length(Char *&format_ptr, long double)
Result visit_string(Arg::StringValue< char >)
std::vector< std::pair< fmt::BasicStringRef< Char >, internal::Arg > > MapType
MakeUnsigned< Int >::Type to_unsigned(Int value)
friend bool operator>=(BasicStringRef lhs, BasicStringRef rhs)
Result visit_cstring(const char *)
SystemError(int error_code, CStringRef message)
StringValue< char > string
BasicWriter & operator<<(char value)
void check_sign(const Char *&s, const Arg &arg)
Buffer(T *ptr=0, std::size_t capacity=0)
BasicCStringRef< wchar_t > WCStringRef
void grow(std::size_t size) FMT_OVERRIDE
FMT_API void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT
internal::Arg operator[](unsigned index) const
BasicWriter & operator<<(typename internal::WCharHelper< wchar_t, Char >::Supported value)
static bool isnotanumber(T x)
int compare(BasicStringRef other) const
ArgList(ULongLong types, const internal::Arg *args)
No & operator<<(std::ostream &, int)
const internal::Arg * args_
void write_int(T value, Spec spec)
BasicWriter< wchar_t > WWriter
MakeValue(const T &value, typename EnableIf< ConvertToInt< T >::value, int >::type=0)
void push_back(const T &value)
BasicWriter & operator<<(long double value)
internal::CharTraits< Char >::CharPtr CharPtr
BasicArrayWriter(Char(&array)[SIZE])
BasicArrayWriter< char > ArrayWriter
BasicMemoryWriter(const Allocator &alloc=Allocator())
Allocator get_allocator() const
FMT_SPECIALIZE_MAKE_UNSIGNED(char, unsigned char)
static char convert(char value)
internal::NamedArg< char > arg(StringRef name, const T &arg)
const char * CharPtr(const char *s)
BasicWriter & operator<<(unsigned value)
void require_numeric_argument(const Arg &arg, char spec)
void set_string(WStringRef str)
Result visit_unhandled_arg()
StringValue< wchar_t > wstring
unsigned count_digits(uint64_t n)
MemoryBuffer(const Allocator &alloc=Allocator())
Buffer< Char > & buffer() FMT_NOEXCEPT
BasicStringRef(const std::basic_string< Char > &s)
void write_double(T value, const FormatSpec &spec)
Result visit_char(int value)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
IntFormatSpec< int, TypeSpec<'b'> > bin(int value)
void reserve(std::size_t capacity)
internal::MemoryBuffer< Char, internal::INLINE_BUFFER_SIZE, Allocator > buffer_
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
Result visit_int(int value)
static Arg make(const T &value)
ULongLong ulong_long_value
bool flag(unsigned) const
BasicMemoryWriter< wchar_t > WMemoryWriter
Result visit_wstring(Arg::StringValue< wchar_t >)
static uint64_t type(const NamedArg< Char_ > &)
AlignSpec(unsigned width, wchar_t fill, Alignment align=ALIGN_DEFAULT)
static bool isnegative(double x)
const Char * c_str() const
static bool is_negative(T)
long double long_double_value
void report_unhandled_arg()
StringValue< unsigned char > ustring
const internal::Value * values_
std::numeric_limits< fmt::internal::DummyInt > FPUtil
static Value make(const T &value)
static Char cast(int value)
static CharPtr fill_padding(CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill)
ArgList(ULongLong types, const internal::Value *values)
internal::Arg::Type type(unsigned index) const
Result visit_long_double(long double value)
BasicArrayWriter< wchar_t > WArrayWriter
FMT_GCC_EXTENSION typedef long long LongLong
bool is_name_start(Char c)
const internal::Arg * find(const fmt::BasicStringRef< Char > &name) const
Result visit(const Arg &arg)
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)