mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 03:17:53 +00:00
core_format_specs -> sprintf_specs
This commit is contained in:
parent
5488d0b53a
commit
79209598f5
@ -754,7 +754,7 @@ FMT_API bool grisu_format(Double value, buffer<char>& buf, int precision,
|
||||
|
||||
template <typename Double>
|
||||
char* sprintf_format(Double value, internal::buffer<char>& buf,
|
||||
core_format_specs specs) {
|
||||
sprintf_specs specs) {
|
||||
// Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
|
||||
FMT_ASSERT(buf.capacity() != 0, "empty buffer");
|
||||
|
||||
|
@ -954,38 +954,6 @@ using format_specs = basic_format_specs<char>;
|
||||
|
||||
namespace internal {
|
||||
|
||||
struct core_format_specs {
|
||||
int precision;
|
||||
char type;
|
||||
bool alt : 1;
|
||||
|
||||
template <typename Char>
|
||||
constexpr core_format_specs(basic_format_specs<Char> specs)
|
||||
: precision(specs.precision), type(specs.type), alt(specs.alt) {}
|
||||
|
||||
constexpr bool has_precision() const { return precision >= 0; }
|
||||
};
|
||||
|
||||
namespace grisu_options {
|
||||
enum { fixed = 1, grisu3 = 2 };
|
||||
}
|
||||
|
||||
// Formats value using the Grisu algorithm:
|
||||
// https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
|
||||
template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))>
|
||||
FMT_API bool grisu_format(Double, buffer<char>&, int, unsigned, int&);
|
||||
template <typename Double, FMT_ENABLE_IF(sizeof(Double) != sizeof(uint64_t))>
|
||||
inline bool grisu_format(Double, buffer<char>&, int, unsigned, int&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct gen_digits_params {
|
||||
int num_digits;
|
||||
bool fixed;
|
||||
bool upper;
|
||||
bool trailing_zeros;
|
||||
};
|
||||
|
||||
// Writes the exponent exp in the form "[+-]d{2,3}" to buffer.
|
||||
template <typename Char, typename It> It write_exponent(int exp, It it) {
|
||||
FMT_ASSERT(-1000 < exp && exp < 1000, "exponent out of range");
|
||||
@ -1009,6 +977,13 @@ template <typename Char, typename It> It write_exponent(int exp, It it) {
|
||||
return it;
|
||||
}
|
||||
|
||||
struct gen_digits_params {
|
||||
int num_digits;
|
||||
bool fixed;
|
||||
bool upper;
|
||||
bool trailing_zeros;
|
||||
};
|
||||
|
||||
// The number is given as v = digits * pow(10, exp).
|
||||
template <typename Char, typename It>
|
||||
It grisu_prettify(const char* digits, int size, int exp, It it,
|
||||
@ -1072,8 +1047,33 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
|
||||
return it;
|
||||
}
|
||||
|
||||
namespace grisu_options {
|
||||
enum { fixed = 1, grisu3 = 2 };
|
||||
}
|
||||
|
||||
// Formats value using the Grisu algorithm:
|
||||
// https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
|
||||
template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))>
|
||||
FMT_API bool grisu_format(Double, buffer<char>&, int, unsigned, int&);
|
||||
template <typename Double, FMT_ENABLE_IF(sizeof(Double) != sizeof(uint64_t))>
|
||||
inline bool grisu_format(Double, buffer<char>&, int, unsigned, int&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct sprintf_specs {
|
||||
int precision;
|
||||
char type;
|
||||
bool alt : 1;
|
||||
|
||||
template <typename Char>
|
||||
constexpr sprintf_specs(basic_format_specs<Char> specs)
|
||||
: precision(specs.precision), type(specs.type), alt(specs.alt) {}
|
||||
|
||||
constexpr bool has_precision() const { return precision >= 0; }
|
||||
};
|
||||
|
||||
template <typename Double>
|
||||
char* sprintf_format(Double, internal::buffer<char>&, core_format_specs);
|
||||
char* sprintf_format(Double, internal::buffer<char>&, sprintf_specs);
|
||||
|
||||
template <typename Handler>
|
||||
FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) {
|
||||
|
@ -36,10 +36,10 @@ template FMT_API format_context::iterator internal::vformat_to(
|
||||
internal::buffer<char>&, string_view, basic_format_args<format_context>);
|
||||
|
||||
template FMT_API char* internal::sprintf_format(double, internal::buffer<char>&,
|
||||
core_format_specs);
|
||||
sprintf_specs);
|
||||
template FMT_API char* internal::sprintf_format(long double,
|
||||
internal::buffer<char>&,
|
||||
core_format_specs);
|
||||
sprintf_specs);
|
||||
|
||||
// Explicit instantiations for wchar_t.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user