From c88dc6904b5162b05a7fb72c551798a74d2dc469 Mon Sep 17 00:00:00 2001 From: rbrugo Date: Tue, 17 Mar 2020 13:21:41 +0100 Subject: [PATCH] Reused `specs` field instead of `precision` and `type` --- src/include/units/format.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/include/units/format.h b/src/include/units/format.h index 27cec7f9..cb8af25a 100644 --- a/src/include/units/format.h +++ b/src/include/units/format.h @@ -169,8 +169,6 @@ private: using arg_ref_type = fmt::internal::arg_ref; fmt::basic_format_specs specs; - int precision = -1; - char type = '\0'; bool quantity_value = false; bool quantity_unit = false; arg_ref_type width_ref; @@ -207,12 +205,12 @@ private: constexpr void on_space() { f.specs.sign = fmt::sign::space; } constexpr void on_align(align_t align) { f.specs.align = align; } constexpr void on_width(int width) { f.specs.width = width; } - constexpr void on_precision(int precision) { f.precision = precision; } + constexpr void on_precision(int precision) { f.specs.precision = precision; } constexpr void on_type(char type) { constexpr auto good_types = std::string_view{"aAbBcdeEfFgGopsxX"}; if (good_types.find(type) != std::string_view::npos) { - f.type = type; + f.specs.type = type; } } constexpr void end_precision() {} @@ -320,12 +318,12 @@ public: // process dynamic width and precision fmt::internal::handle_dynamic_spec(specs.width, width_ref, ctx); - fmt::internal::handle_dynamic_spec(precision, precision_ref, ctx); + fmt::internal::handle_dynamic_spec(specs.precision, precision_ref, ctx); // deal with quantity content if(begin == end || *begin == '}') { // default format should print value followed by the unit separated with 1 space - out = units::detail::format_units_quantity_value(out, q.count(), specs.sign, precision, type); + out = units::detail::format_units_quantity_value(out, q.count(), specs.sign, specs.precision, specs.type); constexpr auto symbol = units::detail::unit_text(); if(symbol.size()) { *out++ = CharT(' '); @@ -334,7 +332,7 @@ public: } else { // user provided format - units::detail::units_formatter f(out, q, specs.sign, precision, type); + units::detail::units_formatter f(out, q, specs.sign, specs.precision, specs.type); parse_units_format(begin, end, f); }