| Victor Zverovich | c095445 | 2018-01-06 09:09:50 -0800 | [diff] [blame] | 1 | // Formatting library for C++ |
| 2 | // |
| 3 | // Copyright (c) 2012 - 2016, Victor Zverovich |
| 4 | // All rights reserved. |
| 5 | // |
| 6 | // For the license information refer to format.h. |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 7 | |
| 8 | #ifndef FMT_PRINTF_H_ |
| 9 | #define FMT_PRINTF_H_ |
| 10 | |
| 11 | #include <algorithm> // std::fill_n |
| 12 | #include <limits> // std::numeric_limits |
| 13 | |
| Victor Zverovich | f853d94 | 2018-01-20 10:28:10 -0800 | [diff] [blame] | 14 | #include "ostream.h" |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 15 | |
| Victor Zverovich | 838400d | 2018-05-12 08:33:51 -0700 | [diff] [blame] | 16 | FMT_BEGIN_NAMESPACE |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 17 | namespace internal { |
| 18 | |
| Victor Zverovich | 294fd7d | 2019-03-17 14:49:19 -0700 | [diff] [blame] | 19 | // A helper function to suppress bogus "conditional expression is constant" |
| 20 | // warnings. |
| 21 | template <typename T> inline T const_check(T value) { return value; } |
| 22 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 23 | // Checks if a value fits in int - used to avoid warnings about comparing |
| 24 | // signed and unsigned integers. |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 25 | template <bool IsSigned> struct int_checker { |
| 26 | template <typename T> static bool fits_in_int(T value) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 27 | unsigned max = std::numeric_limits<int>::max(); |
| 28 | return value <= max; |
| 29 | } |
| 30 | static bool fits_in_int(bool) { return true; } |
| 31 | }; |
| 32 | |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 33 | template <> struct int_checker<true> { |
| 34 | template <typename T> static bool fits_in_int(T value) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 35 | return value >= std::numeric_limits<int>::min() && |
| 36 | value <= std::numeric_limits<int>::max(); |
| 37 | } |
| 38 | static bool fits_in_int(int) { return true; } |
| 39 | }; |
| 40 | |
| Victor Zverovich | 874d672 | 2019-06-13 20:16:06 -0700 | [diff] [blame] | 41 | class printf_precision_handler { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 42 | public: |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 43 | template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)> |
| 44 | int operator()(T value) { |
| Victor Zverovich | 418659a | 2018-03-03 14:04:59 -0800 | [diff] [blame] | 45 | if (!int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value)) |
| Victor Zverovich | 9bb213e | 2016-08-25 08:38:07 -0700 | [diff] [blame] | 46 | FMT_THROW(format_error("number is too big")); |
| Victor Zverovich | bd516e3 | 2019-04-21 07:39:41 -0700 | [diff] [blame] | 47 | return (std::max)(static_cast<int>(value), 0); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 48 | } |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 49 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 50 | template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)> |
| 51 | int operator()(T) { |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 52 | FMT_THROW(format_error("precision is not integer")); |
| Victor Zverovich | 6322b47 | 2018-06-06 16:51:35 +0200 | [diff] [blame] | 53 | return 0; |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 54 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 57 | // An argument visitor that returns true iff arg is a zero integer. |
| Victor Zverovich | 874d672 | 2019-06-13 20:16:06 -0700 | [diff] [blame] | 58 | class is_zero_int { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 59 | public: |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 60 | template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)> |
| 61 | bool operator()(T value) { |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 62 | return value == 0; |
| 63 | } |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 64 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 65 | template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)> |
| 66 | bool operator()(T) { |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 67 | return false; |
| 68 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 71 | template <typename T> struct make_unsigned_or_bool : std::make_unsigned<T> {}; |
| Victor Zverovich | 0fbd846 | 2017-09-04 11:41:15 -0700 | [diff] [blame] | 72 | |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 73 | template <> struct make_unsigned_or_bool<bool> { using type = bool; }; |
| Victor Zverovich | 0fbd846 | 2017-09-04 11:41:15 -0700 | [diff] [blame] | 74 | |
| Victor Zverovich | 874d672 | 2019-06-13 20:16:06 -0700 | [diff] [blame] | 75 | template <typename T, typename Context> class arg_converter { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 76 | private: |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 77 | using char_type = typename Context::char_type; |
| Victor Zverovich | d705d51 | 2016-12-29 09:07:39 -0800 | [diff] [blame] | 78 | |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 79 | basic_format_arg<Context>& arg_; |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 80 | char_type type_; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 81 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 82 | public: |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 83 | arg_converter(basic_format_arg<Context>& arg, char_type type) |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 84 | : arg_(arg), type_(type) {} |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 85 | |
| Victor Zverovich | 751ff64 | 2016-11-19 08:40:24 -0800 | [diff] [blame] | 86 | void operator()(bool value) { |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 87 | if (type_ != 's') operator()<bool>(value); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 90 | template <typename U, FMT_ENABLE_IF(std::is_integral<U>::value)> |
| 91 | void operator()(U value) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 92 | bool is_signed = type_ == 'd' || type_ == 'i'; |
| Victor Zverovich | c264e64 | 2019-06-04 18:50:30 -0700 | [diff] [blame] | 93 | using target_type = conditional_t<std::is_same<T, void>::value, U, T>; |
| 94 | if (const_check(sizeof(target_type) <= sizeof(int))) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 95 | // Extra casts are used to silence warnings. |
| 96 | if (is_signed) { |
| Victor Zverovich | d705d51 | 2016-12-29 09:07:39 -0800 | [diff] [blame] | 97 | arg_ = internal::make_arg<Context>( |
| Victor Zverovich | c264e64 | 2019-06-04 18:50:30 -0700 | [diff] [blame] | 98 | static_cast<int>(static_cast<target_type>(value))); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 99 | } else { |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 100 | using unsigned_type = typename make_unsigned_or_bool<target_type>::type; |
| Victor Zverovich | d705d51 | 2016-12-29 09:07:39 -0800 | [diff] [blame] | 101 | arg_ = internal::make_arg<Context>( |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 102 | static_cast<unsigned>(static_cast<unsigned_type>(value))); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 103 | } |
| 104 | } else { |
| 105 | if (is_signed) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 106 | // glibc's printf doesn't sign extend arguments of smaller types: |
| 107 | // std::printf("%lld", -42); // prints "4294967254" |
| 108 | // but we don't have to do the same because it's a UB. |
| Victor Zverovich | 016aceb | 2017-08-26 09:09:43 -0700 | [diff] [blame] | 109 | arg_ = internal::make_arg<Context>(static_cast<long long>(value)); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 110 | } else { |
| Victor Zverovich | d705d51 | 2016-12-29 09:07:39 -0800 | [diff] [blame] | 111 | arg_ = internal::make_arg<Context>( |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 112 | static_cast<typename make_unsigned_or_bool<U>::type>(value)); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | } |
| Victor Zverovich | 751ff64 | 2016-11-19 08:40:24 -0800 | [diff] [blame] | 116 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 117 | template <typename U, FMT_ENABLE_IF(!std::is_integral<U>::value)> |
| 118 | void operator()(U) {} // No conversion needed for non-integral types. |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 119 | }; |
| 120 | |
| Victor Zverovich | 751ff64 | 2016-11-19 08:40:24 -0800 | [diff] [blame] | 121 | // Converts an integer argument to T for printf, if T is an integral type. |
| 122 | // If T is void, the argument is converted to corresponding signed or unsigned |
| 123 | // type depending on the type specifier: 'd' and 'i' - signed, other - |
| 124 | // unsigned). |
| Victor Zverovich | d705d51 | 2016-12-29 09:07:39 -0800 | [diff] [blame] | 125 | template <typename T, typename Context, typename Char> |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 126 | void convert_arg(basic_format_arg<Context>& arg, Char type) { |
| Victor Zverovich | f548063 | 2018-10-05 07:15:41 -0700 | [diff] [blame] | 127 | visit_format_arg(arg_converter<T, Context>(arg, type), arg); |
| Victor Zverovich | 751ff64 | 2016-11-19 08:40:24 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 130 | // Converts an integer argument to char for printf. |
| Victor Zverovich | 874d672 | 2019-06-13 20:16:06 -0700 | [diff] [blame] | 131 | template <typename Context> class char_converter { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 132 | private: |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 133 | basic_format_arg<Context>& arg_; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 134 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 135 | public: |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 136 | explicit char_converter(basic_format_arg<Context>& arg) : arg_(arg) {} |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 137 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 138 | template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)> |
| 139 | void operator()(T value) { |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 140 | arg_ = internal::make_arg<Context>( |
| Victor Zverovich | dd8cc8b | 2019-07-09 11:50:16 -0700 | [diff] [blame] | 141 | static_cast<typename Context::char_type>(value)); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 142 | } |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 143 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 144 | template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)> |
| 145 | void operator()(T) {} // No conversion needed for non-integral types. |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | // Checks if an argument is a valid printf width specifier and sets |
| 149 | // left alignment if it is negative. |
| Victor Zverovich | 874d672 | 2019-06-13 20:16:06 -0700 | [diff] [blame] | 150 | template <typename Char> class printf_width_handler { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 151 | private: |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 152 | using format_specs = basic_format_specs<Char>; |
| Victor Zverovich | bf0f107 | 2017-01-28 13:17:47 +0000 | [diff] [blame] | 153 | |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 154 | format_specs& specs_; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 155 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 156 | public: |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 157 | explicit printf_width_handler(format_specs& specs) : specs_(specs) {} |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 158 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 159 | template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)> |
| 160 | unsigned operator()(T value) { |
| Victor Zverovich | c286ffc | 2019-07-03 16:01:21 -0700 | [diff] [blame] | 161 | auto width = static_cast<uint32_or_64_t<T>>(value); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 162 | if (internal::is_negative(value)) { |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 163 | specs_.align = align::left; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 164 | width = 0 - width; |
| 165 | } |
| Victor Zverovich | e0d6f63 | 2016-06-15 06:29:47 -0700 | [diff] [blame] | 166 | unsigned int_max = std::numeric_limits<int>::max(); |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 167 | if (width > int_max) FMT_THROW(format_error("number is too big")); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 168 | return static_cast<unsigned>(width); |
| 169 | } |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 170 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 171 | template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)> |
| 172 | unsigned operator()(T) { |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 173 | FMT_THROW(format_error("width is not integer")); |
| Victor Zverovich | 6322b47 | 2018-06-06 16:51:35 +0200 | [diff] [blame] | 174 | return 0; |
| Victor Zverovich | e2dfd39 | 2016-11-19 09:29:09 -0800 | [diff] [blame] | 175 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 176 | }; |
| Victor Zverovich | 8c2e15a | 2018-12-12 16:07:54 -0800 | [diff] [blame] | 177 | |
| 178 | template <typename Char, typename Context> |
| Victor Zverovich | 2808395 | 2019-04-07 10:05:49 -0700 | [diff] [blame] | 179 | void printf(buffer<Char>& buf, basic_string_view<Char> format, |
| Victor Zverovich | 8c2e15a | 2018-12-12 16:07:54 -0800 | [diff] [blame] | 180 | basic_format_args<Context> args) { |
| 181 | Context(std::back_inserter(buf), format, args).format(); |
| 182 | } |
| Daniela Engert | b0cde86 | 2019-01-01 11:45:56 +0100 | [diff] [blame] | 183 | |
| 184 | template <typename OutputIt, typename Char, typename Context> |
| 185 | internal::truncating_iterator<OutputIt> printf( |
| 186 | internal::truncating_iterator<OutputIt> it, basic_string_view<Char> format, |
| 187 | basic_format_args<Context> args) { |
| 188 | return Context(it, format, args).format(); |
| 189 | } |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 190 | } // namespace internal |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 191 | |
| Victor Zverovich | 8c2e15a | 2018-12-12 16:07:54 -0800 | [diff] [blame] | 192 | using internal::printf; // For printing into memory_buffer. |
| 193 | |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 194 | template <typename Range> class printf_arg_formatter; |
| Victor Zverovich | 10e70a0 | 2017-12-02 09:44:48 -0800 | [diff] [blame] | 195 | |
| Victor Zverovich | 397e8dd | 2019-04-15 11:39:19 -0700 | [diff] [blame] | 196 | template <typename OutputIt, typename Char> class basic_printf_context; |
| Victor Zverovich | 10e70a0 | 2017-12-02 09:44:48 -0800 | [diff] [blame] | 197 | |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 198 | /** |
| 199 | \rst |
| Victor Zverovich | d58cc8a | 2016-11-20 07:42:38 -0800 | [diff] [blame] | 200 | The ``printf`` argument formatter. |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 201 | \endrst |
| 202 | */ |
| Victor Zverovich | c095445 | 2018-01-06 09:09:50 -0800 | [diff] [blame] | 203 | template <typename Range> |
| Victor Zverovich | 9d7b64a | 2019-06-11 22:11:47 -0700 | [diff] [blame] | 204 | class printf_arg_formatter : public internal::arg_formatter_base<Range> { |
| ToolsDevler | 2b415b7 | 2019-04-11 11:05:55 +0200 | [diff] [blame] | 205 | public: |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 206 | using iterator = typename Range::iterator; |
| Victor Zverovich | 397e8dd | 2019-04-15 11:39:19 -0700 | [diff] [blame] | 207 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 208 | private: |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 209 | using char_type = typename Range::value_type; |
| 210 | using base = internal::arg_formatter_base<Range>; |
| 211 | using context_type = basic_printf_context<iterator, char_type>; |
| Victor Zverovich | bd8a7e7 | 2018-01-21 14:30:38 -0800 | [diff] [blame] | 212 | |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 213 | context_type& context_; |
| Victor Zverovich | 10e70a0 | 2017-12-02 09:44:48 -0800 | [diff] [blame] | 214 | |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 215 | void write_null_pointer(char) { |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 216 | this->specs()->type = 0; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 217 | this->write("(nil)"); |
| 218 | } |
| 219 | |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 220 | void write_null_pointer(wchar_t) { |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 221 | this->specs()->type = 0; |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 222 | this->write(L"(nil)"); |
| 223 | } |
| 224 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 225 | public: |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 226 | using format_specs = typename base::format_specs; |
| Victor Zverovich | bf0f107 | 2017-01-28 13:17:47 +0000 | [diff] [blame] | 227 | |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 228 | /** |
| 229 | \rst |
| 230 | Constructs an argument formatter object. |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 231 | *buffer* is a reference to the output buffer and *specs* contains format |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 232 | specifier information for standard argument types. |
| 233 | \endrst |
| 234 | */ |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 235 | printf_arg_formatter(iterator iter, format_specs& specs, context_type& ctx) |
| 236 | : base(Range(iter), &specs, internal::locale_ref()), context_(ctx) {} |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 237 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 238 | template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)> |
| 239 | iterator operator()(T value) { |
| Victor Zverovich | e928b67 | 2018-07-04 11:36:38 -0700 | [diff] [blame] | 240 | // MSVC2013 fails to compile separate overloads for bool and char_type so |
| 241 | // use std::is_same instead. |
| 242 | if (std::is_same<T, bool>::value) { |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 243 | format_specs& fmt_specs = *this->specs(); |
| 244 | if (fmt_specs.type != 's') return base::operator()(value ? 1 : 0); |
| 245 | fmt_specs.type = 0; |
| Victor Zverovich | 479ee2a | 2018-07-04 13:17:03 -0700 | [diff] [blame] | 246 | this->write(value != 0); |
| Victor Zverovich | e928b67 | 2018-07-04 11:36:38 -0700 | [diff] [blame] | 247 | } else if (std::is_same<T, char_type>::value) { |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 248 | format_specs& fmt_specs = *this->specs(); |
| 249 | if (fmt_specs.type && fmt_specs.type != 'c') |
| Victor Zverovich | e928b67 | 2018-07-04 11:36:38 -0700 | [diff] [blame] | 250 | return (*this)(static_cast<int>(value)); |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 251 | fmt_specs.sign = sign::none; |
| 252 | fmt_specs.alt = false; |
| 253 | fmt_specs.align = align::right; |
| Victor Zverovich | e928b67 | 2018-07-04 11:36:38 -0700 | [diff] [blame] | 254 | return base::operator()(value); |
| 255 | } else { |
| 256 | return base::operator()(value); |
| 257 | } |
| Victor Zverovich | 3cf0526 | 2018-03-30 08:20:12 -1000 | [diff] [blame] | 258 | return this->out(); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 261 | template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)> |
| 262 | iterator operator()(T value) { |
| Victor Zverovich | 3cf0526 | 2018-03-30 08:20:12 -1000 | [diff] [blame] | 263 | return base::operator()(value); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 264 | } |
| 265 | |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 266 | /** Formats a null-terminated C string. */ |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 267 | iterator operator()(const char* value) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 268 | if (value) |
| Victor Zverovich | c095445 | 2018-01-06 09:09:50 -0800 | [diff] [blame] | 269 | base::operator()(value); |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 270 | else if (this->specs()->type == 'p') |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 271 | write_null_pointer(char_type()); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 272 | else |
| 273 | this->write("(null)"); |
| Victor Zverovich | 3cf0526 | 2018-03-30 08:20:12 -1000 | [diff] [blame] | 274 | return this->out(); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 277 | /** Formats a null-terminated wide C string. */ |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 278 | iterator operator()(const wchar_t* value) { |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 279 | if (value) |
| 280 | base::operator()(value); |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 281 | else if (this->specs()->type == 'p') |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 282 | write_null_pointer(char_type()); |
| 283 | else |
| 284 | this->write(L"(null)"); |
| 285 | return this->out(); |
| 286 | } |
| 287 | |
| Victor Zverovich | 479ee2a | 2018-07-04 13:17:03 -0700 | [diff] [blame] | 288 | iterator operator()(basic_string_view<char_type> value) { |
| 289 | return base::operator()(value); |
| 290 | } |
| 291 | |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 292 | iterator operator()(monostate value) { return base::operator()(value); } |
| Victor Zverovich | 479ee2a | 2018-07-04 13:17:03 -0700 | [diff] [blame] | 293 | |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 294 | /** Formats a pointer. */ |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 295 | iterator operator()(const void* value) { |
| 296 | if (value) return base::operator()(value); |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 297 | this->specs()->type = 0; |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 298 | write_null_pointer(char_type()); |
| Victor Zverovich | 3cf0526 | 2018-03-30 08:20:12 -1000 | [diff] [blame] | 299 | return this->out(); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 300 | } |
| 301 | |
| Victor Zverovich | 6ee9f2e | 2016-07-21 06:59:28 -0700 | [diff] [blame] | 302 | /** Formats an argument of a custom (user-defined) type. */ |
| Victor Zverovich | 23759b2 | 2018-04-04 07:38:21 -0700 | [diff] [blame] | 303 | iterator operator()(typename basic_format_arg<context_type>::handle handle) { |
| Victor Zverovich | 442fa1b | 2019-02-09 19:34:42 -0800 | [diff] [blame] | 304 | handle.format(context_.parse_context(), context_); |
| Victor Zverovich | 3cf0526 | 2018-03-30 08:20:12 -1000 | [diff] [blame] | 305 | return this->out(); |
| Victor Zverovich | 5e0562a | 2017-08-13 13:09:02 -0700 | [diff] [blame] | 306 | } |
| 307 | }; |
| 308 | |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 309 | template <typename T> struct printf_formatter { |
| Victor Zverovich | 8cbf544 | 2017-09-17 08:32:57 -0700 | [diff] [blame] | 310 | template <typename ParseContext> |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 311 | auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 312 | return ctx.begin(); |
| 313 | } |
| Victor Zverovich | 5e0562a | 2017-08-13 13:09:02 -0700 | [diff] [blame] | 314 | |
| Victor Zverovich | 91ee9c9 | 2018-01-14 11:00:27 -0800 | [diff] [blame] | 315 | template <typename FormatContext> |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 316 | auto format(const T& value, FormatContext& ctx) -> decltype(ctx.out()) { |
| Victor Zverovich | fa9066f | 2018-04-22 09:16:32 -0700 | [diff] [blame] | 317 | internal::format_value(internal::get_container(ctx.out()), value); |
| 318 | return ctx.out(); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 319 | } |
| 320 | }; |
| 321 | |
| Victor Zverovich | d4ddaaf | 2016-07-20 08:09:14 -0700 | [diff] [blame] | 322 | /** This template formats data and writes the output to a writer. */ |
| Victor Zverovich | 397e8dd | 2019-04-15 11:39:19 -0700 | [diff] [blame] | 323 | template <typename OutputIt, typename Char> class basic_printf_context { |
| Victor Zverovich | 18dfa25 | 2016-10-21 06:46:21 -0700 | [diff] [blame] | 324 | public: |
| 325 | /** The character type for the output. */ |
| Victor Zverovich | ec66510 | 2019-06-02 16:04:17 -0700 | [diff] [blame] | 326 | using char_type = Char; |
| 327 | using format_arg = basic_format_arg<basic_printf_context>; |
| 328 | template <typename T> using formatter_type = printf_formatter<T>; |
| Victor Zverovich | 18dfa25 | 2016-10-21 06:46:21 -0700 | [diff] [blame] | 329 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 330 | private: |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 331 | using format_specs = basic_format_specs<char_type>; |
| Victor Zverovich | dafbec7 | 2016-10-07 08:37:06 -0700 | [diff] [blame] | 332 | |
| Victor Zverovich | 442fa1b | 2019-02-09 19:34:42 -0800 | [diff] [blame] | 333 | OutputIt out_; |
| 334 | basic_format_args<basic_printf_context> args_; |
| 335 | basic_parse_context<Char> parse_ctx_; |
| 336 | |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 337 | static void parse_flags(format_specs& specs, const Char*& it, |
| 338 | const Char* end); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 339 | |
| 340 | // Returns the argument with specified index or, if arg_index is equal |
| 341 | // to the maximum unsigned value, the next argument. |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 342 | format_arg get_arg(unsigned arg_index = std::numeric_limits<unsigned>::max()); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 343 | |
| 344 | // Parses argument index, flags and width and returns the argument index. |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 345 | unsigned parse_header(const Char*& it, const Char* end, format_specs& specs); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 346 | |
| 347 | public: |
| Victor Zverovich | d4ddaaf | 2016-07-20 08:09:14 -0700 | [diff] [blame] | 348 | /** |
| 349 | \rst |
| Victor Zverovich | 9998f66 | 2016-11-06 16:11:24 -0800 | [diff] [blame] | 350 | Constructs a ``printf_context`` object. References to the arguments and |
| 351 | the writer are stored in the context object so make sure they have |
| Victor Zverovich | ab05453 | 2016-07-20 08:21:13 -0700 | [diff] [blame] | 352 | appropriate lifetimes. |
| Victor Zverovich | d4ddaaf | 2016-07-20 08:09:14 -0700 | [diff] [blame] | 353 | \endrst |
| 354 | */ |
| Victor Zverovich | bd8a7e7 | 2018-01-21 14:30:38 -0800 | [diff] [blame] | 355 | basic_printf_context(OutputIt out, basic_string_view<char_type> format_str, |
| Victor Zverovich | 217e7c7 | 2018-01-14 07:19:23 -0800 | [diff] [blame] | 356 | basic_format_args<basic_printf_context> args) |
| Victor Zverovich | 442fa1b | 2019-02-09 19:34:42 -0800 | [diff] [blame] | 357 | : out_(out), args_(args), parse_ctx_(format_str) {} |
| Victor Zverovich | 8cbf544 | 2017-09-17 08:32:57 -0700 | [diff] [blame] | 358 | |
| Victor Zverovich | 442fa1b | 2019-02-09 19:34:42 -0800 | [diff] [blame] | 359 | OutputIt out() { return out_; } |
| 360 | void advance_to(OutputIt it) { out_ = it; } |
| 361 | |
| 362 | format_arg arg(unsigned id) const { return args_.get(id); } |
| 363 | |
| 364 | basic_parse_context<Char>& parse_context() { return parse_ctx_; } |
| 365 | |
| 366 | FMT_CONSTEXPR void on_error(const char* message) { |
| 367 | parse_ctx_.on_error(message); |
| 368 | } |
| Victor Zverovich | 9998f66 | 2016-11-06 16:11:24 -0800 | [diff] [blame] | 369 | |
| Victor Zverovich | c095445 | 2018-01-06 09:09:50 -0800 | [diff] [blame] | 370 | /** Formats stored arguments and writes the output to the range. */ |
| Victor Zverovich | 3f75e2b | 2019-08-28 06:18:34 -0700 | [diff] [blame] | 371 | template <typename ArgFormatter = printf_arg_formatter<buffer_range<Char>>> |
| Daniela Engert | b0cde86 | 2019-01-01 11:45:56 +0100 | [diff] [blame] | 372 | OutputIt format(); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 373 | }; |
| 374 | |
| ToolsDevler | 2b415b7 | 2019-04-11 11:05:55 +0200 | [diff] [blame] | 375 | template <typename OutputIt, typename Char> |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 376 | void basic_printf_context<OutputIt, Char>::parse_flags(format_specs& specs, |
| Victor Zverovich | 397e8dd | 2019-04-15 11:39:19 -0700 | [diff] [blame] | 377 | const Char*& it, |
| 378 | const Char* end) { |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 379 | for (; it != end; ++it) { |
| 380 | switch (*it) { |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 381 | case '-': |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 382 | specs.align = align::left; |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 383 | break; |
| 384 | case '+': |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 385 | specs.sign = sign::plus; |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 386 | break; |
| 387 | case '0': |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 388 | specs.fill[0] = '0'; |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 389 | break; |
| 390 | case ' ': |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 391 | specs.sign = sign::space; |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 392 | break; |
| 393 | case '#': |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 394 | specs.alt = true; |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 395 | break; |
| 396 | default: |
| 397 | return; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| ToolsDevler | 2b415b7 | 2019-04-11 11:05:55 +0200 | [diff] [blame] | 402 | template <typename OutputIt, typename Char> |
| 403 | typename basic_printf_context<OutputIt, Char>::format_arg |
| 404 | basic_printf_context<OutputIt, Char>::get_arg(unsigned arg_index) { |
| Victor Zverovich | c523dd5 | 2017-11-19 07:36:01 -0800 | [diff] [blame] | 405 | if (arg_index == std::numeric_limits<unsigned>::max()) |
| Victor Zverovich | 442fa1b | 2019-02-09 19:34:42 -0800 | [diff] [blame] | 406 | arg_index = parse_ctx_.next_arg_id(); |
| 407 | else |
| 408 | parse_ctx_.check_arg_id(--arg_index); |
| 409 | return internal::get_arg(*this, arg_index); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 410 | } |
| 411 | |
| ToolsDevler | 2b415b7 | 2019-04-11 11:05:55 +0200 | [diff] [blame] | 412 | template <typename OutputIt, typename Char> |
| 413 | unsigned basic_printf_context<OutputIt, Char>::parse_header( |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 414 | const Char*& it, const Char* end, format_specs& specs) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 415 | unsigned arg_index = std::numeric_limits<unsigned>::max(); |
| Victor Zverovich | c095445 | 2018-01-06 09:09:50 -0800 | [diff] [blame] | 416 | char_type c = *it; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 417 | if (c >= '0' && c <= '9') { |
| 418 | // Parse an argument index (if followed by '$') or a width possibly |
| 419 | // preceded with '0' flag(s). |
| Victor Zverovich | 932ab2b | 2017-10-21 08:37:52 -0700 | [diff] [blame] | 420 | internal::error_handler eh; |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 421 | unsigned value = parse_nonnegative_int(it, end, eh); |
| 422 | if (it != end && *it == '$') { // value is an argument index |
| Victor Zverovich | 2f4f49f | 2017-07-18 19:40:48 -0700 | [diff] [blame] | 423 | ++it; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 424 | arg_index = value; |
| 425 | } else { |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 426 | if (c == '0') specs.fill[0] = '0'; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 427 | if (value != 0) { |
| 428 | // Nonzero value means that we parsed width and don't need to |
| 429 | // parse it or flags again, so return now. |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 430 | specs.width = value; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 431 | return arg_index; |
| 432 | } |
| 433 | } |
| 434 | } |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 435 | parse_flags(specs, it, end); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 436 | // Parse width. |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 437 | if (it != end) { |
| 438 | if (*it >= '0' && *it <= '9') { |
| 439 | internal::error_handler eh; |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 440 | specs.width = parse_nonnegative_int(it, end, eh); |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 441 | } else if (*it == '*') { |
| 442 | ++it; |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 443 | specs.width = visit_format_arg( |
| 444 | internal::printf_width_handler<char_type>(specs), get_arg()); |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 445 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 446 | } |
| 447 | return arg_index; |
| 448 | } |
| 449 | |
| ToolsDevler | 2b415b7 | 2019-04-11 11:05:55 +0200 | [diff] [blame] | 450 | template <typename OutputIt, typename Char> |
| 451 | template <typename ArgFormatter> |
| 452 | OutputIt basic_printf_context<OutputIt, Char>::format() { |
| Daniela Engert | b0cde86 | 2019-01-01 11:45:56 +0100 | [diff] [blame] | 453 | auto out = this->out(); |
| Victor Zverovich | 442fa1b | 2019-02-09 19:34:42 -0800 | [diff] [blame] | 454 | const Char* start = parse_ctx_.begin(); |
| 455 | const Char* end = parse_ctx_.end(); |
| Victor Zverovich | 2f4f49f | 2017-07-18 19:40:48 -0700 | [diff] [blame] | 456 | auto it = start; |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 457 | while (it != end) { |
| Victor Zverovich | c095445 | 2018-01-06 09:09:50 -0800 | [diff] [blame] | 458 | char_type c = *it++; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 459 | if (c != '%') continue; |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 460 | if (it != end && *it == c) { |
| Daniela Engert | b0cde86 | 2019-01-01 11:45:56 +0100 | [diff] [blame] | 461 | out = std::copy(start, it, out); |
| Victor Zverovich | 2f4f49f | 2017-07-18 19:40:48 -0700 | [diff] [blame] | 462 | start = ++it; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 463 | continue; |
| 464 | } |
| Daniela Engert | b0cde86 | 2019-01-01 11:45:56 +0100 | [diff] [blame] | 465 | out = std::copy(start, it - 1, out); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 466 | |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 467 | format_specs specs; |
| 468 | specs.align = align::right; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 469 | |
| 470 | // Parse argument index, flags and width. |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 471 | unsigned arg_index = parse_header(it, end, specs); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 472 | |
| 473 | // Parse precision. |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 474 | if (it != end && *it == '.') { |
| Victor Zverovich | 2f4f49f | 2017-07-18 19:40:48 -0700 | [diff] [blame] | 475 | ++it; |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 476 | c = it != end ? *it : 0; |
| 477 | if ('0' <= c && c <= '9') { |
| Victor Zverovich | 932ab2b | 2017-10-21 08:37:52 -0700 | [diff] [blame] | 478 | internal::error_handler eh; |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 479 | specs.precision = static_cast<int>(parse_nonnegative_int(it, end, eh)); |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 480 | } else if (c == '*') { |
| Victor Zverovich | 2f4f49f | 2017-07-18 19:40:48 -0700 | [diff] [blame] | 481 | ++it; |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 482 | specs.precision = |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 483 | visit_format_arg(internal::printf_precision_handler(), get_arg()); |
| Victor Zverovich | 5060568 | 2018-01-27 17:56:19 -0800 | [diff] [blame] | 484 | } else { |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 485 | specs.precision = 0; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 489 | format_arg arg = get_arg(arg_index); |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 490 | if (specs.alt && visit_format_arg(internal::is_zero_int(), arg)) |
| 491 | specs.alt = false; |
| 492 | if (specs.fill[0] == '0') { |
| Victor Zverovich | 7cea163 | 2017-12-09 06:19:15 -0800 | [diff] [blame] | 493 | if (arg.is_arithmetic()) |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 494 | specs.align = align::numeric; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 495 | else |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 496 | specs.fill[0] = ' '; // Ignore '0' flag for non-numeric types. |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | // Parse length and convert the argument to the required type. |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 500 | c = it != end ? *it++ : 0; |
| 501 | char_type t = it != end ? *it : 0; |
| Victor Zverovich | 751ff64 | 2016-11-19 08:40:24 -0800 | [diff] [blame] | 502 | using internal::convert_arg; |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 503 | switch (c) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 504 | case 'h': |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 505 | if (t == 'h') { |
| 506 | ++it; |
| 507 | t = it != end ? *it : 0; |
| 508 | convert_arg<signed char>(arg, t); |
| 509 | } else { |
| 510 | convert_arg<short>(arg, t); |
| 511 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 512 | break; |
| 513 | case 'l': |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 514 | if (t == 'l') { |
| 515 | ++it; |
| 516 | t = it != end ? *it : 0; |
| 517 | convert_arg<long long>(arg, t); |
| 518 | } else { |
| 519 | convert_arg<long>(arg, t); |
| 520 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 521 | break; |
| 522 | case 'j': |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 523 | convert_arg<intmax_t>(arg, t); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 524 | break; |
| 525 | case 'z': |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 526 | convert_arg<std::size_t>(arg, t); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 527 | break; |
| 528 | case 't': |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 529 | convert_arg<std::ptrdiff_t>(arg, t); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 530 | break; |
| 531 | case 'L': |
| 532 | // printf produces garbage when 'L' is omitted for long double, no |
| 533 | // need to do the same. |
| 534 | break; |
| 535 | default: |
| Victor Zverovich | 2f4f49f | 2017-07-18 19:40:48 -0700 | [diff] [blame] | 536 | --it; |
| Daniela Engert | f5cc77c | 2018-12-31 16:21:45 +0100 | [diff] [blame] | 537 | convert_arg<void>(arg, c); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | // Parse type. |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 541 | if (it == end) FMT_THROW(format_error("invalid format string")); |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 542 | specs.type = static_cast<char>(*it++); |
| Victor Zverovich | 0854f8c | 2016-12-11 13:22:45 -0800 | [diff] [blame] | 543 | if (arg.is_integral()) { |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 544 | // Normalize type. |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 545 | switch (specs.type) { |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 546 | case 'i': |
| 547 | case 'u': |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 548 | specs.type = 'd'; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 549 | break; |
| 550 | case 'c': |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 551 | visit_format_arg(internal::char_converter<basic_printf_context>(arg), |
| 552 | arg); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 553 | break; |
| 554 | } |
| 555 | } |
| 556 | |
| Victor Zverovich | 2f4f49f | 2017-07-18 19:40:48 -0700 | [diff] [blame] | 557 | start = it; |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 558 | |
| 559 | // Format argument. |
| Victor Zverovich | 5488d0b | 2019-07-07 06:39:20 -0700 | [diff] [blame] | 560 | visit_format_arg(ArgFormatter(out, specs, *this), arg); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 561 | } |
| Daniela Engert | b0cde86 | 2019-01-01 11:45:56 +0100 | [diff] [blame] | 562 | return std::copy(start, it, out); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 563 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 564 | |
| Victor Zverovich | dd8cc8b | 2019-07-09 11:50:16 -0700 | [diff] [blame] | 565 | template <typename Char> |
| 566 | using basic_printf_context_t = |
| 567 | basic_printf_context<std::back_insert_iterator<internal::buffer<Char>>, |
| 568 | Char>; |
| Victor Zverovich | 217e7c7 | 2018-01-14 07:19:23 -0800 | [diff] [blame] | 569 | |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 570 | using printf_context = basic_printf_context_t<char>; |
| 571 | using wprintf_context = basic_printf_context_t<wchar_t>; |
| tnovotny | e37d6a9 | 2018-11-22 22:57:07 +0100 | [diff] [blame] | 572 | |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 573 | using printf_args = basic_format_args<printf_context>; |
| 574 | using wprintf_args = basic_format_args<wprintf_context>; |
| tnovotny | e37d6a9 | 2018-11-22 22:57:07 +0100 | [diff] [blame] | 575 | |
| 576 | /** |
| 577 | \rst |
| 578 | Constructs an `~fmt::format_arg_store` object that contains references to |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 579 | arguments and can be implicitly converted to `~fmt::printf_args`. |
| tnovotny | e37d6a9 | 2018-11-22 22:57:07 +0100 | [diff] [blame] | 580 | \endrst |
| 581 | */ |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 582 | template <typename... Args> |
| 583 | inline format_arg_store<printf_context, Args...> make_printf_args( |
| 584 | const Args&... args) { |
| 585 | return {args...}; |
| 586 | } |
| tnovotny | e37d6a9 | 2018-11-22 22:57:07 +0100 | [diff] [blame] | 587 | |
| 588 | /** |
| 589 | \rst |
| 590 | Constructs an `~fmt::format_arg_store` object that contains references to |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 591 | arguments and can be implicitly converted to `~fmt::wprintf_args`. |
| tnovotny | e37d6a9 | 2018-11-22 22:57:07 +0100 | [diff] [blame] | 592 | \endrst |
| 593 | */ |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 594 | template <typename... Args> |
| 595 | inline format_arg_store<wprintf_context, Args...> make_wprintf_args( |
| 596 | const Args&... args) { |
| 597 | return {args...}; |
| 598 | } |
| Victor Zverovich | 0854f8c | 2016-12-11 13:22:45 -0800 | [diff] [blame] | 599 | |
| Victor Zverovich | 4d4b8c2 | 2019-06-01 12:32:24 -0700 | [diff] [blame] | 600 | template <typename S, typename Char = char_t<S>> |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 601 | inline std::basic_string<Char> vsprintf( |
| Victor Zverovich | dd8cc8b | 2019-07-09 11:50:16 -0700 | [diff] [blame] | 602 | const S& format, basic_format_args<basic_printf_context_t<Char>> args) { |
| Daniela Engert | f27defc | 2018-10-07 14:38:29 +0200 | [diff] [blame] | 603 | basic_memory_buffer<Char> buffer; |
| Victor Zverovich | 0a96c03 | 2018-10-25 07:20:02 -0700 | [diff] [blame] | 604 | printf(buffer, to_string_view(format), args); |
| Victor Zverovich | fefaf07 | 2017-02-14 16:29:47 -0500 | [diff] [blame] | 605 | return to_string(buffer); |
| Victor Zverovich | 0028ce5 | 2016-08-26 17:23:13 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 608 | /** |
| 609 | \rst |
| 610 | Formats arguments and returns the result as a string. |
| 611 | |
| 612 | **Example**:: |
| 613 | |
| 614 | std::string message = fmt::sprintf("The answer is %d", 42); |
| 615 | \endrst |
| 616 | */ |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 617 | template <typename S, typename... Args, |
| Victor Zverovich | 4d4b8c2 | 2019-06-01 12:32:24 -0700 | [diff] [blame] | 618 | typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>> |
| 619 | inline std::basic_string<Char> sprintf(const S& format, const Args&... args) { |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 620 | using context = basic_printf_context_t<Char>; |
| 621 | return vsprintf(to_string_view(format), {make_format_args<context>(args...)}); |
| Victor Zverovich | 0028ce5 | 2016-08-26 17:23:13 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| Victor Zverovich | 4d4b8c2 | 2019-06-01 12:32:24 -0700 | [diff] [blame] | 624 | template <typename S, typename Char = char_t<S>> |
| Victor Zverovich | dd8cc8b | 2019-07-09 11:50:16 -0700 | [diff] [blame] | 625 | inline int vfprintf(std::FILE* f, const S& format, |
| 626 | basic_format_args<basic_printf_context_t<Char>> args) { |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 627 | basic_memory_buffer<Char> buffer; |
| Victor Zverovich | 0a96c03 | 2018-10-25 07:20:02 -0700 | [diff] [blame] | 628 | printf(buffer, to_string_view(format), args); |
| Victor Zverovich | 955062d | 2017-12-17 08:36:19 -0800 | [diff] [blame] | 629 | std::size_t size = buffer.size(); |
| Victor Zverovich | 58b6f8d | 2019-01-12 18:27:38 -0800 | [diff] [blame] | 630 | return std::fwrite(buffer.data(), sizeof(Char), size, f) < size |
| 631 | ? -1 |
| 632 | : static_cast<int>(size); |
| Victor Zverovich | 955062d | 2017-12-17 08:36:19 -0800 | [diff] [blame] | 633 | } |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 634 | |
| 635 | /** |
| 636 | \rst |
| 637 | Prints formatted data to the file *f*. |
| 638 | |
| 639 | **Example**:: |
| 640 | |
| 641 | fmt::fprintf(stderr, "Don't %s!", "panic"); |
| 642 | \endrst |
| 643 | */ |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 644 | template <typename S, typename... Args, |
| Victor Zverovich | 4d4b8c2 | 2019-06-01 12:32:24 -0700 | [diff] [blame] | 645 | typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>> |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 646 | inline int fprintf(std::FILE* f, const S& format, const Args&... args) { |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 647 | using context = basic_printf_context_t<Char>; |
| 648 | return vfprintf(f, to_string_view(format), |
| 649 | {make_format_args<context>(args...)}); |
| Victor Zverovich | 0028ce5 | 2016-08-26 17:23:13 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| Victor Zverovich | 4d4b8c2 | 2019-06-01 12:32:24 -0700 | [diff] [blame] | 652 | template <typename S, typename Char = char_t<S>> |
| Victor Zverovich | dd8cc8b | 2019-07-09 11:50:16 -0700 | [diff] [blame] | 653 | inline int vprintf(const S& format, |
| 654 | basic_format_args<basic_printf_context_t<Char>> args) { |
| Victor Zverovich | 0a96c03 | 2018-10-25 07:20:02 -0700 | [diff] [blame] | 655 | return vfprintf(stdout, to_string_view(format), args); |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 656 | } |
| 657 | |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 658 | /** |
| 659 | \rst |
| 660 | Prints formatted data to ``stdout``. |
| 661 | |
| 662 | **Example**:: |
| 663 | |
| 664 | fmt::printf("Elapsed time: %.2f seconds", 1.23); |
| 665 | \endrst |
| 666 | */ |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 667 | template <typename S, typename... Args, |
| 668 | FMT_ENABLE_IF(internal::is_string<S>::value)> |
| 669 | inline int printf(const S& format_str, const Args&... args) { |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 670 | using context = basic_printf_context_t<char_t<S>>; |
| 671 | return vprintf(to_string_view(format_str), |
| 672 | {make_format_args<context>(args...)}); |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 673 | } |
| Victor Zverovich | 0028ce5 | 2016-08-26 17:23:13 -0700 | [diff] [blame] | 674 | |
| Victor Zverovich | 4d4b8c2 | 2019-06-01 12:32:24 -0700 | [diff] [blame] | 675 | template <typename S, typename Char = char_t<S>> |
| Victor Zverovich | dd8cc8b | 2019-07-09 11:50:16 -0700 | [diff] [blame] | 676 | inline int vfprintf(std::basic_ostream<Char>& os, const S& format, |
| 677 | basic_format_args<basic_printf_context_t<Char>> args) { |
| Daniela Engert | f27defc | 2018-10-07 14:38:29 +0200 | [diff] [blame] | 678 | basic_memory_buffer<Char> buffer; |
| Victor Zverovich | 0a96c03 | 2018-10-25 07:20:02 -0700 | [diff] [blame] | 679 | printf(buffer, to_string_view(format), args); |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 680 | internal::write(os, buffer); |
| 681 | return static_cast<int>(buffer.size()); |
| 682 | } |
| 683 | |
| ToolsDevler | 2b415b7 | 2019-04-11 11:05:55 +0200 | [diff] [blame] | 684 | /** Formats arguments and writes the output to the range. */ |
| 685 | template <typename ArgFormatter, typename Char, |
| Victor Zverovich | 397e8dd | 2019-04-15 11:39:19 -0700 | [diff] [blame] | 686 | typename Context = |
| 687 | basic_printf_context<typename ArgFormatter::iterator, Char>> |
| ToolsDevler | 2b415b7 | 2019-04-11 11:05:55 +0200 | [diff] [blame] | 688 | typename ArgFormatter::iterator vprintf(internal::buffer<Char>& out, |
| 689 | basic_string_view<Char> format_str, |
| 690 | basic_format_args<Context> args) { |
| 691 | typename ArgFormatter::iterator iter(out); |
| 692 | Context(iter, format_str, args).template format<ArgFormatter>(); |
| 693 | return iter; |
| 694 | } |
| 695 | |
| Victor Zverovich | 9dbb60c | 2016-08-03 08:52:05 -0700 | [diff] [blame] | 696 | /** |
| 697 | \rst |
| 698 | Prints formatted data to the stream *os*. |
| 699 | |
| 700 | **Example**:: |
| 701 | |
| Victor Zverovich | 4023291 | 2018-03-04 09:55:17 -0800 | [diff] [blame] | 702 | fmt::fprintf(cerr, "Don't %s!", "panic"); |
| Victor Zverovich | 9dbb60c | 2016-08-03 08:52:05 -0700 | [diff] [blame] | 703 | \endrst |
| 704 | */ |
| Victor Zverovich | 4d4b8c2 | 2019-06-01 12:32:24 -0700 | [diff] [blame] | 705 | template <typename S, typename... Args, typename Char = char_t<S>> |
| 706 | inline int fprintf(std::basic_ostream<Char>& os, const S& format_str, |
| Victor Zverovich | c21c6b8 | 2019-03-16 12:58:18 -0700 | [diff] [blame] | 707 | const Args&... args) { |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 708 | using context = basic_printf_context_t<Char>; |
| Daniela Engert | 2c81c85 | 2018-10-08 20:14:39 +0200 | [diff] [blame] | 709 | return vfprintf(os, to_string_view(format_str), |
| Victor Zverovich | f6f0415 | 2019-07-07 16:43:38 -0700 | [diff] [blame] | 710 | {make_format_args<context>(args...)}); |
| Daniela Engert | 2570f1a | 2018-04-26 20:32:14 +0200 | [diff] [blame] | 711 | } |
| Victor Zverovich | 838400d | 2018-05-12 08:33:51 -0700 | [diff] [blame] | 712 | FMT_END_NAMESPACE |
| Glen Stark | 72d51e0 | 2016-06-08 01:23:32 +0200 | [diff] [blame] | 713 | |
| 714 | #endif // FMT_PRINTF_H_ |