mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 20:54:28 +02:00
Reused specs
field instead of precision
and type
This commit is contained in:
@@ -169,8 +169,6 @@ private:
|
|||||||
using arg_ref_type = fmt::internal::arg_ref<CharT>;
|
using arg_ref_type = fmt::internal::arg_ref<CharT>;
|
||||||
|
|
||||||
fmt::basic_format_specs<CharT> specs;
|
fmt::basic_format_specs<CharT> specs;
|
||||||
int precision = -1;
|
|
||||||
char type = '\0';
|
|
||||||
bool quantity_value = false;
|
bool quantity_value = false;
|
||||||
bool quantity_unit = false;
|
bool quantity_unit = false;
|
||||||
arg_ref_type width_ref;
|
arg_ref_type width_ref;
|
||||||
@@ -207,12 +205,12 @@ private:
|
|||||||
constexpr void on_space() { f.specs.sign = fmt::sign::space; }
|
constexpr void on_space() { f.specs.sign = fmt::sign::space; }
|
||||||
constexpr void on_align(align_t align) { f.specs.align = align; }
|
constexpr void on_align(align_t align) { f.specs.align = align; }
|
||||||
constexpr void on_width(int width) { f.specs.width = width; }
|
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 void on_type(char type)
|
||||||
{
|
{
|
||||||
constexpr auto good_types = std::string_view{"aAbBcdeEfFgGopsxX"};
|
constexpr auto good_types = std::string_view{"aAbBcdeEfFgGopsxX"};
|
||||||
if (good_types.find(type) != std::string_view::npos) {
|
if (good_types.find(type) != std::string_view::npos) {
|
||||||
f.type = type;
|
f.specs.type = type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
constexpr void end_precision() {}
|
constexpr void end_precision() {}
|
||||||
@@ -320,12 +318,12 @@ public:
|
|||||||
|
|
||||||
// process dynamic width and precision
|
// process dynamic width and precision
|
||||||
fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>(specs.width, width_ref, ctx);
|
fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>(specs.width, width_ref, ctx);
|
||||||
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(precision, precision_ref, ctx);
|
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(specs.precision, precision_ref, ctx);
|
||||||
|
|
||||||
// deal with quantity content
|
// deal with quantity content
|
||||||
if(begin == end || *begin == '}') {
|
if(begin == end || *begin == '}') {
|
||||||
// default format should print value followed by the unit separated with 1 space
|
// 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<Dimension, Unit>();
|
constexpr auto symbol = units::detail::unit_text<Dimension, Unit>();
|
||||||
if(symbol.size()) {
|
if(symbol.size()) {
|
||||||
*out++ = CharT(' ');
|
*out++ = CharT(' ');
|
||||||
@@ -334,7 +332,7 @@ public:
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// user provided format
|
// 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);
|
parse_units_format(begin, end, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user