refactor: parse_fill_align_width extracted as a standalone function

This commit is contained in:
Mateusz Pusz
2024-01-23 21:31:45 +01:00
parent 39d278a92e
commit a5c35a0cf6

View File

@@ -50,6 +50,20 @@ template<typename Char>
return it; return it;
} }
template<typename Char, typename Specs>
[[nodiscard]] constexpr const Char* parse_fill_align_width(MP_UNITS_STD_FMT::basic_format_parse_context<Char>& ctx,
const Char* begin, const Char* end, Specs& specs,
fmt_align default_align = fmt_align::none)
{
auto it = begin;
if (it == end || *it == '}') return it;
it = mp_units::detail::parse_align(it, end, specs, default_align);
if (it == end) return it;
return mp_units::detail::parse_dynamic_spec(it, end, specs.width, specs.width_ref, ctx);
}
template<typename Char, typename Handler> template<typename Char, typename Handler>
[[nodiscard]] constexpr const Char* parse_subentity_replacement_field(const Char* begin, const Char* end, [[nodiscard]] constexpr const Char* parse_subentity_replacement_field(const Char* begin, const Char* end,
Handler&& handler) Handler&& handler)
@@ -197,16 +211,11 @@ public:
constexpr auto parse(MP_UNITS_STD_FMT::basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) constexpr auto parse(MP_UNITS_STD_FMT::basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin())
{ {
const auto begin = ctx.begin(); const auto begin = ctx.begin();
auto it = begin, end = ctx.end(); auto end = ctx.end();
if (it == end || *it == '}') return it;
it = mp_units::detail::parse_align(it, end, specs_);
if (it == end) return it;
it = mp_units::detail::parse_dynamic_spec(it, end, specs_.width, specs_.width_ref, ctx);
if (it == end) return it;
auto it = parse_fill_align_width(ctx, begin, end, specs_);
fill_align_width_format_str_ = {begin, it}; fill_align_width_format_str_ = {begin, it};
if (it == end) return it;
format_checker checker; format_checker checker;
end = parse_unit_specs(it, end, checker); end = parse_unit_specs(it, end, checker);
@@ -415,17 +424,12 @@ class MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, Char> {
} }
public: public:
// parse quantity-format-specs
constexpr auto parse(MP_UNITS_STD_FMT::basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) constexpr auto parse(MP_UNITS_STD_FMT::basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin())
{ {
const auto begin = ctx.begin(); const auto begin = ctx.begin();
auto it = begin, end = ctx.end(); auto end = ctx.end();
if (it == end || *it == '}') return it;
it = mp_units::detail::parse_align(it, end, specs_, mp_units::detail::fmt_align::right); auto it = parse_fill_align_width(ctx, begin, end, specs_, mp_units::detail::fmt_align::right);
if (it == end) return it;
it = mp_units::detail::parse_dynamic_spec(it, end, specs_.width, specs_.width_ref, ctx);
if (it == end) return it; if (it == end) return it;
format_checker checker(ctx, format_str_lengths_); format_checker checker(ctx, format_str_lengths_);