mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::fmt: Add syntax for specifier forced-termination.
This is available for a particular corner case due to our use of full- word format specifiers. Case: "%couch" is that %c followed by ouch, or is that the handled format specifier '%couch' ? If '%couch' is not registered there is no fallback to finding '%c' (maybe one day), so in this case one must write "%c$ouch" and '%c' becomes the specifier and the output for 'p' will be "pouch" and for "%c$$ouch" the output will be "p$ouch."
This commit is contained in:
parent
d82c013552
commit
21aacf6509
2 changed files with 12 additions and 1 deletions
|
@ -35,6 +35,7 @@ IRCD_EXCEPTION(error, illegal);
|
|||
// module/internal API
|
||||
//
|
||||
extern const char SPECIFIER;
|
||||
extern const char SPECIFIER_TERMINATOR;
|
||||
|
||||
using ptrs = std::vector<const void *>;
|
||||
using types = std::vector<std::type_index>;
|
||||
|
|
12
ircd/fmt.cc
12
ircd/fmt.cc
|
@ -43,6 +43,11 @@ const char SPECIFIER
|
|||
'%'
|
||||
};
|
||||
|
||||
const char SPECIFIER_TERMINATOR
|
||||
{
|
||||
'$'
|
||||
};
|
||||
|
||||
std::map<std::string, specifier *> _specifiers;
|
||||
|
||||
template<class generator> bool generate_string(char *&out, const generator &, const arg &);
|
||||
|
@ -132,6 +137,7 @@ namespace parse
|
|||
:qi::grammar<it, top>
|
||||
{
|
||||
qi::rule<it> specsym;
|
||||
qi::rule<it> specterm;
|
||||
qi::rule<it, std::string()> name;
|
||||
qi::rule<it, fmt::spec> spec;
|
||||
|
||||
|
@ -155,9 +161,13 @@ fmt::parse::grammar<it, top>::grammar(qi::rule<it, top> &top_rule)
|
|||
{
|
||||
lit(SPECIFIER)
|
||||
}
|
||||
,specterm
|
||||
{
|
||||
char_(SPECIFIER_TERMINATOR)
|
||||
}
|
||||
,name
|
||||
{
|
||||
repeat(1,14)[char_("A-Za-z")]
|
||||
repeat(1,14)[char_("A-Za-z")] >> omit[-specterm]
|
||||
}
|
||||
{
|
||||
spec %= specsym >> -char_("+-") >> -int_ >> name[([]
|
||||
|
|
Loading…
Reference in a new issue