mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 10:08:56 +02:00
ircd::rfc1459: Replace gather() with charset() for use with spirit char_().
This commit is contained in:
parent
581ca84439
commit
1a367399d3
|
@ -73,6 +73,10 @@ namespace character
|
|||
// Get all characters for an attribute mask
|
||||
size_t gather(const attr &attr, uint8_t *const &buf, const size_t &max);
|
||||
std::string gather(const attr &attr);
|
||||
|
||||
// Like gather() but with special considerations for boost::spirit's char_()
|
||||
size_t charset(const attr &attr, uint8_t *const &buf, const size_t &max);
|
||||
std::string charset(const attr &attr);
|
||||
}
|
||||
|
||||
using character::is;
|
||||
|
|
|
@ -90,17 +90,17 @@ rfc1459::gen::grammar<it, top>::grammar(karma::rule<it, top> &top_rule)
|
|||
}
|
||||
,hostname // A valid hostname
|
||||
{
|
||||
+char_(gather(character::HOST)) // TODO: https://tools.ietf.org/html/rfc952
|
||||
+char_(charset(character::HOST)) // TODO: https://tools.ietf.org/html/rfc952
|
||||
,"hostname"
|
||||
}
|
||||
,user // A valid username
|
||||
{
|
||||
+char_(gather(character::USER))
|
||||
+char_(charset(character::USER))
|
||||
,"user"
|
||||
}
|
||||
,nick // A valid nickname, leading letter followed by any NICK chars
|
||||
{
|
||||
buffer[char_(gather(character::ALPHA)) << *char_(gather(character::NICK))]
|
||||
buffer[char_(charset(character::ALPHA)) << *char_(charset(character::NICK))]
|
||||
,"nick"
|
||||
}
|
||||
,prefix
|
||||
|
@ -132,12 +132,12 @@ rfc1459::gen::grammar<it, top>::grammar(karma::rule<it, top> &top_rule)
|
|||
}
|
||||
,command_numeric // \d\d\d numeric
|
||||
{
|
||||
repeat(3)[char_(gather(character::DIGIT))]
|
||||
repeat(3)[char_(charset(character::DIGIT))]
|
||||
,"command_numeric"
|
||||
}
|
||||
,command_alpha
|
||||
{
|
||||
+char_(gather(character::ALPHA))
|
||||
+char_(charset(character::ALPHA))
|
||||
,"command_alpha"
|
||||
}
|
||||
,command
|
||||
|
|
|
@ -108,7 +108,7 @@ grammar<it, top>::grammar(qi::rule<it, top> &top_rule)
|
|||
* This needs to be fixed.
|
||||
*/
|
||||
|
||||
//char_(gather(character::SPACE))
|
||||
//char_(charset(character::SPACE))
|
||||
lit(' ')
|
||||
,"space"
|
||||
}
|
||||
|
@ -134,12 +134,12 @@ grammar<it, top>::grammar(qi::rule<it, top> &top_rule)
|
|||
}
|
||||
,hostname // A valid hostname
|
||||
{
|
||||
+char_(gather(character::HOST)) // TODO: https://tools.ietf.org/html/rfc952
|
||||
+char_(charset(character::HOST)) // TODO: https://tools.ietf.org/html/rfc952
|
||||
,"hostname"
|
||||
}
|
||||
,user // A valid username
|
||||
{
|
||||
+char_(gather(character::USER))
|
||||
+char_(charset(character::USER))
|
||||
,"user"
|
||||
}
|
||||
,server // A valid servername
|
||||
|
@ -149,7 +149,7 @@ grammar<it, top>::grammar(qi::rule<it, top> &top_rule)
|
|||
}
|
||||
,nick // A valid nickname, leading letter followed by any NICK chars
|
||||
{
|
||||
char_(gather(character::ALPHA)) >> *char_(gather(character::NICK))
|
||||
char_(charset(character::ALPHA)) >> *char_(charset(character::NICK))
|
||||
,"nick"
|
||||
}
|
||||
,prefix // A valid prefix, required name, optional user and host (or empty placeholders)
|
||||
|
@ -174,12 +174,12 @@ grammar<it, top>::grammar(qi::rule<it, top> &top_rule)
|
|||
}
|
||||
,numeric // \d\d\d numeric
|
||||
{
|
||||
repeat(3)[char_(gather(character::DIGIT))]
|
||||
repeat(3)[char_(charset(character::DIGIT))]
|
||||
,"numeric"
|
||||
}
|
||||
,command // A command or numeric
|
||||
{
|
||||
+char_(gather(character::ALPHA)) | numeric
|
||||
+char_(charset(character::ALPHA)) | numeric
|
||||
,"command"
|
||||
}
|
||||
,line
|
||||
|
|
|
@ -381,7 +381,7 @@ const
|
|||
{
|
||||
karma::rule<char *, char()> printable
|
||||
{
|
||||
char_(rfc1459::character::gather(rfc1459::character::PRINT))
|
||||
char_(rfc1459::character::charset(rfc1459::character::PRINT))
|
||||
};
|
||||
|
||||
generator(): grammar{printable} {}
|
||||
|
@ -502,7 +502,7 @@ const
|
|||
{
|
||||
karma::rule<char *, std::string()> printable
|
||||
{
|
||||
*char_(rfc1459::character::gather(rfc1459::character::PRINT))
|
||||
*char_(rfc1459::character::charset(rfc1459::character::PRINT))
|
||||
};
|
||||
|
||||
generator(): grammar{printable} {}
|
||||
|
|
|
@ -238,6 +238,33 @@ const
|
|||
host.empty();
|
||||
}
|
||||
|
||||
std::string
|
||||
rfc1459::character::charset(const attr &attr)
|
||||
{
|
||||
uint8_t buf[256];
|
||||
const size_t len(charset(attr, buf, sizeof(buf)));
|
||||
return { reinterpret_cast<const char *>(buf), len };
|
||||
}
|
||||
|
||||
size_t
|
||||
rfc1459::character::charset(const attr &attr,
|
||||
uint8_t *const &buf,
|
||||
const size_t &max)
|
||||
{
|
||||
const auto len(gather(attr, buf, max));
|
||||
std::sort(buf, buf + len, []
|
||||
(const uint8_t &a, const uint8_t &b)
|
||||
{
|
||||
// Ensure special char '-' is always at the front. Also preserve
|
||||
// the reverse ordering from gather() so NUL is always at the end.
|
||||
return a == '-'? true:
|
||||
b == '-'? false:
|
||||
a > b;
|
||||
});
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
std::string
|
||||
rfc1459::character::gather(const attr &attr)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue