diff --git a/string.hpp b/string.hpp index e3585408..9e14e132 100644 --- a/string.hpp +++ b/string.hpp @@ -302,6 +302,55 @@ namespace cruft { } +namespace cruft::string { + template + struct less { + bool operator() (char const *a, char const *b) const noexcept + { + for (; a && b; ++a, ++b) { + auto const &a_val = TransformV (*a); + auto const &b_val = TransformV (*b); + + if (a_val < b_val) + return true; + if (a_val > b_val) + return false; + } + + return a == nullptr && b != nullptr; + } + + bool operator() (std::string const &a, std::string const & b) const noexcept + { + return (*this) (std::string_view (a), std::string_view (b)); + } + + bool operator() (std::string_view a, std::string_view b) const noexcept + { + auto a_cursor = a.begin (); + auto b_cursor = b.begin (); + + for ( ; a_cursor != a.end () && b_cursor != b.end (); ++a_cursor, ++b_cursor) { + auto const &a_val = TransformV (*a_cursor); + auto const &b_val = TransformV (*b_cursor); + if (a_val < b_val) + return true; + if (a_val > b_val) + return false; + } + + + if (a_cursor == a.end () && b_cursor != b.end ()) + return true; + return false; + } + }; + + + using less_lower = less; +} + + namespace cruft::string::equality { /////////////////////////////////////////////////////////////////////////// /// A case comparator that tests equality on a string after a