]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/beast/core/string.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / beast / core / string.hpp
CommitLineData
b32b8144
FG
1//
2// Copyright (c) 2016-2017 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_STRING_HPP
11#define BOOST_BEAST_STRING_HPP
12
13#include <boost/beast/core/detail/config.hpp>
14#include <boost/version.hpp>
b32b8144 15#include <boost/utility/string_view.hpp>
b32b8144
FG
16#include <algorithm>
17
18namespace boost {
19namespace beast {
20
b32b8144
FG
21/// The type of string view used by the library
22using string_view = boost::string_view;
23
24/// The type of basic string view used by the library
25template<class CharT, class Traits>
26using basic_string_view =
27 boost::basic_string_view<CharT, Traits>;
b32b8144
FG
28
29namespace detail {
30
31inline
32char
33ascii_tolower(char c)
34{
11fdf7f2
TL
35 return ((static_cast<unsigned>(c) - 65U) < 26) ?
36 c + 'a' - 'A' : c;
b32b8144
FG
37}
38
39template<class = void>
40bool
41iequals(
42 beast::string_view lhs,
43 beast::string_view rhs)
44{
45 auto n = lhs.size();
46 if(rhs.size() != n)
47 return false;
48 auto p1 = lhs.data();
49 auto p2 = rhs.data();
50 char a, b;
51 while(n--)
52 {
53 a = *p1++;
54 b = *p2++;
55 if(a != b)
11fdf7f2
TL
56 {
57 // slow loop
58 do
59 {
60 if(ascii_tolower(a) != ascii_tolower(b))
61 return false;
62 a = *p1++;
63 b = *p2++;
64 }
65 while(n--);
66 return true;
67 }
b32b8144
FG
68 }
69 return true;
70}
71
72} // detail
73
74/** Returns `true` if two strings are equal, using a case-insensitive comparison.
75
76 The case-comparison operation is defined only for low-ASCII characters.
77
78 @param lhs The string on the left side of the equality
79
80 @param rhs The string on the right side of the equality
81*/
82inline
83bool
84iequals(
85 beast::string_view lhs,
86 beast::string_view rhs)
87{
88 return detail::iequals(lhs, rhs);
89}
90
91/** A case-insensitive less predicate for strings.
92
93 The case-comparison operation is defined only for low-ASCII characters.
94*/
95struct iless
96{
97 bool
98 operator()(
99 string_view lhs,
100 string_view rhs) const
101 {
102 using std::begin;
103 using std::end;
104 return std::lexicographical_compare(
105 begin(lhs), end(lhs), begin(rhs), end(rhs),
106 [](char c1, char c2)
107 {
108 return detail::ascii_tolower(c1) < detail::ascii_tolower(c2);
109 }
110 );
111 }
112};
113
114/** A case-insensitive equality predicate for strings.
115
116 The case-comparison operation is defined only for low-ASCII characters.
117*/
118struct iequal
119{
120 bool
121 operator()(
122 string_view lhs,
123 string_view rhs) const
124 {
125 return iequals(lhs, rhs);
126 }
127};
128
129} // beast
130} // boost
131
132#endif