diff --git a/src/beast/beast/utility/ci_char_traits.h b/src/beast/beast/utility/ci_char_traits.h index 056e08c9b..69f8736fc 100644 --- a/src/beast/beast/utility/ci_char_traits.h +++ b/src/beast/beast/utility/ci_char_traits.h @@ -24,8 +24,8 @@ #include // #include #include -#include #include +#include namespace beast { @@ -51,15 +51,15 @@ struct ci_less } }; -/** Returns `true` if strings are case-insensitive equal. */ -template -std::enable_if_t::value && - std::is_same::value, bool> -ci_equal(Lhs const& lhs, Rhs const& rhs) +namespace detail { + +inline +bool +ci_equal(std::pair lhs, + std::pair rhs) { - using std::begin; - using std::end; - return std::equal (begin(lhs), end(lhs), begin(rhs), end(rhs), + return std::equal (lhs.first, lhs.first + lhs.second, + rhs.first, rhs.first + rhs.second, [] (char lhs, char rhs) { return std::tolower(lhs) == std::tolower(rhs); @@ -67,6 +67,34 @@ ci_equal(Lhs const& lhs, Rhs const& rhs) ); } +template +inline +std::pair +view(const char (&s)[N]) +{ + return {s, N-1}; +} + +inline +std::pair +view(std::string const& s) +{ + return {s.data(), s.size()}; +} + +} + +/** Returns `true` if strings are case-insensitive equal. */ +template +inline +bool +ci_equal(String1 const& lhs, String2 const& rhs) +{ + using detail::view; + using detail::ci_equal; + return ci_equal(view(lhs), view(rhs)); +} + } #endif diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index b7b492948..7d7e51e6e 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -210,8 +210,7 @@ OverlayImpl::onHandoff (std::unique_ptr && ssl_bundle, if (std::find_if(types.begin(), types.end(), [](std::string const& s) { - return beast::ci_equal(s, - std::string("peer")); + return beast::ci_equal(s, "peer"); }) == types.end()) { handoff.moved = false;