string.ipp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_IMPL_STRING_IPP
  10. #define BOOST_BEAST_IMPL_STRING_IPP
  11. #include <boost/beast/core/string.hpp>
  12. #include <boost/beast/core/detail/string.hpp>
  13. #include <algorithm>
  14. namespace boost {
  15. namespace beast {
  16. bool
  17. iequals(
  18. beast::string_view lhs,
  19. beast::string_view rhs)
  20. {
  21. auto n = lhs.size();
  22. if(rhs.size() != n)
  23. return false;
  24. auto p1 = lhs.data();
  25. auto p2 = rhs.data();
  26. char a, b;
  27. // fast loop
  28. while(n--)
  29. {
  30. a = *p1++;
  31. b = *p2++;
  32. if(a != b)
  33. goto slow;
  34. }
  35. return true;
  36. slow:
  37. do
  38. {
  39. if( detail::ascii_tolower(a) !=
  40. detail::ascii_tolower(b))
  41. return false;
  42. a = *p1++;
  43. b = *p2++;
  44. }
  45. while(n--);
  46. return true;
  47. }
  48. bool
  49. iless::operator()(
  50. string_view lhs,
  51. string_view rhs) const
  52. {
  53. using std::begin;
  54. using std::end;
  55. return std::lexicographical_compare(
  56. begin(lhs), end(lhs), begin(rhs), end(rhs),
  57. [](char c1, char c2)
  58. {
  59. return detail::ascii_tolower(c1) < detail::ascii_tolower(c2);
  60. }
  61. );
  62. }
  63. } // beast
  64. } // boost
  65. #endif