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:
parent
389af728c4
commit
7eff71b9a3
2 changed files with 21 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
22
ircd/m/id.cc
22
ircd/m/id.cc
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue