25template <
typename Char>
31template <
typename OutputIt,
typename Char>
78 detail::error_handler().on_error(message);
86template <
bool IsSigned>
92 unsigned max = max_value<int>();
104 template <
typename T>
107 return value >= (std::numeric_limits<int>::min)() &&
108 value <= max_value<int>();
119 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
124 return (std::max)(
static_cast<int>(
value), 0);
127 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
139 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
145 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
163template <
typename T,
typename Context>
181 operator()<
bool>(
value);
184 template <
typename U, FMT_ENABLE_IF(std::is_
integral<U>::value)>
189 if (
const_check(
sizeof(target_type) <=
sizeof(
int)))
194 arg_ = detail::make_arg<Context>(
195 static_cast<int>(
static_cast<target_type
>(
value)));
200 arg_ = detail::make_arg<Context>(
201 static_cast<unsigned>(
static_cast<unsigned_type
>(
value)));
211 arg_ = detail::make_arg<Context>(
static_cast<long long>(
value));
215 arg_ = detail::make_arg<Context>(
221 template <
typename U, FMT_ENABLE_IF(!std::is_
integral<U>::value)>
231template <
typename T,
typename Context,
typename Char>
238template <
typename Context>
250 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
253 arg_ = detail::make_arg<Context>(
254 static_cast<typename Context::char_type
>(
value));
257 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
265template <
typename Char>
268 template <
typename T>
281template <
typename Char>
295 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
299 if (detail::is_negative(
value))
301 specs_.align = align::left;
304 unsigned int_max = max_value<int>();
307 return static_cast<unsigned>(width);
310 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
319template <
typename OutputIt,
typename Char>
344 return base::operator()(
value);
347 template <
typename T, FMT_ENABLE_IF(detail::is_
integral<T>::value)>
352 if (std::is_same<T, Char>::value)
358 return (*
this)(
static_cast<int>(
value));
360 fmt_specs.sign = sign::none;
361 fmt_specs.alt =
false;
362 fmt_specs.fill[0] =
' ';
365 if (fmt_specs.align == align::none || fmt_specs.align == align::numeric)
366 fmt_specs.align = align::right;
367 return write<Char>(this->
out,
static_cast<Char
>(
value), fmt_specs);
369 return base::operator()(
value);
372 template <
typename T, FMT_ENABLE_IF(std::is_
floating_po
int<T>::value)>
375 return base::operator()(
value);
382 return base::operator()(
value);
390 return base::operator()(
value);
396 return base::operator()(
value);
415template <
typename Char>
418 for (; it != end; ++it)
423 specs.
align = align::left;
426 specs.
sign = sign::plus;
432 if (specs.
sign != sign::plus)
434 specs.
sign = sign::space;
446template <
typename Char,
typename GetArg>
451 if (c >=
'0' && c <=
'9')
456 if (it != end && *it ==
'$')
459 arg_index =
value != -1 ?
value : max_value<int>();
480 if (*it >=
'0' && *it <=
'9')
483 if (specs.
width == -1)
490 detail::printf_width_handler<Char>(specs),
get_arg(-1)));
496template <
typename Char,
typename Context>
500 auto out = OutputIt(buf);
506 auto get_arg = [&](
int arg_index) {
508 arg_index = parse_ctx.next_arg_id();
510 parse_ctx.check_arg_id(--arg_index);
511 return detail::get_arg(context, arg_index);
514 const Char* start = parse_ctx.begin();
515 const Char* end = parse_ctx.end();
519 if (!detail::find<false, Char>(it, end,
'%', it))
525 if (it != end && *it == c)
533 start, detail::to_unsigned(it - 1 - start)));
536 specs.
align = align::right;
541 parse_ctx.on_error(
"argument not found");
544 if (it != end && *it ==
'.')
547 c = it != end ? *it : 0;
548 if (
'0' <= c && c <=
'9')
570 if (specs.
precision >= 0 &&
arg.type() == detail::type::cstring_type)
574 auto nul = std::find(str, str_end, Char());
575 arg = detail::make_arg<basic_printf_context<OutputIt, Char>>(
577 str, detail::to_unsigned(nul != str_end ? nul - str
582 if (specs.
fill[0] ==
'0')
584 if (
arg.is_arithmetic() && specs.
align != align::left)
585 specs.
align = align::numeric;
592 c = it != end ? *it++ : 0;
593 Char t = it != end ? *it : 0;
594 using detail::convert_arg;
601 t = it != end ? *it : 0;
602 convert_arg<signed char>(
arg, t);
606 convert_arg<short>(
arg, t);
613 t = it != end ? *it : 0;
614 convert_arg<long long>(
arg, t);
618 convert_arg<long>(
arg, t);
622 convert_arg<intmax_t>(
arg, t);
625 convert_arg<size_t>(
arg, t);
628 convert_arg<std::ptrdiff_t>(
arg, t);
636 convert_arg<void>(
arg, c);
642 char type =
static_cast<char>(*it++);
643 if (
arg.is_integral())
661 parse_ctx.on_error(
"invalid type specifier");
667 detail::printf_arg_formatter<OutputIt, Char>(
out, specs, context),
arg);
673template <
typename Char>
689template <
typename... T>
702template <
typename... T>
709template <
typename S,
typename Char =
char_t<S>>
713 -> std::basic_string<Char>
730inline auto sprintf(
const S&
fmt,
const T&... args) -> std::basic_string<Char>
734 fmt::make_format_args<context>(args...));
737template <
typename S,
typename Char =
char_t<S>>
745 return std::fwrite(
buffer.
data(),
sizeof(Char), size, f) < size
747 :
static_cast<int>(size);
759template <
typename S,
typename... T,
typename Char =
char_t<S>>
760inline auto fprintf(std::FILE* f,
const S&
fmt,
const T&... args) ->
int
764 fmt::make_format_args<context>(args...));
767template <
typename S,
typename Char =
char_t<S>>
773 return vfprintf(stdout, detail::to_string_view(
fmt), args);
785template <
typename S,
typename... T,
FMT_ENABLE_IF(detail::is_string<S>::value)>
786inline auto printf(
const S&
fmt,
const T&... args) ->
int
789 detail::to_string_view(
fmt),
char_type type_
Definition printf.h:170
arg_converter(basic_format_arg< Context > &arg, char_type type)
Definition printf.h:173
void operator()(U)
Definition printf.h:222
basic_format_arg< Context > & arg_
Definition printf.h:169
void operator()(U value)
Definition printf.h:185
typename Context::char_type char_type
Definition printf.h:167
void operator()(bool value)
Definition printf.h:178
basic_format_args< basic_printf_context > args_
Definition printf.h:36
OutputIt out()
Definition printf.h:57
printf_formatter< T > formatter_type
Definition printf.h:43
basic_format_arg< basic_printf_context > format_arg
Definition printf.h:40
OutputIt out_
Definition printf.h:35
Char char_type
Definition printf.h:39
FMT_CONSTEXPR void on_error(const char *message)
Definition printf.h:76
format_arg arg(int id) const
Definition printf.h:71
detail::locale_ref locale()
Definition printf.h:66
basic_printf_context(OutputIt out, basic_format_args< basic_printf_context > args)
Definition printf.h:51
basic_printf_parse_context< Char > parse_context_type
Definition printf.h:41
void advance_to(OutputIt it)
Definition printf.h:61
FMT_CONSTEXPR auto data() noexcept -> T *
Definition core.h:1102
constexpr auto size() const noexcept -> size_t
Definition core.h:1090
void operator()(T value)
Definition printf.h:251
void operator()(T)
Definition printf.h:258
basic_format_arg< Context > & arg_
Definition printf.h:242
char_converter(basic_format_arg< Context > &arg)
Definition printf.h:245
bool operator()(T value)
Definition printf.h:140
bool operator()(T)
Definition printf.h:146
int operator()(T value)
Definition printf.h:120
int operator()(T)
Definition printf.h:128
unsigned operator()(T)
Definition printf.h:311
format_specs & specs_
Definition printf.h:287
basic_format_specs< Char > format_specs
Definition printf.h:285
printf_width_handler(format_specs &specs)
Definition printf.h:290
unsigned operator()(T value)
Definition printf.h:296
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:646
typename std::enable_if< B, T >::type enable_if_t
Definition core.h:302
constexpr FMT_INLINE auto const_check(T value) -> T
Definition core.h:390
FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
Definition core.h:2133
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition core.h:2506
typename detail::char_t_impl< S >::type char_t
Definition core.h:759
#define FMT_END_DETAIL_NAMESPACE
Definition core.h:231
#define FMT_MODULE_EXPORT_BEGIN
Definition core.h:226
FMT_CONSTEXPR auto parse_presentation_type(Char type) -> presentation_type
Definition core.h:3276
#define FMT_CONSTEXPR
Definition core.h:106
type
Definition core.h:681
#define FMT_BEGIN_NAMESPACE
Definition core.h:214
#define FMT_BEGIN_DETAIL_NAMESPACE
Definition core.h:228
conditional_t< std::is_same< T, char >::value, appender, std::back_insert_iterator< buffer< T > > > buffer_appender
Definition core.h:1398
#define FMT_ENABLE_IF(...)
Definition core.h:364
FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned< Int >::type
Definition core.h:455
FMT_CONSTEXPR auto parse_nonnegative_int(const Char *&begin, const Char *end, int error_value) noexcept -> int
Definition core.h:3053
typename type_identity< T >::type type_identity_t
Definition core.h:319
typename std::conditional< B, T, F >::type conditional_t
Definition core.h:304
#define FMT_END_NAMESPACE
Definition core.h:219
#define FMT_MODULE_EXPORT_END
Definition core.h:227
#define out
Definition encodings.cpp:5
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
Definition chrono.h:481
Definition bin_to_hex.h:111
void convert_arg(basic_format_arg< Context > &arg, Char type)
Definition printf.h:232
auto vfprintf(std::FILE *f, const S &fmt, basic_format_args< basic_printf_context_t< type_identity_t< Char > > > args) -> int
Definition printf.h:738
basic_format_args< wprintf_context > wprintf_args
Definition printf.h:681
auto vsprintf(const S &fmt, basic_format_args< basic_printf_context_t< type_identity_t< Char > > > args) -> std::basic_string< Char >
Definition printf.h:710
auto make_wprintf_args(const T &... args) -> format_arg_store< wprintf_context, T... >
Definition printf.h:703
basic_format_args< printf_context > printf_args
Definition printf.h:680
void vprintf(buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
Definition printf.h:497
basic_printf_context< detail::buffer_appender< Char >, Char > basic_printf_context_t
Definition printf.h:675
basic_printf_context_t< wchar_t > wprintf_context
Definition printf.h:678
auto fprintf(std::FILE *f, const S &fmt, const T &... args) -> int
Definition printf.h:760
auto printf(const S &fmt, const T &... args) -> int
Definition printf.h:786
auto sprintf(const S &fmt, const T &... args) -> std::basic_string< Char >
Definition printf.h:730
basic_printf_context_t< char > printf_context
Definition printf.h:677
void parse_flags(basic_format_specs< Char > &specs, const Char *&it, const Char *end)
Definition printf.h:416
auto make_printf_args(const T &... args) -> format_arg_store< printf_context, T... >
Definition printf.h:690
int parse_header(const Char *&it, const Char *end, basic_format_specs< Char > &specs, GetArg get_arg)
Definition printf.h:447
const Char * operator()(const Char *s)
Definition printf.h:273
const Char * operator()(T)
Definition printf.h:269
static bool fits_in_int(T value)
Definition printf.h:105
static bool fits_in_int(int)
Definition printf.h:110
static bool fits_in_int(bool)
Definition printf.h:95
static bool fits_in_int(T value)
Definition printf.h:90
bool type
Definition printf.h:160
s
Definition tag_strings.h:47