0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

ircd::fmt: Add width-aligned string format specifiers.

This commit is contained in:
Jason Volk 2018-05-31 10:00:46 -07:00
parent d2df4ca02d
commit 1ab3489977

View file

@ -749,7 +749,7 @@ const
bool bool
fmt::string_specifier::operator()(char *&out, fmt::string_specifier::operator()(char *&out,
const size_t &max, const size_t &max,
const spec &, const spec &spec,
const arg &val) const arg &val)
const const
{ {
@ -772,11 +772,43 @@ const
,"string" ,"string"
}; };
_r1_type width;
karma::rule<char *, const string_view &(ushort)> aligned_left
{
karma::left_align(width)[string]
,"left aligned"
};
karma::rule<char *, const string_view &(ushort)> aligned_right
{
karma::right_align(width)[string]
,"right aligned"
};
karma::rule<char *, const string_view &(ushort)> aligned_center
{
karma::center(width)[string]
,"center aligned"
};
generator() :generator::base_type{string} {} generator() :generator::base_type{string} {}
} }
static const generator; static const generator;
return generate_string(out, maxwidth(max)[generator] | eps[throw_illegal], val); const auto &mw(maxwidth(max));
static const auto &ep(eps[throw_illegal]);
if(!spec.width)
return generate_string(out, mw[generator] | ep, val);
if(spec.sign == '-')
{
const auto &g(generator.aligned_left(spec.width));
return generate_string(out, mw[g] | ep, val);
}
const auto &g(generator.aligned_right(spec.width));
return generate_string(out, mw[g] | ep, val);
} }
template<class generator> template<class generator>