0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd:Ⓜ️🆔 Tighten exception spec on boolean validators; tweak test grammar.

This commit is contained in:
Jason Volk 2018-03-03 04:05:43 -08:00
parent 6db4b083a8
commit d0ef714179
2 changed files with 18 additions and 10 deletions

View file

@ -19,8 +19,8 @@ namespace ircd::m
IRCD_M_EXCEPTION(INVALID_MXID, BAD_SIGIL, http::BAD_REQUEST)
bool my(const id &);
bool is_sigil(const char &c);
bool has_sigil(const string_view &);
bool is_sigil(const char &c) noexcept;
bool has_sigil(const string_view &) noexcept;
}
/// (Appendix 4.2) Common Identifier Format
@ -206,7 +206,7 @@ namespace ircd::m
// Checks
bool valid(const id::sigil &, const string_view &) noexcept;
bool valid_local(const id::sigil &, const string_view &); // Local part is valid
bool valid_local(const id::sigil &, const string_view &) noexcept; // Local part is valid
bool valid_local_only(const id::sigil &, const string_view &) noexcept; // No :host
void validate(const id::sigil &, const string_view &); // valid() | throws
}

View file

@ -558,11 +558,12 @@ noexcept try
{
static const auto test
{
&lit(char(sigil)) > &m::id::parser.prefix > &eoi
m::id::parser.prefix
};
const char *start{begin(id)};
return qi::parse(start, end(id), test);
const char *const stop{end(id)};
return id.at(0) == sigil && qi::parse(start, stop, test) && start == stop;
}
catch(...)
{
@ -572,29 +573,36 @@ catch(...)
bool
ircd::m::valid_local(const id::sigil &sigil,
const string_view &id)
noexcept try
{
static const auto test
{
&lit(char(sigil)) > m::id::parser.prefix
m::id::parser.prefix
};
const char *start{id.data()};
return qi::parse(start, end(id), test);
const char *start{begin(id)};
const char *const stop{end(id)};
return id.at(0) == sigil && qi::parse(start, stop, test);
}
catch(...)
{
return false;
}
bool
ircd::m::has_sigil(const string_view &s)
try
noexcept try
{
return is_sigil(s.at(0));
}
catch(const std::out_of_range &e)
catch(...)
{
return false;
}
bool
ircd::m::is_sigil(const char &c)
noexcept
{
const char *start{&c};
const char *const stop{start + 1};