|
Loading...
Searching...
No Matches
Go to the documentation of this file.
23 unsigned max = max_value<int>();
31 return value >= (std::numeric_limits<int>::min)() &&
32 value <= max_value<int>();
39 template < typename T, FMT_ENABLE_IF(std::is_ integral<T>::value)>
43 return (std::max)( static_cast<int>( value), 0);
46 template < typename T, FMT_ENABLE_IF(!std::is_ integral<T>::value)>
56 template < typename T, FMT_ENABLE_IF(std::is_ integral<T>::value)>
61 template < typename T, FMT_ENABLE_IF(!std::is_ integral<T>::value)>
86 template < typename U, FMT_ENABLE_IF(std::is_ integral<U>::value)>
90 if ( const_check( sizeof(target_type) <= sizeof( int))) {
93 arg_ = detail::make_arg<Context>(
94 static_cast<int>( static_cast<target_type >( value)));
97 arg_ = detail::make_arg<Context>(
98 static_cast<unsigned>( static_cast<unsigned_type >( value)));
105 arg_ = detail::make_arg<Context>( static_cast<long long>( value));
107 arg_ = detail::make_arg<Context>(
113 template < typename U, FMT_ENABLE_IF(!std::is_ integral<U>::value)>
121template < typename T, typename Context, typename Char>
134 template < typename T, FMT_ENABLE_IF(std::is_ integral<T>::value)>
136 arg_ = detail::make_arg<Context>(
137 static_cast<typename Context::char_type >( value));
140 template < typename T, FMT_ENABLE_IF(!std::is_ integral<T>::value)>
147 template < typename T> const Char* operator()(T) { return nullptr; }
162 template < typename T, FMT_ENABLE_IF(std::is_ integral<T>::value)>
169 unsigned int_max = max_value<int>();
171 return static_cast<unsigned>(width);
174 template < typename T, FMT_ENABLE_IF(!std::is_ integral<T>::value)>
181template < typename Char, typename Context>
189template < typename Char, typename Context>
197template < typename Char>
208template < typename OutputIt, typename Char>
222 this-> write( "(nil)");
227 this-> write(L "(nil)");
243 template < typename T, FMT_ENABLE_IF(fmt::detail::is_ integral<T>::value)>
247 if (std::is_same<T, bool>::value) {
251 this-> write(value != 0);
252 } else if (std::is_same<T, char_type>::value) {
254 if (fmt_specs.type && fmt_specs.type != 'c')
255 return (* this)( static_cast<int>(value));
257 fmt_specs.alt = false;
258 fmt_specs.fill[0] = ' ';
270 template < typename T, FMT_ENABLE_IF(std::is_ floating_po int<T>::value)>
279 else if (this-> specs()->type == 'p')
282 this-> write( "(null)");
290 else if (this-> specs()->type == 'p')
293 this-> write(L "(null)");
321 template < typename ParseContext>
322 auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
326 template < typename FormatContext>
327 auto format( const T& value, FormatContext& ctx) -> decltype(ctx.out()) {
387 template < typename ArgFormatter = pr intf_arg_formatter<OutputIt, Char>>
391template < typename OutputIt, typename Char>
395 for (; it != end; ++it) {
420template < typename OutputIt, typename Char>
424 arg_index = parse_ctx_.next_arg_id();
426 parse_ctx_.check_arg_id(--arg_index);
430template < typename OutputIt, typename Char>
436 if (c >= '0' && c <= '9') {
440 int value = parse_nonnegative_int(it, end, eh);
441 if (it != end && *it == '$') {
445 if (c == '0') specs. fill[0] = '0';
454 parse_flags(specs, it, end);
457 if (*it >= '0' && *it <= '9') {
459 specs. width = parse_nonnegative_int(it, end, eh);
460 } else if (*it == '*') {
469template < typename OutputIt, typename Char>
470template < typename ArgFormatter>
472 auto out = this->out();
473 const Char* start = parse_ctx_.begin();
474 const Char* end = parse_ctx_.end();
478 if (c != '%') continue;
479 if (it != end && *it == c) {
480 out = std::copy(start, it, out);
484 out = std::copy(start, it - 1, out);
490 int arg_index = parse_header(it, end, specs);
491 if (arg_index == 0) on_error( "argument not found");
494 if (it != end && *it == '.') {
496 c = it != end ? *it : 0;
497 if ( '0' <= c && c <= '9') {
499 specs. precision = parse_nonnegative_int(it, end, eh);
500 } else if (c == '*') {
518 auto nul = std::find(str, str_end, Char());
525 if (specs. fill[0] == '0') {
534 c = it != end ? *it++ : 0;
541 t = it != end ? *it : 0;
542 convert_arg<signed char>( arg, t);
544 convert_arg<short>( arg, t);
550 t = it != end ? *it : 0;
551 convert_arg<long long>( arg, t);
553 convert_arg<long>( arg, t);
557 convert_arg<intmax_t>( arg, t);
560 convert_arg<size_t>( arg, t);
563 convert_arg<std::ptrdiff_t>( arg, t);
571 convert_arg<void>( arg, c);
576 specs. type = static_cast<char>(*it++);
577 if ( arg.is_integral()) {
579 switch (specs. type) {
596 return std::copy(start, it, out);
599template < typename Char>
615template < typename... Args>
617 const Args&... args) {
627template < typename... Args>
629 const Args&... args) {
633template < typename S, typename Char = char_t<S>>
651template < typename S, typename... Args,
653inline std::basic_string<Char> sprintf( const S& format, const Args&... args) {
658template < typename S, typename Char = char_t<S>>
660 std::FILE* f, const S& format,
664 size_t size = buffer. size();
665 return std::fwrite(buffer. data(), sizeof(Char), size, f) < size
667 : static_cast<int>(size);
679template < typename S, typename... Args,
684 make_format_args<context>(args...));
687template < typename S, typename Char = char_t<S>>
703template < typename S, typename... Args,
705inline int printf( const S& format_str, const Args&... args) {
708 make_format_args<context>(args...));
711template < typename S, typename Char = char_t<S>>
713 std::basic_ostream<Char>& os, const S& format,
718 return static_cast<int>(buffer. size());
722template < typename ArgFormatter, typename Char,
728 typename ArgFormatter::iterator iter(out);
729 Context(iter, format_str, args).template format<ArgFormatter>();
742template < typename S, typename... Args, typename Char = char_t<S>>
743inline int fprintf(std::basic_ostream<Char>& os, const S& format_str,
744 const Args&... args) {
747 make_format_args<context>(args...));
constexpr basic_format_parse_context(basic_string_view< Char > format_str, ErrorHandler eh={}, int next_arg_id=0)
FMT_CONSTEXPR void on_error(const char *message)
basic_format_args< basic_printf_context > args_
format_arg arg(int id) const
static void parse_flags(format_specs &specs, const Char *&it, const Char *end)
basic_printf_context(OutputIt out, basic_string_view< char_type > format_str, basic_format_args< basic_printf_context > args)
detail::locale_ref locale()
FMT_CONSTEXPR void on_error(const char *message)
void advance_to(OutputIt it)
int parse_header(const Char *&it, const Char *end, format_specs &specs)
parse_context_type parse_ctx_
parse_context_type & parse_context()
format_arg get_arg(int arg_index=-1)
arg_converter(basic_format_arg< Context > &arg, char_type type)
void operator()(bool value)
typename Context::char_type char_type
basic_format_arg< Context > & arg_
size_t size() const FMT_NOEXCEPT
char_converter(basic_format_arg< Context > &arg)
basic_format_arg< Context > & arg_
printf_width_handler(format_specs &specs)
unsigned operator()(T value)
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
typename std::enable_if< B, T >::type enable_if_t
typename detail::char_t_impl< S >::type char_t
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
#define FMT_BEGIN_NAMESPACE
basic_string_view< Char > to_string_view(const Char *s)
#define FMT_ENABLE_IF(...)
typename type_identity< T >::type type_identity_t
FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
typename std::conditional< B, T, F >::type conditional_t
#define FMT_END_NAMESPACE
Container & get_container(std::back_insert_iterator< Container > it)
void convert_arg(basic_format_arg< Context > &arg, Char type)
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
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
void vprintf(buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
std::integral_constant< bool, std::numeric_limits< T >::is_signed|| std::is_same< T, int128_t >::value > is_signed
FMT_CONSTEXPR bool is_negative(T value)
void format_value(buffer< Char > &buf, const T &value, locale_ref loc=locale_ref())
constexpr T const_check(T value)
FMT_CONSTEXPR Context::format_arg get_arg(Context &ctx, ID id)
void write_buffer(std::basic_ostream< Char > &os, buffer< Char > &buf)
FMT_DEPRECATED void printf(detail::buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
int fprintf(std::FILE *f, const S &format, const Args &... args)
std::basic_string< Char > sprintf(const S &format, const Args &... args)
basic_printf_context_t< wchar_t > wprintf_context
int vfprintf(std::FILE *f, const S &format, basic_format_args< basic_printf_context_t< type_identity_t< Char > > > args)
format_arg_store< wprintf_context, Args... > make_wprintf_args(const Args &... args)
std::basic_string< Char > vsprintf(const S &format, basic_format_args< basic_printf_context_t< type_identity_t< Char > > > args)
int vprintf(const S &format, basic_format_args< basic_printf_context_t< type_identity_t< Char > > > args)
basic_printf_context_t< char > printf_context
format_arg_store< printf_context, Args... > make_printf_args(const Args &... args)
const Char * operator()(T)
const Char * operator()(const Char *s)
static bool fits_in_int(int)
static bool fits_in_int(T value)
static bool fits_in_int(bool)
static bool fits_in_int(T value)
|