include/boost/url/impl/params_base.hpp

100.0% Lines (128/128) 100.0% List of functions (28/28)
params_base.hpp
f(x) Functions (28)
Function Calls Lines Blocks
boost::urls::params_base::iterator::iterator(boost::urls::detail::params_iter_impl const&, boost::urls::encoding_opts) :43 1724x 100.0% 100.0% boost::urls::params_base::iterator::iterator() :60 4x 100.0% 100.0% boost::urls::params_base::iterator::operator++() :66 6660x 100.0% 100.0% boost::urls::params_base::iterator::operator++(int) :73 367x 100.0% 100.0% boost::urls::params_base::iterator::operator--() :81 730x 100.0% 100.0% boost::urls::params_base::iterator::operator--(int) :88 365x 100.0% 100.0% boost::urls::params_base::iterator::operator==(boost::urls::params_base::iterator const&) const :102 768x 100.0% 100.0% boost::urls::params_base::iterator::operator!=(boost::urls::params_base::iterator const&) const :109 11059x 100.0% 100.0% boost::urls::params_base::iterator::iterator(boost::urls::detail::query_ref const&, boost::urls::encoding_opts) :120 6756x 100.0% 100.0% boost::urls::params_base::iterator::iterator(boost::urls::detail::query_ref const&, boost::urls::encoding_opts, int) :131 11993x 100.0% 100.0% boost::urls::params_base::iterator::operator*() const :145 5908x 100.0% 57.0% boost::urls::params_base::params_base() :169 1x 100.0% 100.0% boost::urls::params_base::contains(boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :178 28x 100.0% 100.0% boost::urls::params_base::find(boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :189 189x 100.0% 100.0% boost::urls::params_base::find(boost::urls::params_base::iterator, boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :203 64x 100.0% 100.0% boost::urls::params_base::find_last(boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :218 4x 100.0% 100.0% boost::urls::params_base::find_last(boost::urls::params_base::iterator, boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :232 9x 100.0% 100.0% boost::urls::params_base::params_base(boost::urls::detail::query_ref const&, boost::urls::encoding_opts) :246 6917x 100.0% 100.0% boost::urls::params_base::buffer() const :257 13x 100.0% 100.0% boost::urls::params_base::empty() const :265 1551x 100.0% 100.0% boost::urls::params_base::size() const :273 781x 100.0% 100.0% boost::urls::params_base::begin() const :281 6756x 100.0% 100.0% boost::urls::params_base::end() const :290 11993x 100.0% 100.0% boost::urls::params_base::count(boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :301 32x 100.0% 100.0% boost::urls::params_base::get_or[abi:cxx11](boost::core::basic_string_view<char>, boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :320 8x 100.0% 85.0% boost::urls::params_base::find_impl(boost::urls::detail::params_iter_impl, boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :348 261x 100.0% 100.0% boost::urls::params_base::find_last_impl(boost::urls::detail::params_iter_impl, boost::core::basic_string_view<char>, boost::urls::ignore_case_param) const :379 13x 100.0% 100.0% boost::urls::operator<<(std::ostream&, boost::urls::params_base const&) :412 1x 100.0% 100.0%
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/boostorg/url
9 //
10
11 #ifndef BOOST_URL_IMPL_PARAMS_BASE_HPP
12 #define BOOST_URL_IMPL_PARAMS_BASE_HPP
13
14 #include <boost/url/detail/params_iter_impl.hpp>
15 #include <boost/url/decode_view.hpp>
16 #include <boost/url/grammar/ci_string.hpp>
17 #include <iterator>
18 #include <ostream>
19 #include <string>
20
21 namespace boost {
22 namespace urls {
23
24 //------------------------------------------------
25
26 class BOOST_SYMBOL_VISIBLE params_base::iterator
27 {
28 detail::params_iter_impl it_;
29 bool space_as_plus_ = true;
30
31 friend class params_base;
32 friend class params_ref;
33
34 iterator(
35 detail::query_ref const& ref,
36 encoding_opts opt) noexcept;
37
38 iterator(
39 detail::query_ref const& impl,
40 encoding_opts opt,
41 int) noexcept;
42
43 1724x iterator(
44 detail::params_iter_impl const& it,
45 encoding_opts opt) noexcept
46 1724x : it_(it)
47 1724x , space_as_plus_(opt.space_as_plus)
48 {
49 1724x }
50
51 public:
52 using value_type = params_base::value_type;
53 using reference = params_base::reference;
54 using pointer = reference;
55 using difference_type =
56 params_base::difference_type;
57 using iterator_category =
58 std::bidirectional_iterator_tag;
59
60 4x iterator() = default;
61 iterator(iterator const&) = default;
62 iterator& operator=(
63 iterator const&) noexcept = default;
64
65 iterator&
66 6660x operator++() noexcept
67 {
68 6660x it_.increment();
69 6660x return *this;
70 }
71
72 iterator
73 367x operator++(int) noexcept
74 {
75 367x auto tmp = *this;
76 367x ++*this;
77 367x return tmp;
78 }
79
80 iterator&
81 730x operator--() noexcept
82 {
83 730x it_.decrement();
84 730x return *this;
85 }
86
87 iterator
88 365x operator--(int) noexcept
89 {
90 365x auto tmp = *this;
91 365x --*this;
92 365x return tmp;
93 }
94
95 reference
96 operator*() const;
97
98 // the return value is too expensive
99 pointer operator->() const = delete;
100
101 bool
102 768x operator==(
103 iterator const& other) const noexcept
104 {
105 768x return it_.equal(other.it_);
106 }
107
108 bool
109 11059x operator!=(
110 iterator const& other) const noexcept
111 {
112 11059x return ! it_.equal(other.it_);
113 }
114 };
115
116
117 //------------------------------------------------
118
119 inline
120 6756x params_base::
121 iterator::
122 iterator(
123 detail::query_ref const& ref,
124 6756x encoding_opts opt) noexcept
125 6756x : it_(ref)
126 6756x , space_as_plus_(opt.space_as_plus)
127 {
128 6756x }
129
130 inline
131 11993x params_base::
132 iterator::
133 iterator(
134 detail::query_ref const& ref,
135 encoding_opts opt,
136 11993x int) noexcept
137 11993x : it_(ref, 0)
138 11993x , space_as_plus_(opt.space_as_plus)
139 {
140 11993x }
141
142
143 inline
144 auto
145 5908x params_base::
146 iterator::
147 operator*() const ->
148 reference
149
150 {
151 5908x encoding_opts opt;
152 5908x opt.space_as_plus =
153 5908x space_as_plus_;
154 param_pct_view p =
155 5908x it_.dereference();
156 return reference(
157 11816x p.key.decode(opt),
158 11816x p.value.decode(opt),
159 29540x p.has_value);
160 }
161
162 //------------------------------------------------
163 //
164 // params_base
165 //
166 //------------------------------------------------
167
168 inline
169 1x params_base::
170 1x params_base() noexcept
171 // space_as_plus = true
172 1x : opt_(true, false, false)
173 {
174 1x }
175
176 inline
177 bool
178 28x params_base::
179 contains(
180 core::string_view key,
181 ignore_case_param ic) const noexcept
182 {
183 28x return find(
184 56x begin(),key, ic) != end();
185 }
186
187 inline
188 auto
189 189x params_base::
190 find(
191 core::string_view key,
192 ignore_case_param ic) const noexcept ->
193 iterator
194 {
195 return iterator(
196 189x find_impl(
197 378x begin().it_, key, ic),
198 189x opt_);
199 }
200
201 inline
202 auto
203 64x params_base::
204 find(
205 iterator it,
206 core::string_view key,
207 ignore_case_param ic) const noexcept ->
208 iterator
209 {
210 return iterator(
211 128x find_impl(
212 it.it_, key, ic),
213 64x opt_);
214 }
215
216 inline
217 auto
218 4x params_base::
219 find_last(
220 core::string_view key,
221 ignore_case_param ic) const noexcept ->
222 iterator
223 {
224 return iterator(
225 4x find_last_impl(
226 8x end().it_, key, ic),
227 4x opt_);
228 }
229
230 inline
231 auto
232 9x params_base::
233 find_last(
234 iterator it,
235 core::string_view key,
236 ignore_case_param ic) const noexcept ->
237 iterator
238 {
239 return iterator(
240 18x find_last_impl(
241 it.it_, key, ic),
242 9x opt_);
243 }
244
245 inline
246 6917x params_base::
247 params_base(
248 detail::query_ref const& ref,
249 6917x encoding_opts opt) noexcept
250 6917x : ref_(ref)
251 6917x , opt_(opt)
252 {
253 6917x }
254
255 inline
256 pct_string_view
257 13x params_base::
258 buffer() const noexcept
259 {
260 13x return ref_.buffer();
261 }
262
263 inline
264 bool
265 1551x params_base::
266 empty() const noexcept
267 {
268 1551x return ref_.nparam() == 0;
269 }
270
271 inline
272 std::size_t
273 781x params_base::
274 size() const noexcept
275 {
276 781x return ref_.nparam();
277 }
278
279 inline
280 auto
281 6756x params_base::
282 begin() const noexcept ->
283 iterator
284 {
285 6756x return iterator(ref_, opt_);
286 }
287
288 inline
289 auto
290 11993x params_base::
291 end() const noexcept ->
292 iterator
293 {
294 11993x return {ref_, opt_, 0};
295 }
296
297 //------------------------------------------------
298
299 inline
300 std::size_t
301 32x params_base::
302 count(
303 core::string_view key,
304 ignore_case_param ic) const noexcept
305 {
306 32x std::size_t n = 0;
307 32x auto it = find(key, ic);
308 32x auto const end_ = end();
309 64x while(it != end_)
310 {
311 32x ++n;
312 32x ++it;
313 32x it = find(it, key, ic);
314 }
315 32x return n;
316 }
317
318 inline
319 std::string
320 8x params_base::
321 get_or(
322 core::string_view key,
323 core::string_view value,
324 ignore_case_param ic) const
325 {
326 8x auto it = find_impl(
327 8x begin().it_, key, ic);
328 8x detail::params_iter_impl end_(ref_, 0);
329 8x if(it.equal(end_))
330 2x return std::string(value);
331
332 6x param_pct_view const p = it.dereference();
333 6x if(! p.has_value)
334 1x return std::string();
335
336 5x auto opt = opt_;
337 5x return p.value.decode(opt);
338 }
339
340 //------------------------------------------------
341 //
342 // (implementation)
343 //
344 //------------------------------------------------
345
346 inline
347 detail::params_iter_impl
348 261x params_base::
349 find_impl(
350 detail::params_iter_impl it,
351 core::string_view key,
352 ignore_case_param ic) const noexcept
353 {
354 261x detail::params_iter_impl end_(ref_, 0);
355 261x if(! ic)
356 {
357 for(;;)
358 {
359 566x if(it.equal(end_))
360 146x return it;
361 420x if(*it.key() == key)
362 77x return it;
363 343x it.increment();
364 }
365 }
366 for(;;)
367 {
368 129x if(it.equal(end_))
369 10x return it;
370 119x if( grammar::ci_is_equal(
371 238x *it.key(), key))
372 28x return it;
373 91x it.increment();
374 }
375 }
376
377 inline
378 detail::params_iter_impl
379 13x params_base::
380 find_last_impl(
381 detail::params_iter_impl it,
382 core::string_view key,
383 ignore_case_param ic) const noexcept
384 {
385 13x detail::params_iter_impl begin_(ref_);
386 13x if(! ic)
387 {
388 for(;;)
389 {
390 13x if(it.equal(begin_))
391 2x return { ref_, 0 };
392 11x it.decrement();
393 11x if(*it.key() == key)
394 5x return it;
395 }
396 }
397 for(;;)
398 {
399 9x if(it.equal(begin_))
400 1x return { ref_, 0 };
401 8x it.decrement();
402 8x if(grammar::ci_is_equal(
403 16x *it.key(), key))
404 5x return it;
405 }
406 }
407
408 //------------------------------------------------
409
410 inline
411 std::ostream&
412 1x operator<<(
413 std::ostream& os,
414 params_base const& qp)
415 {
416 1x os << qp.buffer();
417 1x return os;
418 }
419
420 } // urls
421 } // boost
422
423 #endif
424