39 : out_(
out), args_(args) {}
61 unsigned max = max_value<int>();
76 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
83 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
92 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
97 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
109 using char_type =
typename Context::char_type;
119 if (type_ !=
's') operator()<
bool>(
value);
122 template <
typename U, FMT_ENABLE_IF(std::is_
integral<U>::value)>
124 bool is_signed = type_ ==
'd' || type_ ==
'i';
126 if (
const_check(
sizeof(target_type) <=
sizeof(
int))) {
129 auto n =
static_cast<int>(
static_cast<target_type
>(
value));
130 arg_ = detail::make_arg<Context>(n);
133 auto n =
static_cast<unsigned>(
static_cast<unsigned_type
>(
value));
134 arg_ = detail::make_arg<Context>(n);
141 auto n =
static_cast<long long>(
value);
142 arg_ = detail::make_arg<Context>(n);
145 arg_ = detail::make_arg<Context>(n);
150 template <
typename U, FMT_ENABLE_IF(!std::is_
integral<U>::value)>
158template <
typename T,
typename Context,
typename Char>
171 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
173 auto c =
static_cast<typename Context::char_type
>(
value);
174 arg_ = detail::make_arg<Context>(
c);
177 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
184 template <
typename T>
auto operator()(T) ->
const Char* {
return nullptr; }
197 template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
201 specs_.
align = align::left;
204 unsigned int_max = max_value<int>();
206 return static_cast<unsigned>(
width);
209 template <
typename T, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
218template <
typename Char>
225template <
typename Char>
233 void write_null_pointer(
bool is_string =
false) {
234 auto s = this->
specs;
246 template <
typename T, FMT_ENABLE_IF(detail::is_
integral<T>::value)>
250 if (!std::is_same<T, Char>::value) {
257 return (*
this)(
static_cast<int>(
value));
259 fmt_specs.
sign = sign::none;
260 fmt_specs.
alt =
false;
261 fmt_specs.
fill[0] =
' ';
264 if (fmt_specs.
align == align::none || fmt_specs.
align == align::numeric)
265 fmt_specs.
align = align::right;
266 write<Char>(this->
out,
static_cast<Char
>(
value), fmt_specs);
269 template <
typename T, FMT_ENABLE_IF(std::is_
floating_po
int<T>::value)>
297 write_null_pointer();
303 handle.
format(parse_ctx, context_);
307template <
typename Char>
309 for (; it != end; ++it) {
312 specs.
align = align::left;
315 specs.
sign = sign::plus;
321 if (specs.
sign != sign::plus) specs.
sign = sign::space;
332template <
typename Char,
typename GetArg>
337 if (
c >=
'0' &&
c <=
'9') {
341 if (it != end && *it ==
'$') {
343 arg_index =
value != -1 ?
value : max_value<int>();
345 if (
c ==
'0') specs.fill[0] =
'0';
358 if (*it >=
'0' && *it <=
'9') {
361 }
else if (*it ==
'*') {
376 return in(t, integral_set) ? pt::dec : pt::none;
378 return in(t, integral_set) ? pt::oct : pt::none;
380 return in(t, integral_set) ? pt::hex_lower : pt::none;
382 return in(t, integral_set) ? pt::hex_upper : pt::none;
384 return in(t,
float_set) ? pt::hexfloat_lower : pt::none;
386 return in(t,
float_set) ? pt::hexfloat_upper : pt::none;
388 return in(t,
float_set) ? pt::exp_lower : pt::none;
390 return in(t,
float_set) ? pt::exp_upper : pt::none;
392 return in(t,
float_set) ? pt::fixed_lower : pt::none;
394 return in(t,
float_set) ? pt::fixed_upper : pt::none;
396 return in(t,
float_set) ? pt::general_lower : pt::none;
398 return in(t,
float_set) ? pt::general_upper : pt::none;
400 return in(t, integral_set) ? pt::chr : pt::none;
410template <
typename Char,
typename Context>
414 auto out = iterator(buf);
420 auto get_arg = [&](
int arg_index) {
422 arg_index = parse_ctx.next_arg_id();
424 parse_ctx.check_arg_id(--arg_index);
428 const Char*
start = parse_ctx.begin();
429 const Char* end = parse_ctx.end();
432 if (!find<false, Char>(it, end,
'%', it)) {
437 if (it != end && *it ==
c) {
445 specs.align = align::right;
452 if (it != end && *it ==
'.') {
454 c = it != end ? *it : 0;
455 if (
'0' <=
c &&
c <=
'9') {
457 }
else if (
c ==
'*') {
459 specs.precision =
static_cast<int>(
469 if (specs.precision >= 0 &&
arg.is_integral()) {
475 auto str_end = str + specs.precision;
476 auto nul =
std::find(str, str_end, Char());
478 str,
to_unsigned(nul != str_end ? nul - str : specs.precision));
479 arg = make_arg<basic_printf_context<Char>>(sv);
482 if (specs.fill[0] ==
'0') {
483 if (
arg.is_arithmetic() && specs.align != align::left)
484 specs.align = align::numeric;
491 c = it != end ? *it++ : 0;
492 Char t = it != end ? *it : 0;
497 t = it != end ? *it : 0;
498 convert_arg<signed char>(
arg, t);
500 convert_arg<short>(
arg, t);
506 t = it != end ? *it : 0;
507 convert_arg<long long>(
arg, t);
509 convert_arg<long>(
arg, t);
513 convert_arg<intmax_t>(
arg, t);
516 convert_arg<size_t>(
arg, t);
519 convert_arg<std::ptrdiff_t>(
arg, t);
527 convert_arg<void>(
arg,
c);
532 char type =
static_cast<char>(*it++);
533 if (
arg.is_integral()) {
570template <
typename... T>
577template <
typename... T>
583template <
typename Char>
587 -> std::basic_string<Char> {
602template <
typename S,
typename... T,
604inline auto sprintf(
const S& fmt,
const T&... args) -> std::basic_string<Char> {
609template <
typename Char>
616 size_t size = buf.size();
617 return std::fwrite(buf.data(),
sizeof(Char), size, f) < size
619 :
static_cast<int>(size);
631template <
typename S,
typename... T,
typename Char =
char_t<S>>
632inline auto fprintf(std::FILE* f,
const S& fmt,
const T&... args) ->
int {
637template <
typename Char>
654template <
typename... T>
658template <
typename... T>
660 const T&... args) ->
int {
you may not use this file except in compliance with the License You may obtain a copy of the License at software distributed under the License is distributed on an AS IS WITHOUT WARRANTIES OR CONDITIONS OF ANY either express or implied See the License for the specific language governing permissions and limitations under the License LLVM Exceptions to the Apache License As an if
Definition: ThirdPartyNotices.txt:289
\rst Parsing context consisting of a format string range being parsed and an argument counter for aut...
Definition: core.h:656
\rst A dynamically growing memory buffer for trivially copyable/constructible types with the first SI...
Definition: format.h:918
auto out() -> detail::buffer_appender< Char >
Definition: printf.h:41
basic_printf_context(detail::buffer_appender< Char > out, basic_format_args< basic_printf_context > args)
\rst Constructs a printf_context object.
Definition: printf.h:37
auto locale() -> detail::locale_ref
Definition: printf.h:44
Char char_type
Definition: printf.h:27
FMT_CONSTEXPR void on_error(const char *message)
Definition: printf.h:50
void advance_to(detail::buffer_appender< Char >)
Definition: printf.h:42
auto arg(int id) const -> basic_format_arg< basic_printf_context >
Definition: printf.h:46
An implementation of std::basic_string_view for pre-C++17.
Definition: core.h:398
arg_converter(basic_format_arg< Context > &arg, char_type type)
Definition: printf.h:115
void operator()(U)
Definition: printf.h:151
void operator()(U value)
Definition: printf.h:123
void operator()(bool value)
Definition: printf.h:118
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:798
char_converter(basic_format_arg< Context > &arg)
Definition: printf.h:169
void operator()(T)
Definition: printf.h:178
void operator()(T value)
Definition: printf.h:172
auto operator()(T value) -> unsigned
Definition: printf.h:198
printf_width_handler(format_specs< Char > &specs)
Definition: printf.h:195
auto operator()(T) -> unsigned
Definition: printf.h:210
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:256
FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
\rst Visits an argument dispatching to the appropriate visit method based on the argument type.
Definition: core.h:1665
#define FMT_END_EXPORT
Definition: core.h:185
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
\rst Returns a named argument to be used in a formatting function.
Definition: core.h:1841
typename detail::char_t_impl< S >::type char_t
String's character type.
Definition: core.h:646
#define FMT_CONSTEXPR
Definition: core.h:105
#define FMT_BEGIN_NAMESPACE
Definition: core.h:174
constexpr auto make_format_args(T &... args) -> format_arg_store< Context, remove_cvref_t< T >... >
\rst Constructs a ~fmtformat_arg_store object that contains references to arguments and can be implic...
Definition: core.h:1824
#define FMT_BEGIN_EXPORT
Definition: core.h:184
typename type_identity< T >::type type_identity_t
Definition: core.h:267
typename std::conditional< B, T, F >::type conditional_t
Definition: core.h:258
presentation_type
Definition: core.h:2019
#define FMT_END_NAMESPACE
Definition: core.h:177
detail namespace with internal helper functions
Definition: xchar.h:20
void convert_arg(basic_format_arg< Context > &arg, Char type)
Definition: printf.h:159
void vprintf(buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
Definition: printf.h:411
auto make_arg_formatter(buffer_appender< Char > iter, format_specs< Char > &s) -> arg_formatter< Char >
Definition: printf.h:219
std::integral_constant< bool, std::numeric_limits< T >::is_signed||std::is_same< T, int128_opt >::value > is_signed
Definition: format.h:811
FMT_CONSTEXPR auto write_bytes(OutputIt out, string_view bytes, const format_specs< Char > &specs) -> OutputIt
Definition: format.h:1819
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
Definition: chrono.h:419
auto parse_printf_presentation_type(char c, type t) -> presentation_type
Definition: printf.h:370
FMT_CONSTEXPR auto parse_nonnegative_int(const Char *&begin, const Char *end, int error_value) noexcept -> int
Definition: core.h:2138
FMT_INLINE auto to_string_view(const Char *s) -> basic_string_view< Char >
Definition: core.h:517
FMT_CONSTEXPR auto get_arg(Context &ctx, ID id) -> decltype(ctx.arg(id))
Definition: format.h:3871
FMT_FUNC void throw_format_error(const char *message)
Definition: format-inl.h:39
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
@ bool_set
Definition: core.h:621
@ uint_set
Definition: core.h:619
@ pointer_set
Definition: core.h:627
@ float_set
Definition: core.h:623
@ cstring_set
Definition: core.h:626
@ char_set
Definition: core.h:622
@ sint_set
Definition: core.h:617
@ string_set
Definition: core.h:625
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2120
conditional_t< std::is_same< T, char >::value, appender, std::back_insert_iterator< buffer< T > > > buffer_appender
Definition: core.h:1113
void parse_flags(format_specs< Char > &specs, const Char *&it, const Char *end)
Definition: printf.h:308
auto parse_header(const Char *&it, const Char *end, format_specs< Char > &specs, GetArg get_arg) -> int
Definition: printf.h:333
constexpr auto is_negative(T value) -> bool
Definition: format.h:1130
type
Definition: core.h:556
constexpr FMT_INLINE auto const_check(T value) -> T
Definition: core.h:323
FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned< Int >::type
Definition: core.h:374
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:1152
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
std::string to_string(const T &t)
Definition: base.h:92
UnitTypeLhs() max(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3417
UnitTypeLhs() min(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3409
auto vsprintf(basic_string_view< Char > fmt, basic_format_args< basic_printf_context< type_identity_t< Char > > > args) -> std::basic_string< Char >
Definition: printf.h:584
auto make_wprintf_args(const T &... args) -> format_arg_store< wprintf_context, T... >
Definition: printf.h:578
auto fprintf(std::FILE *f, const S &fmt, const T &... args) -> int
\rst Prints formatted data to the file f.
Definition: printf.h:632
auto sprintf(const S &fmt, const T &... args) -> std::basic_string< Char >
\rst Formats arguments and returns the result as a string.
Definition: printf.h:604
auto vfprintf(std::FILE *f, basic_string_view< Char > fmt, basic_format_args< basic_printf_context< type_identity_t< Char > > > args) -> int
Definition: printf.h:610
basic_printf_context< char > printf_context
Definition: printf.h:558
basic_printf_context< wchar_t > wprintf_context
Definition: printf.h:559
auto make_printf_args(const T &... args) -> format_arg_store< printf_context, T... >
\rst Constructs an ~fmtformat_arg_store object that contains references to arguments and can be impli...
Definition: printf.h:571
auto printf(string_view fmt, const T &... args) -> int
\rst Prints formatted data to stdout.
Definition: printf.h:655
FMT_DEPRECATED auto vprintf(basic_string_view< Char > fmt, basic_format_args< basic_printf_context< type_identity_t< Char > > > args) -> int
Definition: printf.h:638
FMT_NORETURN void on_error(const char *message)
Definition: core.h:636
auto operator()(T) -> const Char *
Definition: printf.h:184
auto operator()(const Char *s) -> const Char *
Definition: printf.h:185
static auto fits_in_int(int) -> bool
Definition: printf.h:72
static auto fits_in_int(T value) -> bool
Definition: printf.h:68
static auto fits_in_int(T value) -> bool
Definition: printf.h:60
static auto fits_in_int(bool) -> bool
Definition: printf.h:64
auto operator()(T value) -> bool
Definition: printf.h:93
auto operator()(T) -> bool
Definition: printf.h:98
bool type
Definition: printf.h:105
auto operator()(T) -> int
Definition: printf.h:84
auto operator()(T value) -> int
Definition: printf.h:77
#define S(label, offset, message)
Definition: Errors.h:119
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:108