#include "core.h"
#include <algorithm>
#include <cerrno>
#include <cmath>
#include <cstdint>
#include <limits>
#include <memory>
#include <stdexcept>
#include "format-inl.h"
Go to the source code of this file.
Namespaces | |
internal | |
align | |
sign | |
Macros | |
#define | FMT_CLANG_VERSION 0 |
#define | FMT_ICC_VERSION 0 |
#define | FMT_CUDA_VERSION 0 |
#define | FMT_HAS_BUILTIN(x) 0 |
#define | FMT_FALLTHROUGH |
#define | FMT_THROW(x) throw x |
#define | FMT_USE_USER_DEFINED_LITERALS 0 |
#define | FMT_USE_UDL_TEMPLATE 0 |
#define | FMT_NUMERIC_ALIGN 1 |
#define | FMT_DEPRECATED_PERCENT 0 |
#define | FMT_USE_GRISU 1 |
#define | FMT_ALWAYS_INLINE |
#define | FMT_USE_WINDOWS_H 0 |
#define | FMT_FORMAT_AS(Type, Base) |
#define | FMT_STRING_IMPL(s, ...) |
#define | FMT_STRING(s) FMT_STRING_IMPL(s, ) |
#define | FMT_FUNC |
Typedefs | |
using | uintptr_t = fallback_uintptr |
template<typename T > | |
using | iterator_t = decltype(std::begin(std::declval< T & >())) |
template<typename T > | |
using | checked_ptr = T * |
template<typename InputIt , typename OutChar > | |
using | needs_conversion = bool_constant< std::is_same< typename std::iterator_traits< InputIt >::value_type, char >::value &&std::is_same< OutChar, char8_t >::value > |
using | memory_buffer = basic_memory_buffer< char > |
using | wmemory_buffer = basic_memory_buffer< wchar_t > |
template<typename T > | |
using | uint32_or_64_or_128_t = conditional_t< std::numeric_limits< T >::digits<=32, uint32_t, conditional_t< std::numeric_limits< T >::digits<=64, uint64_t, uint128_t > > |
using | align_t = align::type |
using | sign_t = sign::type |
using | format_specs = basic_format_specs< char > |
using | writer = basic_writer< buffer_range< char > > |
template<typename T > | |
using | is_integer = bool_constant< is_integral< T >::value &&!std::is_same< T, bool >::value &&!std::is_same< T, char >::value &&!std::is_same< T, wchar_t >::value > |
using | FMT_DEPRECATED_ALIAS = internal::basic_writer< Range > |
template<typename OutputIt , typename Char = char> | |
using | format_context_t = basic_format_context< OutputIt, Char > |
template<typename OutputIt , typename Char = char> | |
using | format_args_t = basic_format_args< format_context_t< OutputIt, Char > > |
template<typename OutputIt , typename Char = typename OutputIt::value_type> | |
using | format_to_n_context = format_context_t< internal::truncating_iterator< OutputIt >, Char > |
template<typename OutputIt , typename Char = typename OutputIt::value_type> | |
using | format_to_n_args = basic_format_args< format_to_n_context< OutputIt, Char > > |
Enumerations | |
enum | { inline_buffer_size = 500 } |
enum | type { none, left, right, center, numeric } |
enum | type { none, minus, plus, space } |
enum | float_format : unsigned char { general, exp, fixed, hex } |
enum | arg_id_kind { none, index, name } |
Functions | |
template<typename T > | |
T | const_check (T value) |
template<typename Dest , typename Source > | |
Dest | bit_cast (const Source &source) |
bool | is_big_endian () |
fallback_uintptr | to_uintptr (const void *p) |
template<typename T > | |
constexpr T | max_value () |
template<typename T > | |
constexpr int | num_bits () |
template<> | |
constexpr int | num_bits< fallback_uintptr > () |
template<typename Char > | |
Char * | get_data (std::basic_string< Char > &s) |
template<typename Container > | |
Container::value_type * | get_data (Container &c) |
template<typename T > | |
T * | make_checked (T *p, std::size_t) |
template<typename Container , FMT_ENABLE_IF(is_contiguous< Container >::value) > | |
checked_ptr< typename Container::value_type > | reserve (std::back_insert_iterator< Container > &it, std::size_t n) |
template<typename Iterator > | |
Iterator & | reserve (Iterator &it, std::size_t) |
template<typename Char > | |
size_t | count_code_points (basic_string_view< Char > s) |
size_t | count_code_points (basic_string_view< char8_t > s) |
template<typename Char > | |
size_t | code_point_index (basic_string_view< Char > s, size_t n) |
size_t | code_point_index (basic_string_view< char8_t > s, size_t n) |
char8_t | to_char8_t (char c) |
template<typename OutChar , typename InputIt , typename OutputIt , FMT_ENABLE_IF(!needs_conversion< InputIt, OutChar >::value) > | |
OutputIt | copy_str (InputIt begin, InputIt end, OutputIt it) |
template<typename T > | |
constexpr bool | use_grisu () |
template<typename T , FMT_ENABLE_IF(std::numeric_limits< T >::is_signed) > | |
FMT_CONSTEXPR bool | is_negative (T value) |
int | count_digits (uint64_t n) |
template<unsigned BITS, typename UInt > | |
int | count_digits (UInt n) |
template<> | |
int | count_digits< 4 > (internal::fallback_uintptr n) |
template<typename Char > | |
FMT_API std::string | grouping_impl (locale_ref loc) |
template<typename Char > | |
std::string | grouping (locale_ref loc) |
template<> | |
std::string | grouping< wchar_t > (locale_ref loc) |
template<typename Char > | |
FMT_API Char | thousands_sep_impl (locale_ref loc) |
template<typename Char > | |
Char | thousands_sep (locale_ref loc) |
template<> | |
wchar_t | thousands_sep (locale_ref loc) |
template<typename Char > | |
FMT_API Char | decimal_point_impl (locale_ref loc) |
template<typename Char > | |
Char | decimal_point (locale_ref loc) |
template<> | |
wchar_t | decimal_point (locale_ref loc) |
template<typename UInt , typename Char , typename F > | |
Char * | format_decimal (Char *buffer, UInt value, int num_digits, F add_thousands_sep) |
template<typename Int > | |
constexpr int | digits10 () noexcept |
template<> | |
constexpr int | digits10< int128_t > () noexcept |
template<> | |
constexpr int | digits10< uint128_t > () noexcept |
template<typename Char , typename UInt , typename Iterator , typename F > | |
Iterator | format_decimal (Iterator out, UInt value, int num_digits, F add_thousands_sep) |
template<typename Char , typename It , typename UInt > | |
It | format_decimal (It out, UInt value, int num_digits) |
template<unsigned BASE_BITS, typename Char , typename UInt > | |
Char * | format_uint (Char *buffer, UInt value, int num_digits, bool upper=false) |
template<unsigned BASE_BITS, typename Char > | |
Char * | format_uint (Char *buffer, internal::fallback_uintptr n, int num_digits, bool=false) |
template<unsigned BASE_BITS, typename Char , typename It , typename UInt > | |
It | format_uint (It out, UInt value, int num_digits, bool upper=false) |
template<typename Char , typename It > | |
It | write_exponent (int exp, It it) |
template<typename T > | |
int | format_float (T value, int precision, float_specs specs, buffer< char > &buf) |
template<typename T > | |
int | snprintf_float (T value, int precision, float_specs specs, buffer< char > &buf) |
template<typename T > | |
T | promote_float (T value) |
double | promote_float (float value) |
template<typename Handler > | |
FMT_CONSTEXPR void | handle_int_type_spec (char spec, Handler &&handler) |
template<typename ErrorHandler = error_handler, typename Char > | |
FMT_CONSTEXPR float_specs | parse_float_type_spec (const basic_format_specs< Char > &specs, ErrorHandler &&eh={}) |
template<typename Char , typename Handler > | |
FMT_CONSTEXPR void | handle_char_specs (const basic_format_specs< Char > *specs, Handler &&handler) |
template<typename Char , typename Handler > | |
FMT_CONSTEXPR void | handle_cstring_type_spec (Char spec, Handler &&handler) |
template<typename Char , typename ErrorHandler > | |
FMT_CONSTEXPR void | check_string_type_spec (Char spec, ErrorHandler &&eh) |
template<typename Char , typename ErrorHandler > | |
FMT_CONSTEXPR void | check_pointer_type_spec (Char spec, ErrorHandler &&eh) |
template<typename Char > | |
FMT_CONSTEXPR bool | is_name_start (Char c) |
template<typename Char , typename ErrorHandler > | |
FMT_CONSTEXPR int | parse_nonnegative_int (const Char *&begin, const Char *end, ErrorHandler &&eh) |
template<template< typename > class Handler, typename FormatArg , typename ErrorHandler > | |
FMT_CONSTEXPR int | get_dynamic_spec (FormatArg arg, ErrorHandler eh) |
template<typename Context > | |
FMT_CONSTEXPR Context::format_arg | get_arg (Context &ctx, int id) |
template<typename Char , typename IDHandler > | |
FMT_CONSTEXPR const Char * | parse_arg_id (const Char *begin, const Char *end, IDHandler &&handler) |
template<typename Char , typename Handler > | |
FMT_CONSTEXPR const Char * | parse_align (const Char *begin, const Char *end, Handler &&handler) |
template<typename Char , typename Handler > | |
FMT_CONSTEXPR const Char * | parse_width (const Char *begin, const Char *end, Handler &&handler) |
template<typename Char , typename Handler > | |
FMT_CONSTEXPR const Char * | parse_precision (const Char *begin, const Char *end, Handler &&handler) |
template<typename Char , typename SpecHandler > | |
FMT_CONSTEXPR const Char * | parse_format_specs (const Char *begin, const Char *end, SpecHandler &&handler) |
template<bool IS_CONSTEXPR, typename T , typename Ptr = const T*> | |
FMT_CONSTEXPR bool | find (Ptr first, Ptr last, T value, Ptr &out) |
template<> | |
bool | find< false, char > (const char *first, const char *last, char value, const char *&out) |
template<bool IS_CONSTEXPR, typename Char , typename Handler > | |
FMT_CONSTEXPR void | parse_format_string (basic_string_view< Char > format_str, Handler &&handler) |
template<typename T , typename ParseContext > | |
FMT_CONSTEXPR const ParseContext::char_type * | parse_format_specs (ParseContext &ctx) |
template<typename Char , typename ErrorHandler , typename... Args> | |
FMT_CONSTEXPR bool | do_check_format_string (basic_string_view< Char > s, ErrorHandler eh=ErrorHandler()) |
template<typename... , typename S , FMT_ENABLE_IF(is_compile_string< S >::value) > | |
void | check_format_string (S) |
template<template< typename > class Handler, typename Context > | |
void | handle_dynamic_spec (int &value, arg_ref< typename Context::char_type > ref, Context &ctx) |
FMT_API void | format_system_error (internal::buffer< char > &out, int error_code, string_view message) FMT_NOEXCEPT |
FMT_API void | report_system_error (int error_code, string_view message) FMT_NOEXCEPT |
FMT_FORMAT_AS (signed char, int) | |
FMT_FORMAT_AS (unsigned char, unsigned) | |
FMT_FORMAT_AS (short, int) | |
FMT_FORMAT_AS (long, long long) | |
FMT_FORMAT_AS (unsigned long, unsigned long long) | |
FMT_FORMAT_AS (Char *, const Char *) | |
FMT_FORMAT_AS (std::basic_string< Char >, basic_string_view< Char >) | |
FMT_FORMAT_AS (std::nullptr_t, const void *) | |
FMT_FORMAT_AS (internal::std_string_view< Char >, basic_string_view< Char >) | |
template<typename Char , typename ErrorHandler > | |
FMT_CONSTEXPR void | advance_to (basic_format_parse_context< Char, ErrorHandler > &ctx, const Char *p) |
template<typename ArgFormatter , typename Char , typename Context > | |
Context::iterator | vformat_to (typename ArgFormatter::range out, basic_string_view< Char > format_str, basic_format_args< Context > args, internal::locale_ref loc=internal::locale_ref()) |
template<typename T > | |
const void * | ptr (const T *p) |
template<typename T > | |
const void * | ptr (const std::unique_ptr< T > &p) |
template<typename T > | |
const void * | ptr (const std::shared_ptr< T > &p) |
template<typename It > | |
arg_join< It, char > | join (It begin, It end, string_view sep) |
template<typename It > | |
arg_join< It, wchar_t > | join (It begin, It end, wstring_view sep) |
template<typename Range > | |
arg_join< internal::iterator_t< const Range >, char > | join (const Range &range, string_view sep) |
template<typename Range > | |
arg_join< internal::iterator_t< const Range >, wchar_t > | join (const Range &range, wstring_view sep) |
template<typename T > | |
std::string | to_string (const T &value) |
template<typename T > | |
std::wstring | to_wstring (const T &value) |
template<typename Char , std::size_t SIZE> | |
std::basic_string< Char > | to_string (const basic_memory_buffer< Char, SIZE > &buf) |
template<typename S , typename Char = char_t<S>, FMT_ENABLE_IF(internal::is_string< S >::value) > | |
buffer_context< Char >::iterator | vformat_to (internal::buffer< Char > &buf, const S &format_str, basic_format_args< buffer_context< Char >> args) |
template<typename S , typename... Args, std::size_t SIZE = inline_buffer_size, typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>> | |
buffer_context< Char >::iterator | format_to (basic_memory_buffer< Char, SIZE > &buf, const S &format_str, Args &&... args) |
template<typename S , typename OutputIt , typename... Args, FMT_ENABLE_IF( internal::is_output_iterator< OutputIt >::value && !internal::is_contiguous_back_insert_iterator< OutputIt >::value) > | |
OutputIt | vformat_to (OutputIt out, const S &format_str, format_args_t< OutputIt, char_t< S >> args) |
template<typename OutputIt , typename S , typename... Args, FMT_ENABLE_IF( internal::is_output_iterator< OutputIt >::value && !internal::is_contiguous_back_insert_iterator< OutputIt >::value && internal::is_string< S >::value) > | |
OutputIt | format_to (OutputIt out, const S &format_str, Args &&... args) |
template<typename OutputIt , typename Char , typename... Args> | |
format_arg_store< format_to_n_context< OutputIt, Char >, Args... > | make_format_to_n_args (const Args &... args) |
template<typename OutputIt , typename Char , typename... Args, FMT_ENABLE_IF(internal::is_output_iterator< OutputIt >::value) > | |
format_to_n_result< OutputIt > | vformat_to_n (OutputIt out, std::size_t n, basic_string_view< Char > format_str, format_to_n_args< OutputIt, Char > args) |
template<typename OutputIt , typename S , typename... Args, FMT_ENABLE_IF(internal::is_string< S >::value && internal::is_output_iterator< OutputIt >::value) > | |
format_to_n_result< OutputIt > | format_to_n (OutputIt out, std::size_t n, const S &format_str, const Args &... args) |
template<typename... Args> | |
std::size_t | formatted_size (string_view format_str, const Args &... args) |
template<typename Char , FMT_ENABLE_IF(std::is_same< Char, wchar_t >::value) > | |
void | vprint (std::FILE *f, basic_string_view< Char > format_str, wformat_args args) |
template<typename Char , FMT_ENABLE_IF(std::is_same< Char, wchar_t >::value) > | |
void | vprint (basic_string_view< Char > format_str, wformat_args args) |
Variables | |
FMT_EXTERN template struct | basic_data< void > |
#define FMT_DEPRECATED_PERCENT 0 |
Definition at line 200 of file format.h.
Referenced by basic_writer< Range >::write().
#define FMT_FALLTHROUGH |
Definition at line 76 of file format.h.
Referenced by internal::parse_float_type_spec().
#define FMT_FORMAT_AS | ( | Type, | |
Base | |||
) |
#define FMT_FUNC |
Definition at line 3538 of file format.h.
Referenced by internal::decimal_point_impl(), formatter< internal::bigint >::format(), and report_system_error().
#define FMT_STRING | ( | s | ) | FMT_STRING_IMPL(s, ) |
#define FMT_STRING_IMPL | ( | s, | |
... | |||
) |
#define FMT_THROW | ( | x | ) | throw x |
Definition at line 94 of file format.h.
Referenced by internal::fmt_safe_duration_cast(), basic_printf_context< OutputIt, Char >::format(), formatter< internal::bigint >::format(), internal::fwrite_fully(), gmtime(), localtime(), error_handler::on_error(), formatter< std::chrono::duration< Rep, Period >, Char >::spec_handler::on_error(), basic_writer< Range >::int_writer< Int, Specs >::on_error(), text_style::operator &=(), printf_precision_handler::operator()(), printf_width_handler< Char >::operator()(), text_style::operator|=(), internal::parse_chrono_format(), buffered_file::print(), chrono_format_checker::report_no_date(), vprint(), and arg_formatter_base< Range >::write().
#define FMT_USE_GRISU 1 |
Definition at line 517 of file format.h.
Referenced by internal::use_grisu().
using align_t = align::type |
using FMT_DEPRECATED_ALIAS = internal::basic_writer<buffer_range<wchar_t> > |
using format_args_t = basic_format_args<format_context_t<OutputIt, Char> > |
using format_context_t = basic_format_context<OutputIt, Char> |
using format_specs = basic_format_specs<char> |
using format_to_n_args = basic_format_args<format_to_n_context<OutputIt, Char> > |
using format_to_n_context = format_context_t<internal::truncating_iterator<OutputIt>, Char> |
using memory_buffer = basic_memory_buffer<char> |
using sign_t = sign::type |
using wmemory_buffer = basic_memory_buffer<wchar_t> |
FMT_CONSTEXPR void advance_to | ( | basic_format_parse_context< Char, ErrorHandler > & | ctx, |
const Char * | p | ||
) |
Definition at line 3085 of file format.h.
References basic_format_parse_context< Char, ErrorHandler >::advance_to(), and basic_format_parse_context< Char, ErrorHandler >::begin().
Referenced by format_string_checker< Char, ErrorHandler, Args >::on_format_specs(), format_handler< ArgFormatter, Char, Context >::on_format_specs(), format_handler< ArgFormatter, Char, Context >::on_replacement_field(), and internal::cf::vformat_to().
FMT_FORMAT_AS | ( | signed | char, |
int | |||
) |
FMT_FORMAT_AS | ( | unsigned | char, |
unsigned | |||
) |
FMT_FORMAT_AS | ( | short | , |
int | |||
) |
FMT_FORMAT_AS | ( | long | , |
long | long | ||
) |
FMT_FORMAT_AS | ( | unsigned | long, |
unsigned long | long | ||
) |
FMT_FORMAT_AS | ( | Char * | , |
const Char * | |||
) |
FMT_FORMAT_AS | ( | std::basic_string< Char > | , |
basic_string_view< Char > | |||
) |
FMT_FORMAT_AS | ( | std::nullptr_t | , |
const void * | |||
) |
FMT_FORMAT_AS | ( | internal::std_string_view< Char > | , |
basic_string_view< Char > | |||
) |
FMT_API void format_system_error | ( | internal::buffer< char > & | out, |
int | error_code, | ||
string_view | message | ||
) |
Formats an error returned by an operating system or a language runtime, for example a file opening error, and writes it to out in the following form:
.. parsed-literal:: <message>*: *<system-message>*
where *<message>* is the passed message and *<system-message>* is the system message corresponding to the error code. error_code* is a system error code as given by errno
. If error_code is not a valid error code such as -1, the system message may look like "Unknown error -1" and is platform-dependent.
Definition at line 1338 of file format-inl.h.
References FMT_CATCH, FMT_TRY, internal::format_error_code(), inline_buffer_size, buffer< T >::resize(), internal::safe_strerror(), buffer< T >::size(), and basic_writer< Range >::write().
Referenced by system_error::error_code(), system_error::init(), and report_system_error().
buffer_context<Char>::iterator format_to | ( | basic_memory_buffer< Char, SIZE > & | buf, |
const S & | format_str, | ||
Args &&... | args | ||
) |
Definition at line 3280 of file format.h.
References internal::check_format_string(), internal::to_string_view(), and internal::vformat_to().
Referenced by formatted_size().
OutputIt format_to | ( | OutputIt | out, |
const S & | format_str, | ||
Args &&... | args | ||
) |
Formats arguments, writes the result to the output iterator out
and returns the iterator past the end of the output range.
Example**::
std::vector<char> out; fmt::format_to(std::back_inserter(out), "{}", 42);
Definition at line 3321 of file format.h.
References internal::check_format_string(), internal::to_string_view(), and internal::vformat_to().
format_to_n_result<OutputIt> format_to_n | ( | OutputIt | out, |
std::size_t | n, | ||
const S & | format_str, | ||
const Args &... | args | ||
) |
Formats arguments, writes up to n
characters of the result to the output iterator out
and returns the total output size and the iterator past the end of the output range.
Definition at line 3369 of file format.h.
References internal::check_format_string(), internal::to_string_view(), and vformat_to_n().
std::size_t formatted_size | ( | string_view | format_str, |
const Args &... | args | ||
) |
Returns the number of characters in the output of format(format_str, args...)
.
Definition at line 3392 of file format.h.
References format_to().
arg_join<It, char> join | ( | It | begin, |
It | end, | ||
string_view | sep | ||
) |
arg_join<It, wchar_t> join | ( | It | begin, |
It | end, | ||
wstring_view | sep | ||
) |
arg_join<internal::iterator_t<const Range>, char> join | ( | const Range & | range, |
string_view | sep | ||
) |
arg_join<internal::iterator_t<const Range>, wchar_t> join | ( | const Range & | range, |
wstring_view | sep | ||
) |
format_arg_store<format_to_n_context<OutputIt, Char>, Args...> make_format_to_n_args | ( | const Args &... | args | ) |
Definition at line 3344 of file format.h.
References FMT_ENABLE_IF.
const void* ptr | ( | const T * | p | ) |
Definition at line 3159 of file format.h.
Referenced by format_int::format_decimal(), format_string_compiler< Char, PartHandler >::on_replacement_field(), and internal::parse_chrono_format().
FMT_API void report_system_error | ( | int | error_code, |
string_view | message | ||
) |
Referenced by system_error::error_code().
std::string to_string | ( | const T & | value | ) |
Converts value to std::string
using the default format for type T. It doesn't support user-defined types with custom formatters.
Example**::
#include <fmt/format.h>
std::string answer = fmt::to_string(42);
Definition at line 3245 of file format.h.
References format().
Referenced by compiled_format< S, Args >::compiled_format(), format(), formatter< internal::bigint >::format(), system_error::init(), vformat(), internal::vformat(), and vsprintf().
std::basic_string<Char> to_string | ( | const basic_memory_buffer< Char, SIZE > & | buf | ) |
Definition at line 3257 of file format.h.
References buffer< T >::data(), and buffer< T >::size().
std::wstring to_wstring | ( | const T & | value | ) |
Context::iterator vformat_to | ( | typename ArgFormatter::range | out, |
basic_string_view< Char > | format_str, | ||
basic_format_args< Context > | args, | ||
internal::locale_ref | loc = internal::locale_ref() |
||
) |
Formats arguments and writes the output to the range.
Definition at line 3147 of file format.h.
References format_handler< ArgFormatter, Char, Context >::context.
buffer_context<Char>::iterator vformat_to | ( | internal::buffer< Char > & | buf, |
const S & | format_str, | ||
basic_format_args< buffer_context< Char >> | args | ||
) |
Definition at line 3272 of file format.h.
References inline_buffer_size, internal::to_string_view(), and internal::vformat_to().
OutputIt vformat_to | ( | OutputIt | out, |
const S & | format_str, | ||
format_args_t< OutputIt, char_t< S >> | args | ||
) |
Definition at line 3298 of file format.h.
References FMT_ENABLE_IF, and internal::to_string_view().
format_to_n_result<OutputIt> vformat_to_n | ( | OutputIt | out, |
std::size_t | n, | ||
basic_string_view< Char > | format_str, | ||
format_to_n_args< OutputIt, Char > | args | ||
) |
Definition at line 3351 of file format.h.
References FMT_ENABLE_IF, and internal::vformat_to().
Referenced by format_to_n().
void vprint | ( | std::FILE * | f, |
basic_string_view< Char > | format_str, | ||
wformat_args | args | ||
) |
Definition at line 3397 of file format.h.
References buffer< T >::data(), FMT_THROW, buffer< T >::push_back(), and internal::vformat_to().
Referenced by vprint().
void vprint | ( | basic_string_view< Char > | format_str, |
wformat_args | args | ||
) |
Definition at line 3407 of file format.h.
References FMT_CONSTEXPR, FMT_CONSTEXPR_DECL, FMT_END_NAMESPACE, format(), and vprint().