26 static_assert(std::is_same<Char, char>::value ||
27 std::is_same<Char, wchar_t>::value,
28 "Unsupported code unit type.");
38 : out_(out), args_(args) {}
53template <
bool IS_CONSTEXPR,
typename T,
typename Ptr = const T*>
55 for (out =
first; out != last; ++out) {
56 if (*out ==
value)
return true;
63 const char*& out) ->
bool {
66 return out !=
nullptr;
73 return value <= to_unsigned(max_value<int>());
80 return value >= (std::numeric_limits<int>::min)() &&
81 value <= max_value<int>();
87 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
94 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
103 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
108 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
122 using char_type =
typename Context::char_type;
132 if (type_ !=
's') operator()<
bool>(
value);
135 template <
typename U, FMT_ENABLE_IF(std::is_
integral<U>::value)>
137 bool is_signed = type_ ==
'd' || type_ ==
'i';
139 if (
const_check(
sizeof(target_type) <=
sizeof(
int))) {
143 arg_ =
static_cast<int>(
static_cast<target_type
>(
value));
145 arg_ =
static_cast<unsigned>(
static_cast<unsigned_type
>(
value));
151 arg_ =
static_cast<long long>(
value);
157 template <
typename U, FMT_ENABLE_IF(!std::is_
integral<U>::value)>
165template <
typename T,
typename Context,
typename Char>
178 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
180 arg_ =
static_cast<typename Context::char_type
>(
value);
183 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
190 template <
typename T>
auto operator()(T) ->
const Char* {
return nullptr; }
203 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
212 return static_cast<unsigned>(
width);
215 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
224template <
typename Char>
231template <
typename Char>
239 void write_null_pointer(
bool is_string =
false) {
240 auto s = this->
specs;
245 template <
typename T>
void write(T
value) {
256 template <
typename T, FMT_ENABLE_IF(detail::is_
integral<T>::value)>
260 if (!std::is_same<T, Char>::value) {
267 return (*
this)(
static_cast<int>(
value));
279 template <
typename T, FMT_ENABLE_IF(std::is_
floating_po
int<T>::value)>
304 write_null_pointer();
309 handle.
format(parse_ctx, context_);
313template <
typename Char>
315 for (; it != end; ++it) {
319 case '0': specs.
set_fill(
'0');
break;
323 case '#': specs.
set_alt();
break;
329template <
typename Char,
typename GetArg>
331 GetArg get_arg) ->
int {
334 if (c >=
'0' && c <=
'9') {
338 if (it != end && *it ==
'$') {
342 if (c ==
'0') specs.set_fill(
'0');
355 if (*it >=
'0' && *it <=
'9') {
357 if (specs.width == -1)
report_error(
"number is too big");
358 }
else if (*it ==
'*') {
360 specs.width =
static_cast<int>(
372 case 'd':
return in(t, integral_set) ? pt::dec : pt::none;
373 case 'o':
return in(t, integral_set) ? pt::oct : pt::none;
375 case 'x':
return in(t, integral_set) ? pt::hex : pt::none;
377 case 'e':
return in(t,
float_set) ? pt::exp : pt::none;
379 case 'f':
return in(t,
float_set) ? pt::fixed : pt::none;
381 case 'g':
return in(t,
float_set) ? pt::general : pt::none;
383 case 'a':
return in(t,
float_set) ? pt::hexfloat : pt::none;
384 case 'c':
return in(t, integral_set) ? pt::chr : pt::none;
387 default:
return pt::none;
391template <
typename Char,
typename Context>
395 auto out = iterator(buf);
401 auto get_arg = [&](
int arg_index) {
403 arg_index = parse_ctx.next_arg_id();
405 parse_ctx.check_arg_id(--arg_index);
411 const Char*
start = parse_ctx.begin();
412 const Char* end = parse_ctx.end();
420 if (it != end && *it == c) {
435 if (it != end && *it ==
'.') {
437 c = it != end ? *it : 0;
438 if (
'0' <= c && c <=
'9') {
440 }
else if (c ==
'*') {
449 auto arg = get_arg(arg_index);
458 auto str_end = str + specs.precision;
459 auto nul = std::find(str, str_end, Char());
461 str,
to_unsigned(nul != str_end ? nul - str : specs.precision));
465 if (specs.fill_unit<Char>() ==
'0') {
475 c = it != end ? *it++ : 0;
476 Char t = it != end ? *it : 0;
481 t = it != end ? *it : 0;
490 t = it != end ? *it : 0;
508 char type =
static_cast<char>(*it++);
513 case 'u':
type =
'd';
break;
523 if (upper) specs.set_upper();
542template <
typename Char = char,
typename... T>
544 ->
decltype(fmt::make_format_args<basic_printf_context<Char>>(args...)) {
545 return fmt::make_format_args<basic_printf_context<Char>>(args...);
552template <
typename Char>
555 -> std::basic_string<Char> {
558 return {buf.data(), buf.size()};
569template <
typename... T>
573template <
typename... T>
579template <
typename Char>
584 size_t size = buf.size();
585 return std::fwrite(buf.data(),
sizeof(Char), size, f) < size
587 :
static_cast<int>(size);
598template <
typename... T>
602template <
typename... T>
604 const T&... args) ->
int {
616template <
typename... T>
#define FMT_END_EXPORT
Definition base.h:264
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:2831
#define FMT_FALLTHROUGH
Definition base.h:186
constexpr auto max_of(T a, T b) -> T
Definition base.h:347
#define FMT_CONSTEXPR
Definition base.h:113
#define FMT_BEGIN_NAMESPACE
Definition base.h:253
#define FMT_BEGIN_EXPORT
Definition base.h:263
typename std::conditional< B, T, F >::type conditional_t
Definition base.h:306
presentation_type
Definition base.h:658
#define FMT_END_NAMESPACE
Definition base.h:256
A dynamically growing memory buffer for trivially copyable/constructible types with the first SIZE el...
Definition format.h:785
void advance_to(basic_appender< Char >)
Definition printf.h:41
Char char_type
Definition printf.h:31
@ builtin_types
Definition printf.h:32
auto out() -> basic_appender< Char >
Definition printf.h:40
auto arg(int id) const -> basic_format_arg< basic_printf_context >
Definition printf.h:45
auto locale() -> locale_ref
Definition printf.h:43
basic_printf_context(basic_appender< Char > out, basic_format_args< basic_printf_context > args)
Constructs a printf_context object.
Definition printf.h:36
FMT_CONSTEXPR void set_fill(char c)
Definition base.h:810
constexpr auto align() const -> align
Definition base.h:744
constexpr auto sign() const -> sign
Definition base.h:771
FMT_CONSTEXPR void set_alt()
Definition base.h:782
FMT_CONSTEXPR void set_sign(fmt::sign s)
Definition base.h:774
FMT_CONSTEXPR void clear_alt()
Definition base.h:783
constexpr auto type() const -> presentation_type
Definition base.h:737
FMT_CONSTEXPR void set_align(fmt::align a)
Definition base.h:747
FMT_CONSTEXPR void set_type(presentation_type t)
Definition base.h:740
An implementation of std::basic_string_view for pre-C++17.
Definition base.h:515
FMT_CONSTEXPR auto arg(int id) const -> format_arg
Definition base.h:2688
arg_converter(basic_format_arg< Context > &arg, char_type type)
Definition printf.h:128
void operator()(U)
Definition printf.h:158
void operator()(U value)
Definition printf.h:136
void operator()(bool value)
Definition printf.h:131
A contiguous memory buffer with an optional growing ability.
Definition base.h:1763
char_converter(basic_format_arg< Context > &arg)
Definition printf.h:176
void operator()(T)
Definition printf.h:184
void operator()(T value)
Definition printf.h:179
printf_width_handler(format_specs &specs)
Definition printf.h:201
auto operator()(T) -> unsigned
Definition printf.h:216
auto operator()(T value) -> unsigned
Definition printf.h:204
Parsing context consisting of a format string range being parsed and an argument counter for automati...
Definition base.h:850
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
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:1010
void convert_arg(basic_format_arg< Context > &arg, Char type)
Definition printf.h:166
void vprintf(buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
Definition printf.h:392
auto make_arg_formatter(basic_appender< Char > iter, format_specs &s) -> arg_formatter< Char >
Definition printf.h:225
constexpr auto is_integral_type(type t) -> bool
Definition base.h:1022
FMT_CONSTEXPR auto parse_nonnegative_int(const Char *&begin, const Char *end, int error_value) noexcept -> int
Definition base.h:1312
FMT_CONSTEXPR auto write_bytes(OutputIt out, string_view bytes, const format_specs &specs={}) -> OutputIt
Definition format.h:1702
void parse_flags(format_specs &specs, const Char *&it, const Char *end)
Definition printf.h:314
constexpr auto max_value() -> T
Definition format.h:423
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t< Int >
Definition base.h:432
constexpr auto in(type t, int set) -> bool
Definition base.h:1030
constexpr auto first(const T &value, const Tail &...) -> const T &
Definition compile.h:65
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition printf.h:54
constexpr auto is_arithmetic_type(type t) -> bool
Definition base.h:1025
FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T
Definition base.h:377
std::integral_constant< bool, std::numeric_limits< T >::is_signed|| std::is_same< T, int128_opt >::value > is_signed
Definition format.h:693
auto parse_printf_presentation_type(char c, type t, bool &upper) -> presentation_type
Definition printf.h:367
@ bool_set
Definition base.h:1040
@ uint_set
Definition base.h:1038
@ pointer_set
Definition base.h:1046
@ float_set
Definition base.h:1042
@ cstring_set
Definition base.h:1045
@ char_set
Definition base.h:1041
@ sint_set
Definition base.h:1036
@ string_set
Definition base.h:1044
constexpr auto is_negative(T value) -> bool
Definition format.h:999
FMT_CONSTEXPR FMT_INLINE auto write(basic_appender< Char > out, T value, const format_specs &specs, locale_ref loc) -> basic_appender< Char >
Definition format.h:2125
type
Definition base.h:975
auto parse_header(const Char *&it, const Char *end, format_specs &specs, GetArg get_arg) -> int
Definition printf.h:330
auto find< false, char >(const char *first, const char *last, char value, const char *&out) -> bool
Definition printf.h:62
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:543
auto vsprintf(basic_string_view< Char > fmt, typename vprintf_args< Char >::type args) -> std::basic_string< Char >
Definition printf.h:553
auto vfprintf(std::FILE *f, basic_string_view< Char > fmt, typename vprintf_args< Char >::type args) -> int
Definition printf.h:580
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:617
auto sprintf(string_view fmt, const T &... args) -> std::string
Formats args according to specifications in fmt and returns the result as as string.
Definition printf.h:570
auto fprintf(std::FILE *f, string_view fmt, const T &... args) -> int
Formats args according to specifications in fmt and writes the output to f.
Definition printf.h:599
auto operator()(T) -> const Char *
Definition printf.h:190
auto operator()(const Char *s) -> const Char *
Definition printf.h:191
static auto fits_in_int(int) -> bool
Definition printf.h:83
static auto fits_in_int(T value) -> bool
Definition printf.h:79
static auto fits_in_int(T value) -> bool
Definition printf.h:72
static auto fits_in_int(bool) -> bool
Definition printf.h:75
auto operator()(T value) -> bool
Definition printf.h:104
auto operator()(T) -> bool
Definition printf.h:109
Definition format-inl.h:57
bool type
Definition printf.h:117
auto operator()(T) -> int
Definition printf.h:95
auto operator()(T value) -> int
Definition printf.h:88