0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd:Ⓜ️ Add function to check if and only if id is a valid localpart.

This commit is contained in:
Jason Volk 2018-03-03 02:34:42 -08:00
parent 389af728c4
commit 7eff71b9a3
2 changed files with 21 additions and 2 deletions

View file

@ -207,6 +207,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_only(const id::sigil &, const string_view &) noexcept; // No :host
void validate(const id::sigil &, const string_view &); // valid() | throws
}

View file

@ -30,6 +30,7 @@ namespace ircd::m
using qi::raw;
using qi::attr;
using qi::eps;
using qi::eoi;
using qi::attr_cast;
using karma::lit;
@ -546,6 +547,24 @@ catch(...)
return false;
}
bool
ircd::m::valid_local_only(const id::sigil &sigil,
const string_view &id)
noexcept try
{
static const auto test
{
&lit(char(sigil)) > &m::id::parser.prefix > &eoi
};
const char *start{begin(id)};
return qi::parse(start, end(id), test);
}
catch(...)
{
return false;
}
bool
ircd::m::valid_local(const id::sigil &sigil,
const string_view &id)
@ -556,8 +575,7 @@ ircd::m::valid_local(const id::sigil &sigil,
};
const char *start{id.data()};
const char *const stop{id.data() + id.size()};
return qi::parse(start, stop, test);
return qi::parse(start, end(id), test);
}
bool