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
10#ifndef BOOST_BEAST_IMPL_STRING_IPP
11#define BOOST_BEAST_IMPL_STRING_IPP
12
13#include <boost/beast/core/string.hpp>
14#include <boost/beast/core/detail/string.hpp>
15
16#include <algorithm>
17
18namespace boost {
19namespace beast {
20
21bool
22iequals(
23    beast::string_view lhs,
24    beast::string_view rhs)
25{
26    auto n = lhs.size();
27    if(rhs.size() != n)
28        return false;
29    auto p1 = lhs.data();
30    auto p2 = rhs.data();
31    char a, b;
32    // fast loop
33    while(n--)
34    {
35        a = *p1++;
36        b = *p2++;
37        if(a != b)
38            goto slow;
39    }
40    return true;
41slow:
42    do
43    {
44        if( detail::ascii_tolower(a) !=
45            detail::ascii_tolower(b))
46            return false;
47        a = *p1++;
48        b = *p2++;
49    }
50    while(n--);
51    return true;
52}
53
54bool
55iless::operator()(
56    string_view lhs,
57    string_view rhs) const
58{
59    using std::begin;
60    using std::end;
61    return std::lexicographical_compare(
62        begin(lhs), end(lhs), begin(rhs), end(rhs),
63        [](char c1, char c2)
64        {
65            return detail::ascii_tolower(c1) < detail::ascii_tolower(c2);
66        }
67    );
68}
69
70} // beast
71} // boost
72
73#endif
74