ゴミ箱
string.hpp
Go to the documentation of this file.
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/config.hpp>
14 #include <boost/version.hpp>
15 #ifndef BOOST_BEAST_NO_BOOST_STRING_VIEW
16 # if BOOST_VERSION >= 106400
17 # define BOOST_BEAST_NO_BOOST_STRING_VIEW 0
18 # else
19 # define BOOST_BEAST_NO_BOOST_STRING_VIEW 1
20 # endif
21 #endif
22 
23 #if BOOST_BEAST_NO_BOOST_STRING_VIEW
24 #include <boost/utility/string_ref.hpp>
25 #else
26 #include <boost/utility/string_view.hpp>
27 #endif
28 
29 #include <algorithm>
30 
31 namespace boost {
32 namespace beast {
33 
34 #if BOOST_BEAST_NO_BOOST_STRING_VIEW
35 using string_view = boost::string_ref;
37 
39 template<class CharT, class Traits>
40 using basic_string_view =
41  boost::basic_string_ref<CharT, Traits>;
42 #else
45 
47 template<class CharT, class Traits>
48 using basic_string_view =
49  boost::basic_string_view<CharT, Traits>;
50 #endif
51 
52 namespace detail {
53 
54 inline
55 char
57 {
58  if(c >= 'A' && c <= 'Z')
59  c += 'a' - 'A';
60  return c;
61 }
62 
63 template<class = void>
64 bool
68 {
69  auto n = lhs.size();
70  if(rhs.size() != n)
71  return false;
72  auto p1 = lhs.data();
73  auto p2 = rhs.data();
74  char a, b;
75  while(n--)
76  {
77  a = *p1++;
78  b = *p2++;
79  if(a != b)
80  goto slow;
81  }
82  return true;
83 
84  while(n--)
85  {
86  slow:
87  if(ascii_tolower(a) != ascii_tolower(b))
88  return false;
89  a = *p1++;
90  b = *p2++;
91  }
92  return true;
93 }
94 
95 } // detail
96 
105 inline
106 bool
108  beast::string_view lhs,
109  beast::string_view rhs)
110 {
111  return detail::iequals(lhs, rhs);
112 }
113 
118 struct iless
119 {
120  bool
122  string_view lhs,
123  string_view rhs) const
124  {
125  using std::begin;
126  using std::end;
128  begin(lhs), end(lhs), begin(rhs), end(rhs),
129  [](char c1, char c2)
130  {
132  }
133  );
134  }
135 };
136 
141 struct iequal
142 {
143  bool
145  string_view lhs,
146  string_view rhs) const
147  {
148  return iequals(lhs, rhs);
149  }
150 };
151 
152 } // beast
153 } // boost
154 
155 #endif
Definition: async_result.hpp:20
int lexicographical_compare(CharT const *s1, std::size_t n1, CharT const *s2, std::size_t n2)
Definition: static_string.hpp:30
boost::basic_string_ref< CharT, Traits > basic_string_view
The type of basic string view used by the library.
Definition: string.hpp:41
Definition: string.hpp:141
boost::string_ref string_view
The type of string view used by the library.
Definition: string.hpp:36
bool iequals(beast::string_view lhs, beast::string_view rhs)
Definition: string.hpp:65
Definition: string.hpp:118
bool operator()(string_view lhs, string_view rhs) const
Definition: string.hpp:144
bool operator()(string_view lhs, string_view rhs) const
Definition: string.hpp:121
char ascii_tolower(char c)
Definition: string.hpp:56