mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd: Add missing globular_imatch.
This commit is contained in:
parent
3c69f85e66
commit
9bbc5834af
3 changed files with 37 additions and 14 deletions
|
@ -42,20 +42,11 @@ struct ircd::globular_iequals
|
||||||
/// than globular_equals. Case insensitive.
|
/// than globular_equals. Case insensitive.
|
||||||
struct ircd::globular_imatch
|
struct ircd::globular_imatch
|
||||||
{
|
{
|
||||||
string_view expr;
|
string_view a;
|
||||||
|
|
||||||
template<class A>
|
bool operator()(const string_view &b) const noexcept;
|
||||||
bool operator()(A&& a) const noexcept
|
|
||||||
{
|
|
||||||
const globular_iequals globular_iequals
|
|
||||||
{
|
|
||||||
expr, std::forward<A>(a)
|
|
||||||
};
|
|
||||||
|
|
||||||
return bool(globular_iequals);
|
globular_imatch(const string_view &expr)
|
||||||
}
|
:a{expr}
|
||||||
|
|
||||||
globular_imatch(const string_view &expr = {})
|
|
||||||
:expr{expr}
|
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,3 +53,35 @@ const noexcept
|
||||||
|
|
||||||
return iequals(a.substr(ap), b.substr(bp));
|
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));
|
||||||
|
}
|
||||||
|
|
|
@ -446,7 +446,7 @@ command__read(const mutable_buffer &buf,
|
||||||
|
|
||||||
// for_each returns true if it didn't break from the loop, which means
|
// for_each returns true if it didn't break from the loop, which means
|
||||||
// no match and skip actions for this room.
|
// no match and skip actions for this room.
|
||||||
if(match.expr != "*")
|
if(match.a != "*")
|
||||||
if(room_tags.for_each(without_match))
|
if(room_tags.for_each(without_match))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue