Commit 79209598 authored by Victor Zverovich's avatar Victor Zverovich

core_format_specs -> sprintf_specs

parent 5488d0b5
...@@ -754,7 +754,7 @@ FMT_API bool grisu_format(Double value, buffer<char>& buf, int precision, ...@@ -754,7 +754,7 @@ FMT_API bool grisu_format(Double value, buffer<char>& buf, int precision,
template <typename Double> template <typename Double>
char* sprintf_format(Double value, internal::buffer<char>& buf, 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. // Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
FMT_ASSERT(buf.capacity() != 0, "empty buffer"); FMT_ASSERT(buf.capacity() != 0, "empty buffer");
......
...@@ -954,38 +954,6 @@ using format_specs = basic_format_specs<char>; ...@@ -954,38 +954,6 @@ using format_specs = basic_format_specs<char>;
namespace internal { 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. // Writes the exponent exp in the form "[+-]d{2,3}" to buffer.
template <typename Char, typename It> It write_exponent(int exp, It it) { template <typename Char, typename It> It write_exponent(int exp, It it) {
FMT_ASSERT(-1000 < exp && exp < 1000, "exponent out of range"); 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) { ...@@ -1009,6 +977,13 @@ template <typename Char, typename It> It write_exponent(int exp, It it) {
return 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). // The number is given as v = digits * pow(10, exp).
template <typename Char, typename It> template <typename Char, typename It>
It grisu_prettify(const char* digits, int size, int exp, It 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, ...@@ -1072,8 +1047,33 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
return 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> 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> template <typename Handler>
FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& 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( ...@@ -36,10 +36,10 @@ template FMT_API format_context::iterator internal::vformat_to(
internal::buffer<char>&, string_view, basic_format_args<format_context>); internal::buffer<char>&, string_view, basic_format_args<format_context>);
template FMT_API char* internal::sprintf_format(double, internal::buffer<char>&, 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, template FMT_API char* internal::sprintf_format(long double,
internal::buffer<char>&, internal::buffer<char>&,
core_format_specs); sprintf_specs);
// Explicit instantiations for wchar_t. // Explicit instantiations for wchar_t.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment