mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd: Use util::boolean for globular suite; apply noexcept; minor simplify.
This commit is contained in:
parent
70e32d9292
commit
71d6bd66c1
2 changed files with 16 additions and 42 deletions
|
@ -22,25 +22,17 @@ namespace ircd
|
||||||
/// and '?' characters and equality of the string expressions will be
|
/// and '?' characters and equality of the string expressions will be
|
||||||
/// determined.
|
/// determined.
|
||||||
struct ircd::globular_equals
|
struct ircd::globular_equals
|
||||||
|
:boolean
|
||||||
{
|
{
|
||||||
using is_transparent = std::true_type;
|
using is_transparent = std::true_type;
|
||||||
|
|
||||||
bool s;
|
bool operator()(const string_view &a, const string_view &b) const noexcept;
|
||||||
|
|
||||||
operator const bool &() const
|
|
||||||
{
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator()(const string_view &a, const string_view &b) const;
|
|
||||||
|
|
||||||
template<class A,
|
template<class A,
|
||||||
class B>
|
class B>
|
||||||
globular_equals(A&& a, B&& b)
|
globular_equals(A&& a, B&& b)
|
||||||
:s{operator()(std::forward<A>(a), std::forward<B>(b))}
|
:boolean{operator()(std::forward<A>(a), std::forward<B>(b))}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
globular_equals() = default;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Globular match. Similar to globular_equals but only one side of the
|
/// Globular match. Similar to globular_equals but only one side of the
|
||||||
|
@ -51,24 +43,19 @@ struct ircd::globular_equals
|
||||||
struct ircd::globular_match
|
struct ircd::globular_match
|
||||||
{
|
{
|
||||||
string_view expr;
|
string_view expr;
|
||||||
bool s;
|
|
||||||
|
|
||||||
operator const bool &() const
|
|
||||||
{
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator()(const string_view &a) const;
|
|
||||||
|
|
||||||
globular_match(const string_view &expr)
|
|
||||||
:expr{expr}
|
|
||||||
{}
|
|
||||||
|
|
||||||
template<class A>
|
template<class A>
|
||||||
globular_match(const string_view &expr, A&& a)
|
bool operator()(A&& a) const noexcept
|
||||||
:expr{expr}
|
{
|
||||||
,s{operator()(std::forward<A>(a))}
|
const globular_equals globular_equals
|
||||||
{}
|
{
|
||||||
|
expr, std::forward<A>(a)
|
||||||
|
};
|
||||||
|
|
||||||
globular_match() = default;
|
return bool(globular_equals);
|
||||||
|
}
|
||||||
|
|
||||||
|
globular_match(const string_view &expr = {})
|
||||||
|
:expr{expr}
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::globular_equals::operator()(const string_view &a, const string_view &b)
|
ircd::globular_equals::operator()(const string_view &a, const string_view &b)
|
||||||
const
|
const noexcept
|
||||||
{
|
{
|
||||||
size_t ap(0), bp(0);
|
size_t ap(0), bp(0);
|
||||||
while(ap < a.size() && bp < b.size())
|
while(ap < a.size() && bp < b.size())
|
||||||
|
@ -53,16 +53,3 @@ const
|
||||||
|
|
||||||
return iequals(a.substr(ap), b.substr(bp));
|
return iequals(a.substr(ap), b.substr(bp));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// globular_match
|
|
||||||
//
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::globular_match::operator()(const string_view &a)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
//TODO: optimize.
|
|
||||||
const globular_equals globular_equals(expr, a);
|
|
||||||
return bool(globular_equals);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue