string: simplify the lower/upper comparators

This commit is contained in:
Danny Robson 2019-10-10 15:12:15 +11:00
parent 5666a64e77
commit 2e16e8962b

View File

@ -228,14 +228,11 @@ namespace cruft::string::compare {
/// \tparam TransformV A character transform function /// \tparam TransformV A character transform function
template <char (*TransformV)(char) noexcept> template <char (*TransformV)(char) noexcept>
struct transform { struct transform {
template < template <typename ContainerT>
typename CharT, bool operator() (
typename = std::void_t< ContainerT const &a,
typename std::char_traits<CharT>::char_type ContainerT const &b
> ) const noexcept {
>
bool operator() (cruft::view<CharT const *> a, cruft::view<CharT const*> b)
{
if (a.size () != b.size ()) if (a.size () != b.size ())
return false; return false;
@ -255,15 +252,7 @@ namespace cruft::string::compare {
> >
bool operator() (CharT const *a, CharT const *b) const noexcept bool operator() (CharT const *a, CharT const *b) const noexcept
{ {
auto const *i = a; return (*this) (std::string_view (a), std::string_view (b));
auto const *j = b;
for ( ; *i && *j; ++i, ++j)
if (TransformV (*i) != TransformV (*j))
return false;
// Ensure we've reached the ends of both strings
return !*i && !*j;
} }
}; };