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

View file

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