From 8b84a76d5def16357d40bfa8e1c860ec40f52fce Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 6 Nov 2014 06:13:11 -0800 Subject: [PATCH] Make ci_equal a function --- src/beast/beast/utility/ci_char_traits.h | 84 +++--------------------- src/ripple/nodestore/impl/Manager.cpp | 4 +- 2 files changed, 11 insertions(+), 77 deletions(-) diff --git a/src/beast/beast/utility/ci_char_traits.h b/src/beast/beast/utility/ci_char_traits.h index 1b0715202..b7243052f 100644 --- a/src/beast/beast/utility/ci_char_traits.h +++ b/src/beast/beast/utility/ci_char_traits.h @@ -47,83 +47,19 @@ struct ci_less } }; -/** Case-insensitive function object for performing equal to comparisons. */ -struct ci_equal_to +/** Returns `true` if strings are case-insensitive equal. */ +template +bool +ci_equal(String const& lhs, String const& rhs) { - static bool const is_transparent = true; - - template - bool - operator() (String const& lhs, String const& rhs) const - { - typedef typename String::value_type char_type; - return std::equal (lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), - [] (char_type lhs, char_type rhs) - { - return std::tolower(lhs) == std::tolower(rhs); - } - ); - } -}; - -// DEPRECATED VFALCO This causes far more problems than it solves! -// -/** Case insensitive character traits. */ -struct ci_char_traits : std::char_traits -{ - static - bool - eq (char c1, char c2) - { - return ::toupper(c1) == - ::toupper(c2); - } - - static - bool - ne (char c1, char c2) - { - return ::toupper(c1) != - ::toupper(c2); - } - - static - bool - lt (char c1, char c2) - { - return ::toupper(c1) < - ::toupper(c2); - } - - static - int - compare (char const* s1, char const* s2, std::size_t n) - { - while (n-- > 0) + typedef typename String::value_type char_type; + return std::equal (lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), + [] (char_type lhs, char_type rhs) { - auto const comp ( - int(::toupper(*s1++)) - - int(::toupper(*s2++))); - if (comp != 0) - return comp; + return std::tolower(lhs) == std::tolower(rhs); } - return 0; - } - - static - char const* - find (char const* s, int n, char a) - { - auto const ua (::toupper(a)); - for (;n--;) - { - if (::toupper(*s) == ua) - return s; - s++; - } - return nullptr; - } -}; + ); +} } diff --git a/src/ripple/nodestore/impl/Manager.cpp b/src/ripple/nodestore/impl/Manager.cpp index 0972b4f25..91953c315 100644 --- a/src/ripple/nodestore/impl/Manager.cpp +++ b/src/ripple/nodestore/impl/Manager.cpp @@ -70,12 +70,10 @@ public: Factory* find (std::string const& name) const { - beast::ci_equal_to casecmp; - for (List::const_iterator iter (m_list.begin ()); iter != m_list.end (); ++iter) { - if (casecmp ((*iter)->getName(), name)) + if (beast::ci_equal ((*iter)->getName(), name)) return iter->get(); } return nullptr;