0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

ircd: Add missing globular_imatch.

This commit is contained in:
Jason Volk 2020-04-26 16:38:01 -07:00
parent 3c69f85e66
commit 9bbc5834af
3 changed files with 37 additions and 14 deletions

View file

@ -42,20 +42,11 @@ struct ircd::globular_iequals
/// than globular_equals. Case insensitive.
struct ircd::globular_imatch
{
string_view expr;
string_view a;
template<class A>
bool operator()(A&& a) const noexcept
{
const globular_iequals globular_iequals
{
expr, std::forward<A>(a)
};
bool operator()(const string_view &b) const noexcept;
return bool(globular_iequals);
}
globular_imatch(const string_view &expr = {})
:expr{expr}
globular_imatch(const string_view &expr)
:a{expr}
{}
};

View file

@ -53,3 +53,35 @@ const noexcept
return iequals(a.substr(ap), b.substr(bp));
}
bool
ircd::globular_imatch::operator()(const string_view &b)
const noexcept
{
size_t ap(0), bp(0);
while(ap < a.size() && bp < b.size())
{
const auto ca(tolower(a.at(ap))), cb(tolower(b.at(bp)));
const auto globa(ca == '*');
const auto wilda(ca == '?');
if(!globa && !wilda && ca != cb)
return false;
if(globa && ap + 1 >= a.size())
break;
if(globa && cb == tolower(a.at(ap + 1)))
ap += 2;
if(!globa)
++ap;
++bp;
}
if(bp < b.size() && !a.empty() && a.back() == '*')
return true;
return iequals(a.substr(ap), b.substr(bp));
}

View file

@ -446,7 +446,7 @@ command__read(const mutable_buffer &buf,
// for_each returns true if it didn't break from the loop, which means
// no match and skip actions for this room.
if(match.expr != "*")
if(match.a != "*")
if(room_tags.for_each(without_match))
return;