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:
parent
d2df4ca02d
commit
1ab3489977
1 changed files with 34 additions and 2 deletions
36
ircd/fmt.cc
36
ircd/fmt.cc
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue