0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::fmt: Add a "%prefix" specifier which builds ":foo!bar@baz" from the arg.

This commit is contained in:
Jason Volk 2016-09-17 16:55:21 -07:00
parent a42765f0f3
commit 99ad299ef0

View file

@ -86,6 +86,17 @@ const host_specifier
"host"s
};
struct prefix_specifier
:specifier
{
bool operator()(char *&out, const size_t &max, const spec &, const arg &) const override;
using specifier::specifier;
}
const prefix_specifier
{
"prefix"s
};
struct string_specifier
:specifier
{
@ -474,6 +485,37 @@ const
return generate_string(out, maxwidth(max)[generator] | eps[throw_illegal], val);
}
bool
fmt::prefix_specifier::operator()(char *&out,
const size_t &max,
const spec &spec,
const arg &val)
const
{
using karma::eps;
using karma::maxwidth;
static const auto throw_illegal([]
{
throw illegal("Argument is not a valid IRC prefix");
});
const auto &ptr(get<0>(val));
const auto &type(get<1>(val));
if(type == typeid(rfc1459::pfx))
{
struct generator
:rfc1459::gen::grammar<char *, rfc1459::pfx>
{
generator(): grammar{grammar::prefix} {}
}
static const generator;
const auto &pfx(*reinterpret_cast<const rfc1459::pfx *>(ptr));
return karma::generate(out, maxwidth(max)[generator] | eps[throw_illegal], pfx);
}
else return false;
}
bool
fmt::host_specifier::operator()(char *&out,
const size_t &max,