mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
Fix beast::ci_equal
This commit is contained in:
@@ -24,8 +24,8 @@
|
|||||||
#include <beast/cxx14/type_traits.h> // <type_traits>
|
#include <beast/cxx14/type_traits.h> // <type_traits>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <locale>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
|
||||||
@@ -51,15 +51,15 @@ struct ci_less
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Returns `true` if strings are case-insensitive equal. */
|
namespace detail {
|
||||||
template <class Lhs, class Rhs>
|
|
||||||
std::enable_if_t<std::is_same<typename Lhs::value_type, char>::value &&
|
inline
|
||||||
std::is_same<typename Lhs::value_type, char>::value, bool>
|
bool
|
||||||
ci_equal(Lhs const& lhs, Rhs const& rhs)
|
ci_equal(std::pair<const char*, std::size_t> lhs,
|
||||||
|
std::pair<const char*, std::size_t> rhs)
|
||||||
{
|
{
|
||||||
using std::begin;
|
return std::equal (lhs.first, lhs.first + lhs.second,
|
||||||
using std::end;
|
rhs.first, rhs.first + rhs.second,
|
||||||
return std::equal (begin(lhs), end(lhs), begin(rhs), end(rhs),
|
|
||||||
[] (char lhs, char rhs)
|
[] (char lhs, char rhs)
|
||||||
{
|
{
|
||||||
return std::tolower(lhs) == std::tolower(rhs);
|
return std::tolower(lhs) == std::tolower(rhs);
|
||||||
@@ -67,6 +67,34 @@ ci_equal(Lhs const& lhs, Rhs const& rhs)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
inline
|
||||||
|
std::pair<const char*, std::size_t>
|
||||||
|
view(const char (&s)[N])
|
||||||
|
{
|
||||||
|
return {s, N-1};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
std::pair<const char*, std::size_t>
|
||||||
|
view(std::string const& s)
|
||||||
|
{
|
||||||
|
return {s.data(), s.size()};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns `true` if strings are case-insensitive equal. */
|
||||||
|
template <class String1, class String2>
|
||||||
|
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
|
#endif
|
||||||
|
|||||||
@@ -210,8 +210,7 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
|
|||||||
if (std::find_if(types.begin(), types.end(),
|
if (std::find_if(types.begin(), types.end(),
|
||||||
[](std::string const& s)
|
[](std::string const& s)
|
||||||
{
|
{
|
||||||
return beast::ci_equal(s,
|
return beast::ci_equal(s, "peer");
|
||||||
std::string("peer"));
|
|
||||||
}) == types.end())
|
}) == types.end())
|
||||||
{
|
{
|
||||||
handoff.moved = false;
|
handoff.moved = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user