30 static_assert(std::is_same<Char, char>::value ||
31 std::is_same<Char, wchar_t>::value,
32 "Unsupported code unit type.");
44 : out_(out), args_(args) {}
59template <
bool IS_CONSTEXPR,
typename T,
typename Ptr = const T*>
61 for (out =
first; out != last; ++out) {
62 if (*out ==
value)
return true;
69 const char*& out) ->
bool {
72 return out !=
nullptr;
87 return value >= (std::numeric_limits<int>::min)() &&
94 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
98 return (std::max)(
static_cast<int>(
value), 0);
101 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
110 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
115 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
129 using char_type =
typename Context::char_type;
139 if (type_ !=
's') operator()<
bool>(
value);
142 template <
typename U, FMT_ENABLE_IF(std::is_
integral<U>::value)>
144 bool is_signed = type_ ==
'd' || type_ ==
'i';
146 if (
const_check(
sizeof(target_type) <=
sizeof(
int))) {
150 arg_ =
static_cast<int>(
static_cast<target_type
>(
value));
152 arg_ =
static_cast<unsigned>(
static_cast<unsigned_type
>(
value));
158 arg_ =
static_cast<long long>(
value);
164 template <
typename U, FMT_ENABLE_IF(!std::is_
integral<U>::value)>
172template <
typename T,
typename Context,
typename Char>
185 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
187 arg_ =
static_cast<typename Context::char_type
>(
value);
190 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
197 template <
typename T>
auto operator()(T) ->
const Char* {
return nullptr; }
210 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
219 return static_cast<unsigned>(
width);
222 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
231template <
typename Char>
238template <
typename Char>
246 void write_null_pointer(
bool is_string =
false) {
247 auto s = this->
specs;
252 template <
typename T>
void write(T
value) {
263 template <
typename T, FMT_ENABLE_IF(detail::is_
integral<T>::value)>
267 if (!std::is_same<T, Char>::value) {
274 return (*
this)(
static_cast<int>(
value));
286 template <
typename T, FMT_ENABLE_IF(std::is_
floating_po
int<T>::value)>
311 write_null_pointer();
316 handle.
format(parse_ctx, context_);
320template <
typename Char>
322 for (; it != end; ++it) {
326 case '0': specs.
set_fill(
'0');
break;
330 case '#': specs.
set_alt();
break;
336template <
typename Char,
typename GetArg>
341 if (c >=
'0' && c <=
'9') {
345 if (it != end && *it ==
'$') {
349 if (c ==
'0') specs.set_fill(
'0');
362 if (*it >=
'0' && *it <=
'9') {
364 if (specs.width == -1)
report_error(
"number is too big");
365 }
else if (*it ==
'*') {
367 specs.width =
static_cast<int>(
379 case 'd':
return in(t, integral_set) ? pt::dec : pt::none;
380 case 'o':
return in(t, integral_set) ? pt::oct : pt::none;
382 case 'x':
return in(t, integral_set) ? pt::hex : pt::none;
384 case 'e':
return in(t,
float_set) ? pt::exp : pt::none;
386 case 'f':
return in(t,
float_set) ? pt::fixed : pt::none;
388 case 'g':
return in(t,
float_set) ? pt::general : pt::none;
390 case 'a':
return in(t,
float_set) ? pt::hexfloat : pt::none;
391 case 'c':
return in(t, integral_set) ? pt::chr : pt::none;
394 default:
return pt::none;
398template <
typename Char,
typename Context>
402 auto out = iterator(buf);
408 auto get_arg = [&](
int arg_index) {
410 arg_index = parse_ctx.next_arg_id();
412 parse_ctx.check_arg_id(--arg_index);
416 const Char*
start = parse_ctx.begin();
417 const Char* end = parse_ctx.end();
425 if (it != end && *it == c) {
440 if (it != end && *it ==
'.') {
442 c = it != end ? *it : 0;
443 if (
'0' <= c && c <=
'9') {
445 }
else if (c ==
'*') {
463 auto str_end = str + specs.precision;
464 auto nul = std::find(str, str_end, Char());
466 str,
to_unsigned(nul != str_end ? nul - str : specs.precision));
470 if (specs.fill_unit<Char>() ==
'0') {
480 c = it != end ? *it++ : 0;
481 Char t = it != end ? *it : 0;
486 t = it != end ? *it : 0;
495 t = it != end ? *it : 0;
513 char type =
static_cast<char>(*it++);
518 case 'u':
type =
'd';
break;
528 if (upper) specs.set_upper();
547template <
typename Char = char,
typename... T>
549 ->
decltype(fmt::make_format_args<basic_printf_context<Char>>(args...)) {
550 return fmt::make_format_args<basic_printf_context<Char>>(args...);
557template <
typename Char>
560 -> std::basic_string<Char> {
563 return {buf.data(), buf.size()};
575inline auto sprintf(
const S& fmt,
const T&... args) -> std::basic_string<Char> {
580template <
typename Char>
585 size_t size = buf.size();
586 return std::fwrite(buf.data(),
sizeof(Char), size, f) < size
588 :
static_cast<int>(size);
600inline auto fprintf(std::FILE* f,
const S& fmt,
const T&... args) ->
int {
605template <
typename Char>
620template <
typename... T>
624template <
typename... T>
626 const T&... args) ->
int {
A dynamically growing memory buffer for trivially copyable/constructible types with the first SIZE el...
Definition format.h:790
void advance_to(basic_appender< Char >)
Definition printf.h:47
auto locale() -> detail::locale_ref
Definition printf.h:49
Char char_type
Definition printf.h:35
auto out() -> basic_appender< Char >
Definition printf.h:46
auto arg(int id) const -> basic_format_arg< basic_printf_context >
Definition printf.h:51
basic_printf_context(basic_appender< Char > out, basic_format_args< basic_printf_context > args)
Constructs a printf_context object.
Definition printf.h:42
@ builtin_types
Definition printf.h:38
FMT_CONSTEXPR void set_fill(char c)
Definition base.h:811
constexpr auto align() const -> align
Definition base.h:745
constexpr auto sign() const -> sign
Definition base.h:772
FMT_CONSTEXPR void set_alt()
Definition base.h:783
FMT_CONSTEXPR void set_sign(fmt::sign s)
Definition base.h:775
FMT_CONSTEXPR void clear_alt()
Definition base.h:784
constexpr auto type() const -> presentation_type
Definition base.h:738
FMT_CONSTEXPR void set_align(fmt::align a)
Definition base.h:748
FMT_CONSTEXPR void set_type(presentation_type t)
Definition base.h:741
An implementation of std::basic_string_view for pre-C++17.
Definition base.h:504
arg_converter(basic_format_arg< Context > &arg, char_type type)
Definition printf.h:135
void operator()(U)
Definition printf.h:165
void operator()(U value)
Definition printf.h:143
void operator()(bool value)
Definition printf.h:138
A contiguous memory buffer with an optional growing ability.
Definition base.h:1698
char_converter(basic_format_arg< Context > &arg)
Definition printf.h:183
void operator()(T)
Definition printf.h:191
void operator()(T value)
Definition printf.h:186
printf_width_handler(format_specs &specs)
Definition printf.h:208
auto operator()(T) -> unsigned
Definition printf.h:223
auto operator()(T value) -> unsigned
Definition printf.h:211
detail namespace with internal helper functions
Definition input_adapters.h:32
conditional_t< num_bits< T >()<=32 &&!FMT_REDUCE_INT_INSTANTIATIONS, uint32_t, conditional_t< num_bits< T >()<=64, uint64_t, uint128_t > > uint32_or_64_or_128_t
Definition format.h:994
auto first(const T &value, const Tail &...) -> const T &
Definition compile.h:55
void convert_arg(basic_format_arg< Context > &arg, Char type)
Definition printf.h:173
void vprintf(buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
Definition printf.h:399
auto make_arg_formatter(basic_appender< Char > iter, format_specs &s) -> arg_formatter< Char >
Definition printf.h:232
constexpr auto is_integral_type(type t) -> bool
Definition base.h:984
FMT_CONSTEXPR auto write(OutputIt out, Char value, const format_specs &specs, locale_ref loc={}) -> OutputIt
Definition format.h:1824
FMT_CONSTEXPR auto parse_nonnegative_int(const Char *&begin, const Char *end, int error_value) noexcept -> int
Definition base.h:1257
FMT_CONSTEXPR auto get_arg(Context &ctx, ID id) -> basic_format_arg< Context >
Definition format.h:3527
FMT_CONSTEXPR auto write_bytes(OutputIt out, string_view bytes, const format_specs &specs={}) -> OutputIt
Definition format.h:1670
void parse_flags(format_specs &specs, const Char *&it, const Char *end)
Definition printf.h:321
constexpr auto max_value() -> T
Definition format.h:407
@ value
the parser finished reading a JSON value
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t< Int >
Definition base.h:422
constexpr auto in(type t, int set) -> bool
Definition base.h:992
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition printf.h:60
@ bool_set
Definition base.h:1002
@ uint_set
Definition base.h:1000
@ pointer_set
Definition base.h:1008
@ float_set
Definition base.h:1004
@ cstring_set
Definition base.h:1007
@ char_set
Definition base.h:1003
@ sint_set
Definition base.h:998
@ string_set
Definition base.h:1006
constexpr auto is_arithmetic_type(type t) -> bool
Definition base.h:987
FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T
Definition base.h:367
std::integral_constant< bool, std::numeric_limits< T >::is_signed|| std::is_same< T, int128_opt >::value > is_signed
Definition format.h:708
auto parse_printf_presentation_type(char c, type t, bool &upper) -> presentation_type
Definition printf.h:374
typename V::value_type char_t
String's character (code unit) type. detail:: is intentional to prevent ADL.
Definition base.h:935
constexpr auto to_string_view(const Char *s) -> basic_string_view< Char >
Definition base.h:910
constexpr auto is_negative(T value) -> bool
Definition format.h:983
type
Definition base.h:937
auto parse_header(const Char *&it, const Char *end, format_specs &specs, GetArg get_arg) -> int
Definition printf.h:337
auto find< false, char >(const char *first, const char *last, char value, const char *&out) -> bool
Definition printf.h:68
auto make_printf_args(T &... args) -> decltype(fmt::make_format_args< basic_printf_context< Char > >(args...))
Constructs an format_arg_store object that contains references to arguments and can be implicitly con...
Definition printf.h:548
auto vsprintf(basic_string_view< Char > fmt, typename vprintf_args< Char >::type args) -> std::basic_string< Char >
Definition printf.h:558
auto fprintf(std::FILE *f, const S &fmt, const T &... args) -> int
Formats args according to specifications in fmt and writes the output to f.
Definition printf.h:600
auto sprintf(const S &fmt, const T &... args) -> std::basic_string< Char >
Formats args according to specifications in fmt and returns the result as as string.
Definition printf.h:575
auto vfprintf(std::FILE *f, basic_string_view< Char > fmt, typename vprintf_args< Char >::type args) -> int
Definition printf.h:581
FMT_DEPRECATED auto vprintf(basic_string_view< Char > fmt, typename vprintf_args< Char >::type args) -> int
Definition printf.h:606
auto printf(string_view fmt, const T &... args) -> int
Formats args according to specifications in fmt and writes the output to stdout.
Definition printf.h:621
auto operator()(T) -> const Char *
Definition printf.h:197
auto operator()(const Char *s) -> const Char *
Definition printf.h:198
static auto fits_in_int(int) -> bool
Definition printf.h:90
static auto fits_in_int(T value) -> bool
Definition printf.h:86
static auto fits_in_int(T value) -> bool
Definition printf.h:78
static auto fits_in_int(bool) -> bool
Definition printf.h:82
auto operator()(T value) -> bool
Definition printf.h:111
auto operator()(T) -> bool
Definition printf.h:116
Definition format-inl.h:92
bool type
Definition printf.h:124
auto operator()(T) -> int
Definition printf.h:102
auto operator()(T value) -> int
Definition printf.h:95
#define S(label, offset, message)
Definition Errors.h:113
#define FMT_END_EXPORT
Definition base.h:250
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Returns a named argument to be used in a formatting function.
Definition base.h:2775
#define FMT_FALLTHROUGH
Definition base.h:172
#define FMT_CONSTEXPR
Definition base.h:113
#define FMT_BEGIN_NAMESPACE
Definition base.h:239
#define FMT_BEGIN_EXPORT
Definition base.h:249
std::is_constructible< formatter< T, Char > > FMT_DEPRECATED
Definition base.h:2732
typename std::conditional< B, T, F >::type conditional_t
Definition base.h:299
presentation_type
Definition base.h:661
#define FMT_END_NAMESPACE
Definition base.h:242