• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_HTTP_IMPL_RFC7230_HPP
11 #define BOOST_BEAST_HTTP_IMPL_RFC7230_HPP
12 
13 #include <boost/beast/http/detail/rfc7230.hpp>
14 #include <iterator>
15 
16 namespace boost {
17 namespace beast {
18 namespace http {
19 
20 class param_list::const_iterator
21 {
22     using iter_type = string_view::const_iterator;
23 
24     std::string s_;
25     detail::param_iter pi_;
26 
27 public:
28     using value_type = param_list::value_type;
29     using pointer = value_type const*;
30     using reference = value_type const&;
31     using difference_type = std::ptrdiff_t;
32     using iterator_category = std::input_iterator_tag;
33 
34     const_iterator() = default;
35 
36     bool
operator ==(const_iterator const & other) const37     operator==(const_iterator const& other) const
38     {
39         return
40             other.pi_.it == pi_.it &&
41             other.pi_.last == pi_.last &&
42             other.pi_.first == pi_.first;
43     }
44 
45     bool
operator !=(const_iterator const & other) const46     operator!=(const_iterator const& other) const
47     {
48         return !(*this == other);
49     }
50 
51     reference
operator *() const52     operator*() const
53     {
54         return pi_.v;
55     }
56 
57     pointer
operator ->() const58     operator->() const
59     {
60         return &*(*this);
61     }
62 
63     const_iterator&
operator ++()64     operator++()
65     {
66         increment();
67         return *this;
68     }
69 
70     const_iterator
operator ++(int)71     operator++(int)
72     {
73         auto temp = *this;
74         ++(*this);
75         return temp;
76     }
77 
78 private:
79     friend class param_list;
80 
const_iterator(iter_type first,iter_type last)81     const_iterator(iter_type first, iter_type last)
82     {
83         pi_.it = first;
84         pi_.first = first;
85         pi_.last = last;
86         increment();
87     }
88 
89     BOOST_BEAST_DECL
90     static
91     std::string
92     unquote(string_view sr);
93 
94     BOOST_BEAST_DECL
95     void
96     increment();
97 };
98 
99 inline
100 auto
101 param_list::
begin() const102 begin() const ->
103     const_iterator
104 {
105     return const_iterator{s_.begin(), s_.end()};
106 }
107 
108 inline
109 auto
110 param_list::
end() const111 end() const ->
112     const_iterator
113 {
114     return const_iterator{s_.end(), s_.end()};
115 }
116 
117 inline
118 auto
119 param_list::
cbegin() const120 cbegin() const ->
121     const_iterator
122 {
123     return const_iterator{s_.begin(), s_.end()};
124 }
125 
126 inline
127 auto
128 param_list::
cend() const129 cend() const ->
130     const_iterator
131 {
132     return const_iterator{s_.end(), s_.end()};
133 }
134 
135 //------------------------------------------------------------------------------
136 
137 class ext_list::const_iterator
138 {
139     ext_list::value_type v_;
140     iter_type it_;
141     iter_type first_;
142     iter_type last_;
143 
144 public:
145     using value_type = ext_list::value_type;
146     using pointer = value_type const*;
147     using reference = value_type const&;
148     using difference_type = std::ptrdiff_t;
149     using iterator_category = std::forward_iterator_tag;
150 
151     const_iterator() = default;
152 
153     bool
operator ==(const_iterator const & other) const154     operator==(const_iterator const& other) const
155     {
156         return
157             other.it_ == it_ &&
158             other.first_ == first_ &&
159             other.last_ == last_;
160     }
161 
162     bool
operator !=(const_iterator const & other) const163     operator!=(const_iterator const& other) const
164     {
165         return !(*this == other);
166     }
167 
168     reference
operator *() const169     operator*() const
170     {
171         return v_;
172     }
173 
174     pointer
operator ->() const175     operator->() const
176     {
177         return &*(*this);
178     }
179 
180     const_iterator&
operator ++()181     operator++()
182     {
183         increment();
184         return *this;
185     }
186 
187     const_iterator
operator ++(int)188     operator++(int)
189     {
190         auto temp = *this;
191         ++(*this);
192         return temp;
193     }
194 
195 private:
196     friend class ext_list;
197 
const_iterator(iter_type begin,iter_type end)198     const_iterator(iter_type begin, iter_type end)
199     {
200         it_ = begin;
201         first_ = begin;
202         last_ = end;
203         increment();
204     }
205 
206     BOOST_BEAST_DECL
207     void
208     increment();
209 };
210 
211 inline
212 auto
213 ext_list::
begin() const214 begin() const ->
215     const_iterator
216 {
217     return const_iterator{s_.begin(), s_.end()};
218 }
219 
220 inline
221 auto
222 ext_list::
end() const223 end() const ->
224     const_iterator
225 {
226     return const_iterator{s_.end(), s_.end()};
227 }
228 
229 inline
230 auto
231 ext_list::
cbegin() const232 cbegin() const ->
233     const_iterator
234 {
235     return const_iterator{s_.begin(), s_.end()};
236 }
237 
238 inline
239 auto
240 ext_list::
cend() const241 cend() const ->
242     const_iterator
243 {
244     return const_iterator{s_.end(), s_.end()};
245 }
246 
247 
248 //------------------------------------------------------------------------------
249 
250 class token_list::const_iterator
251 {
252     token_list::value_type v_;
253     iter_type it_;
254     iter_type first_;
255     iter_type last_;
256 
257 public:
258     using value_type = token_list::value_type;
259     using pointer = value_type const*;
260     using reference = value_type const&;
261     using difference_type = std::ptrdiff_t;
262     using iterator_category = std::forward_iterator_tag;
263 
264     const_iterator() = default;
265 
266     bool
operator ==(const_iterator const & other) const267     operator==(const_iterator const& other) const
268     {
269         return
270             other.it_ == it_ &&
271             other.first_ == first_ &&
272             other.last_ == last_;
273     }
274 
275     bool
operator !=(const_iterator const & other) const276     operator!=(const_iterator const& other) const
277     {
278         return !(*this == other);
279     }
280 
281     reference
operator *() const282     operator*() const
283     {
284         return v_;
285     }
286 
287     pointer
operator ->() const288     operator->() const
289     {
290         return &*(*this);
291     }
292 
293     const_iterator&
operator ++()294     operator++()
295     {
296         increment();
297         return *this;
298     }
299 
300     const_iterator
operator ++(int)301     operator++(int)
302     {
303         auto temp = *this;
304         ++(*this);
305         return temp;
306     }
307 
308 private:
309     friend class token_list;
310 
const_iterator(iter_type begin,iter_type end)311     const_iterator(iter_type begin, iter_type end)
312     {
313         it_ = begin;
314         first_ = begin;
315         last_ = end;
316         increment();
317     }
318 
319     BOOST_BEAST_DECL
320     void
321     increment();
322 };
323 
324 inline
325 auto
326 token_list::
begin() const327 begin() const ->
328     const_iterator
329 {
330     return const_iterator{s_.begin(), s_.end()};
331 }
332 
333 inline
334 auto
335 token_list::
end() const336 end() const ->
337     const_iterator
338 {
339     return const_iterator{s_.end(), s_.end()};
340 }
341 
342 inline
343 auto
344 token_list::
cbegin() const345 cbegin() const ->
346     const_iterator
347 {
348     return const_iterator{s_.begin(), s_.end()};
349 }
350 
351 inline
352 auto
353 token_list::
cend() const354 cend() const ->
355     const_iterator
356 {
357     return const_iterator{s_.end(), s_.end()};
358 }
359 
360 template<class Policy>
361 bool
validate_list(detail::basic_parsed_list<Policy> const & list)362 validate_list(detail::basic_parsed_list<
363     Policy> const& list)
364 {
365     auto const last = list.end();
366     auto it = list.begin();
367     if(it.error())
368         return false;
369     while(it != last)
370     {
371         ++it;
372         if(it.error())
373             return false;
374         if(it == last)
375             break;
376     }
377     return true;
378 }
379 
380 } // http
381 } // beast
382 } // boost
383 
384 #ifdef BOOST_BEAST_HEADER_ONLY
385 #include <boost/beast/http/impl/rfc7230.ipp>
386 #endif
387 
388 #endif
389 
390