|
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_ = internal::make_arg<Context>(
94 static_cast<int>( static_cast<target_type >( value)));
97 arg_ = internal::make_arg<Context>(
98 static_cast<unsigned>( static_cast<unsigned_type >( value)));
105 arg_ = internal::make_arg<Context>( static_cast<long long>( value));
107 arg_ = internal::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_ = internal::make_arg<Context>(
137 static_cast<typename Context::char_type >( value));
140 template < typename T, FMT_ENABLE_IF(!std::is_ integral<T>::value)>
155 template < typename T, FMT_ENABLE_IF(std::is_ integral<T>::value)>
162 unsigned int_max = max_value<int>();
164 return static_cast<unsigned>(width);
167 template < typename T, FMT_ENABLE_IF(!std::is_ integral<T>::value)>
174template < typename Char, typename Context>
177 Context(std::back_inserter(buf), format, args).format();
180template < typename OutputIt, typename Char, typename Context>
184 return Context(it, format, args).format();
199template < typename Range>
213 this-> write( "(nil)");
218 this-> write(L "(nil)");
234 template < typename T, FMT_ENABLE_IF(fmt:: internal::is_ integral<T>::value)>
238 if (std::is_same<T, bool>::value) {
242 this-> write(value != 0);
243 } else if (std::is_same<T, char_type>::value) {
245 if (fmt_specs.type && fmt_specs.type != 'c')
246 return (* this)( static_cast<int>(value));
248 fmt_specs.alt = false;
257 template < typename T, FMT_ENABLE_IF(std::is_ floating_po int<T>::value)>
266 else if (this-> specs()->type == 'p')
269 this-> write( "(null)");
277 else if (this-> specs()->type == 'p')
280 this-> write(L "(null)");
306 template < typename ParseContext>
307 auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
311 template < typename FormatContext>
312 auto format( const T& value, FormatContext& ctx) -> decltype(ctx.out()) {
367 template < typename ArgFormatter = pr intf_arg_formatter<buffer_range<Char>>>
371template < typename OutputIt, typename Char>
375 for (; it != end; ++it) {
398template < typename OutputIt, typename Char>
402 arg_index = parse_ctx_.next_arg_id();
404 parse_ctx_.check_arg_id(--arg_index);
408template < typename OutputIt, typename Char>
410 const Char*& it, const Char* end, format_specs& specs) {
413 if (c >= '0' && c <= '9') {
417 int value = parse_nonnegative_int(it, end, eh);
418 if (it != end && *it == '$') {
422 if (c == '0') specs. fill[0] = '0';
431 parse_flags(specs, it, end);
434 if (*it >= '0' && *it <= '9') {
436 specs. width = parse_nonnegative_int(it, end, eh);
437 } else if (*it == '*') {
446template < typename OutputIt, typename Char>
447template < typename ArgFormatter>
449 auto out = this->out();
450 const Char* start = parse_ctx_.begin();
451 const Char* end = parse_ctx_.end();
455 if (c != '%') continue;
456 if (it != end && *it == c) {
457 out = std::copy(start, it, out);
461 out = std::copy(start, it - 1, out);
467 int arg_index = parse_header(it, end, specs);
468 if (arg_index == 0) on_error( "argument index out of range");
471 if (it != end && *it == '.') {
473 c = it != end ? *it : 0;
474 if ( '0' <= c && c <= '9') {
476 specs. precision = parse_nonnegative_int(it, end, eh);
477 } else if (c == '*') {
489 if (specs. fill[0] == '0') {
490 if ( arg.is_arithmetic())
497 c = it != end ? *it++ : 0;
504 t = it != end ? *it : 0;
505 convert_arg<signed char>( arg, t);
507 convert_arg<short>( arg, t);
513 t = it != end ? *it : 0;
514 convert_arg<long long>( arg, t);
516 convert_arg<long>( arg, t);
520 convert_arg<intmax_t>( arg, t);
523 convert_arg<std::size_t>( arg, t);
526 convert_arg<std::ptrdiff_t>( arg, t);
534 convert_arg<void>( arg, c);
539 specs. type = static_cast<char>(*it++);
540 if ( arg.is_integral()) {
542 switch (specs. type) {
559 return std::copy(start, it, out);
562template < typename Char>
579template < typename... Args>
581 const Args&... args) {
591template < typename... Args>
593 const Args&... args) {
597template < typename S, typename Char = char_t<S>>
614template < typename S, typename... Args,
616inline std::basic_string<Char> sprintf( const S& format, const Args&... args) {
621template < typename S, typename Char = char_t<S>>
626 std::size_t size = buffer. size();
627 return std::fwrite(buffer. data(), sizeof(Char), size, f) < size
629 : static_cast<int>(size);
641template < typename S, typename... Args,
646 {make_format_args<context>(args...)});
649template < typename S, typename Char = char_t<S>>
664template < typename S, typename... Args,
666inline int printf( const S& format_str, const Args&... args) {
669 {make_format_args<context>(args...)});
672template < typename S, typename Char = char_t<S>>
678 return static_cast<int>(buffer. size());
682template < typename ArgFormatter, typename Char,
688 typename ArgFormatter::iterator iter(out);
689 Context(iter, format_str, args).template format<ArgFormatter>();
702template < typename S, typename... Args, typename Char = char_t<S>>
703inline int fprintf(std::basic_ostream<Char>& os, const S& format_str,
704 const Args&... args) {
707 {make_format_args<context>(args...)});
basic_format_parse_context< Char > & parse_context()
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)
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)
basic_format_parse_context< Char > parse_ctx_
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_
std::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
internal::named_arg< T, Char > arg(const S &name, const T &arg)
#define FMT_BEGIN_NAMESPACE
FMT_CONSTEXPR auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
basic_string_view< Char > to_string_view(const Char *s)
#define FMT_ENABLE_IF(...)
typename internal::char_t_impl< S >::type char_t
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 bool is_negative(T value)
void format_value(buffer< Char > &buf, const T &value, locale_ref loc=locale_ref())
void write(std::basic_ostream< Char > &os, buffer< Char > &buf)
conditional_t< std::numeric_limits< T >::digits<=32, uint32_t, conditional_t< std::numeric_limits< T >::digits<=64, uint64_t, uint128_t > > uint32_or_64_or_128_t
void printf(buffer< Char > &buf, basic_string_view< Char > format, basic_format_args< Context > args)
FMT_CONSTEXPR Context::format_arg get_arg(Context &ctx, int id)
int vprintf(const S &format, basic_format_args< basic_printf_context_t< Char > > args)
std::basic_string< Char > vsprintf(const S &format, basic_format_args< basic_printf_context_t< Char > > args)
int vfprintf(std::FILE *f, const S &format, basic_format_args< basic_printf_context_t< Char > > 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
format_arg_store< wprintf_context, Args... > make_wprintf_args(const Args &... args)
int printf(const S &format_str, const Args &... args)
basic_printf_context_t< char > printf_context
format_arg_store< printf_context, Args... > make_printf_args(const Args &... args)
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)
|