22 template <
typename Char>
23 class null_terminating_iterator {
34 : ptr_(ptr), end_(end) {}
36 template <
typename Range>
47 return ptr_ != end_ ? *ptr_ : Char();
81 return ptr_ - other.ptr_;
85 return ptr_ != other.ptr_;
89 return ptr_ >= other.ptr_;
94 template <
typename CharT>
103 template <
typename T>
106 template <
typename Char>
115 template <
typename Iterator,
typename ErrorHandler>
117 assert(
'0' <= *it && *it <=
'9');
124 unsigned max_int = (std::numeric_limits<int>::max)();
125 unsigned big = max_int / 10;
132 value = value * 10 + unsigned(*it -
'0');
137 }
while (
'0' <= *it && *it <=
'9');
139 eh.on_error(
"number is too big");
145 template <
bool IsSigned>
147 template <
typename T>
149 unsigned max = std::numeric_limits<int>::max();
157 template <
typename T>
159 return value >= std::numeric_limits<int>::min() &&
167 template <
typename T>
168 typename std::enable_if<std::is_integral<T>::value,
int>
::type 170 if (!
int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
172 return static_cast<int>(value);
175 template <
typename T>
185 template <
typename T>
186 typename std::enable_if<std::is_integral<T>::value,
bool>
::type 189 template <
typename T>
190 typename std::enable_if<!std::is_integral<T>::value,
bool>
::type 194 template <
typename T>
202 template <
typename T,
typename Context>
212 : arg_(arg), type_(type) {}
216 operator()<
bool>(value);
219 template <
typename U>
220 typename std::enable_if<std::is_integral<U>::value>
::type 222 bool is_signed = type_ ==
'd' || type_ ==
'i';
223 typedef typename std::conditional<
224 std::is_same<T, void>::value, U, T>
::type TargetType;
225 if (
const_check(
sizeof(TargetType) <=
sizeof(
int))) {
228 arg_ = internal::make_arg<Context>(
229 static_cast<int>(
static_cast<TargetType
>(value)));
232 arg_ = internal::make_arg<Context>(
233 static_cast<unsigned>(
static_cast<Unsigned
>(value)));
240 arg_ = internal::make_arg<Context>(
static_cast<long long>(value));
242 arg_ = internal::make_arg<Context>(
248 template <
typename U>
258 template <
typename T,
typename Context,
typename Char>
264 template <
typename Context>
272 template <
typename T>
273 typename std::enable_if<std::is_integral<T>::value>
::type 276 arg_ = internal::make_arg<Context>(
static_cast<Char
>(value));
279 template <
typename T>
287 template <
typename Char>
297 template <
typename T>
298 typename std::enable_if<std::is_integral<T>::value,
unsigned>
::type 301 UnsignedType width =
static_cast<UnsignedType
>(value);
306 unsigned int_max = std::numeric_limits<int>::max();
309 return static_cast<unsigned>(width);
312 template <
typename T>
313 typename std::enable_if<!std::is_integral<T>::value,
unsigned>
::type 320 template <
typename Char,
typename Context>
323 Context(std::back_inserter(buf), format, args).format();
329 template <
typename Range>
333 typename OutputIt,
typename Char,
334 typename ArgFormatter =
343 template <
typename Range>
346 typename internal::arg_formatter_base<Range>::iterator>,
349 typedef typename Range::value_type
char_type;
350 typedef decltype(internal::declval<Range>().
begin())
iterator;
351 typedef internal::arg_formatter_base<Range>
base;
354 context_type &context_;
356 void write_null_pointer(
char) {
357 this->spec()->type = 0;
358 this->
write(
"(nil)");
361 void write_null_pointer(
wchar_t) {
362 this->spec()->type = 0;
363 this->
write(L
"(nil)");
382 template <
typename T>
383 typename std::enable_if<std::is_integral<T>::value, iterator>
::type 387 if (std::is_same<T, bool>::value) {
388 format_specs &fmt_spec = *this->spec();
389 if (fmt_spec.
type !=
's')
390 return base::operator()(value ? 1 : 0);
392 this->
write(value != 0);
393 }
else if (std::is_same<T, char_type>::value) {
394 format_specs &fmt_spec = *this->spec();
395 if (fmt_spec.
type && fmt_spec.
type !=
'c')
396 return (*
this)(
static_cast<int>(value));
399 return base::operator()(value);
401 return base::operator()(value);
406 template <
typename T>
407 typename std::enable_if<std::is_floating_point<T>::value, iterator>
::type 409 return base::operator()(value);
415 base::operator()(value);
416 else if (this->spec()->
type ==
'p')
419 this->
write(
"(null)");
426 base::operator()(value);
427 else if (this->spec()->
type ==
'p')
430 this->
write(L
"(null)");
435 return base::operator()(value);
439 return base::operator()(value);
445 return base::operator()(value);
446 this->spec()->type = 0;
458 template <
typename T>
460 template <
typename ParseContext>
461 auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
return ctx.begin(); }
463 template <
typename FormatContext>
464 auto format(
const T &value, FormatContext &ctx) -> decltype(ctx.out()) {
471 template <
typename OutputIt,
typename Char,
typename ArgFormatter>
476 OutputIt, basic_printf_context<OutputIt, Char, ArgFormatter>, Char> {
481 template <
typename T>
490 void parse_flags(format_specs &spec, iterator &it);
496 unsigned arg_index = (std::numeric_limits<unsigned>::max)());
499 unsigned parse_header(iterator &it, format_specs &spec);
511 : base(out, format_str, args) {}
515 using base::advance_to;
521 template <
typename OutputIt,
typename Char,
typename AF>
548 template <
typename OutputIt,
typename Char,
typename AF>
553 if (arg_index == std::numeric_limits<unsigned>::max())
554 return this->do_get_arg(this->
parse_context().next_arg_id());
555 return base::get_arg(arg_index - 1);
558 template <
typename OutputIt,
typename Char,
typename AF>
561 unsigned arg_index = std::numeric_limits<unsigned>::max();
563 if (c >=
'0' && c <=
'9') {
582 parse_flags(spec, it);
584 if (*it >=
'0' && *it <=
'9') {
587 }
else if (*it ==
'*') {
595 template <
typename OutputIt,
typename Char,
typename AF>
603 if (c !=
'%')
continue;
615 unsigned arg_index = parse_header(it, spec);
620 if (
'0' <= *it && *it <=
'9') {
623 }
else if (*it ==
'*') {
634 spec.
flags = static_cast<uint_least8_t>(spec.
flags & (~internal::to_unsigned<int>(
HASH_FLAG)));
635 if (spec.
fill_ ==
'0') {
647 convert_arg<signed char>(
arg, *++it);
649 convert_arg<short>(
arg, *it);
653 convert_arg<long long>(
arg, *++it);
655 convert_arg<long>(
arg, *it);
658 convert_arg<intmax_t>(
arg, *it);
661 convert_arg<std::size_t>(
arg, *it);
664 convert_arg<std::ptrdiff_t>(
arg, *it);
672 convert_arg<void>(
arg, *it);
678 spec.
type =
static_cast<char>(*it++);
701 template <
typename Buffer>
704 std::back_insert_iterator<Buffer>,
typename Buffer::value_type>
type;
719 template<
typename... Args>
729 template<
typename... Args>
733 template <
typename S,
typename Char = FMT_CHAR(S)>
734 inline std::basic_string<Char>
752 template <
typename S,
typename... Args>
764 template <
typename S,
typename Char = FMT_CHAR(S)>
770 std::size_t size = buffer.
size();
772 buffer.
data(),
sizeof(Char), size, f) < size ? -1 :
static_cast<int>(size);
784 template <
typename S,
typename... Args>
795 template <
typename S,
typename Char = FMT_CHAR(S)>
811 template <
typename S,
typename... Args>
813 printf(const S &format_str, const Args & ... args) {
822 template <
typename S,
typename Char = FMT_CHAR(S)>
830 return static_cast<int>(buffer.
size());
842 template <
typename S,
typename... Args>
845 const S &format_str, const Args & ... args) {
855 #endif // FMT_PRINTF_H_ std::enable_if<!std::is_integral< T >::value, bool >::type operator()(T)
auto begin(const C &c) -> decltype(c.begin())
null_terminating_iterator operator-(difference_type n)
void convert_arg(basic_format_arg< Context > &arg, Char type)
static bool fits_in_int(T value)
const T * pointer_from(const T *p)
static bool fits_in_int(T value)
basic_printf_context(OutputIt out, basic_string_view< char_type > format_str, basic_format_args< basic_printf_context > args)
void write(std::basic_ostream< Char > &os, basic_buffer< Char > &buf)
std::enable_if< internal::is_string< S >::value, std::basic_string< typename char_t< S >::type > >::type sprintf(const S &format, const Args &...args)
std::enable_if< internal::is_string< S >::value, int >::type printf(const S &format_str, const Args &...args)
null_terminating_iterator operator++()
std::ptrdiff_t difference_type
int vprintf(const S &format, basic_format_args< typename basic_printf_context_t< internal::basic_buffer< Char >>::type > args)
basic_printf_context< std::back_insert_iterator< Buffer >, typename Buffer::value_type > type
null_terminating_iterator & operator=(const Char *ptr)
std::enable_if< std::is_integral< T >::value, int >::type operator()(T value)
#define FMT_CONSTEXPR_DECL
std::enable_if< std::is_integral< T >::value, unsigned >::type operator()(T value)
internal::named_arg< T, char > arg(string_view name, const T &arg)
Container & get_container(std::back_insert_iterator< Container > it)
std::enable_if< std::is_integral< T >::value, bool >::type operator()(T value)
#define FMT_END_NAMESPACE
printf_formatter< T > type
null_terminating_iterator operator+=(difference_type n)
std::enable_if<!std::is_integral< U >::value >::type operator()(U)
std::enable_if< std::is_integral< T >::value >::type operator()(T value)
unsigned parse_nonnegative_int(Iterator &it, ErrorHandler &&eh)
static bool fits_in_int(bool)
bool operator>=(null_terminating_iterator other) const
null_terminating_iterator()
bool operator!=(null_terminating_iterator other) const
internal::result_of< Visitor(int)>::type visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg)
basic_buffer< char > buffer
std::enable_if< std::is_integral< U >::value >::type operator()(U value)
std::basic_string< typename char_t< S >::type > format(const S &format_str, const Args &...args)
format_arg_store< printf_context, Args... > make_printf_args(const Args &...args)
null_terminating_iterator operator+(difference_type n)
format_arg_store< wprintf_context, Args... > make_wprintf_args(const Args &...args)
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type is_negative(T value)
basic_format_specs< char > format_specs
printf_width_handler(format_specs &spec)
std::enable_if< internal::is_string< S >::value, int >::type fprintf(std::basic_ostream< typename char_t< S >::type > &os, const S &format_str, const Args &...args)
char_converter(basic_format_arg< Context > &arg)
null_terminating_iterator operator--()
arg_converter(basic_format_arg< Context > &arg, Char type)
basic_format_args< wprintf_context > wprintf_args
string_view_t & to_string_view(spdlog::level::level_enum l) noexcept
const void * ptr(const T *p)
basic_parse_context< char > parse_context
null_terminating_iterator(const Char *ptr, const Char *end)
std::enable_if<!std::is_integral< T >::value >::type operator()(T)
null_terminating_iterator(const Range &r)
std::basic_string< Char > vsprintf(const S &format, basic_format_args< typename basic_printf_context_t< internal::basic_buffer< Char >>::type > args)
void format_value(basic_buffer< Char > &buffer, const T &value)
void operator()(bool value)
#define FMT_ENABLE_IF_T(B, T)
std::string to_string(const T &value)
#define FMT_BEGIN_NAMESPACE
std::random_access_iterator_tag iterator_category
null_terminating_iterator operator++(int)
std::enable_if<!is_compile_string< S >::value >::type check_format_string(const S &)
static bool fits_in_int(int)
basic_printf_context_t< internal::wbuffer >::type wprintf_context
difference_type operator-(null_terminating_iterator other) const
int vfprintf(std::basic_ostream< Char > &os, const S &format, basic_format_args< typename basic_printf_context_t< internal::basic_buffer< Char >>::type > args)
std::enable_if<!std::is_integral< T >::value, unsigned >::type operator()(T)
std::enable_if<!std::is_integral< T >::value, int >::type operator()(T)
auto end(const C &c) -> decltype(c.end())
basic_printf_context_t< internal::buffer >::type printf_context
basic_format_args< printf_context > printf_args
void append(const U *begin, const U *end)