mirror of
https://github.com/fmtlib/fmt.git
synced 2026-05-04 03:40:49 +02:00
Improve handling of format specs
This commit is contained in:
+1
-1
@@ -516,7 +516,7 @@ TEST(core_test, constexpr_parse_format_specs) {
|
||||
static_assert(parse_test_specs(".42").precision == 42, "");
|
||||
static_assert(parse_test_specs(".{42}").precision_ref.val.index == 42, "");
|
||||
static_assert(
|
||||
parse_test_specs("f").type == fmt::presentation_type::fixed_lower, "");
|
||||
parse_test_specs("f").type == fmt::presentation_type::fixed, "");
|
||||
}
|
||||
|
||||
struct test_format_string_handler {
|
||||
|
||||
+2
-2
@@ -439,7 +439,7 @@ const char* parse_scan_specs(const char* begin, const char* end,
|
||||
switch (to_ascii(*begin)) {
|
||||
// TODO: parse more scan format specifiers
|
||||
case 'x':
|
||||
specs.type = presentation_type::hex_lower;
|
||||
specs.type = presentation_type::hex;
|
||||
++begin;
|
||||
break;
|
||||
case '}':
|
||||
@@ -508,7 +508,7 @@ auto read_hex(scan_iterator it, T& value) -> scan_iterator {
|
||||
template <typename T, FMT_ENABLE_IF(std::is_unsigned<T>::value)>
|
||||
auto read(scan_iterator it, T& value, const format_specs<>& specs)
|
||||
-> scan_iterator {
|
||||
if (specs.type == presentation_type::hex_lower) return read_hex(it, value);
|
||||
if (specs.type == presentation_type::hex) return read_hex(it, value);
|
||||
return read(it, value);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -584,7 +584,7 @@ template <class charT> struct formatter<std::complex<double>, charT> {
|
||||
specs.precision, specs.precision_ref, ctx);
|
||||
auto fspecs = std::string();
|
||||
if (specs.precision > 0) fspecs = fmt::format(".{}", specs.precision);
|
||||
if (specs.type == presentation_type::fixed_lower) fspecs += 'f';
|
||||
if (specs.type == presentation_type::fixed) fspecs += 'f';
|
||||
auto real = fmt::format(ctx.locale().template get<std::locale>(),
|
||||
fmt::runtime("{:" + fspecs + "}"), c.real());
|
||||
auto imag = fmt::format(ctx.locale().template get<std::locale>(),
|
||||
|
||||
Reference in New Issue
Block a user