include/boost/url/impl/params_encoded_base.hpp

100.0% Lines (113/113) 100.0% List of functions (28/28)
params_encoded_base.hpp
f(x) Functions (28)
Function Calls Lines Blocks
boost::urls::params_encoded_base::iterator::iterator(boost::urls::detail::params_iter_impl const&) :36 159x 100.0% 100.0% boost::urls::params_encoded_base::iterator::iterator() :52 4x 100.0% 100.0% boost::urls::params_encoded_base::iterator::operator++() :58 778x 100.0% 100.0% boost::urls::params_encoded_base::iterator::operator++(int) :65 303x 100.0% 100.0% boost::urls::params_encoded_base::iterator::operator--() :73 602x 100.0% 100.0% boost::urls::params_encoded_base::iterator::operator--(int) :80 301x 100.0% 100.0% boost::urls::params_encoded_base::iterator::operator*() const :88 704x 100.0% 100.0% boost::urls::params_encoded_base::iterator::operator->() const :94 21x 100.0% 100.0% boost::urls::operator==(boost::urls::params_encoded_base::iterator const&, boost::urls::params_encoded_base::iterator const&) :101 643x 100.0% 100.0% boost::urls::operator!=(boost::urls::params_encoded_base::iterator const&, boost::urls::params_encoded_base::iterator const&) :110 220x 100.0% 100.0% boost::urls::params_encoded_base::contains(boost::urls::pct_string_view, boost::urls::ignore_case_param) const :126 28x 100.0% 100.0% boost::urls::params_encoded_base::get_or(boost::urls::pct_string_view, boost::urls::pct_string_view, boost::urls::ignore_case_param) const :137 7x 100.0% 100.0% boost::urls::params_encoded_base::find(boost::urls::pct_string_view, boost::urls::ignore_case_param) const :158 38x 100.0% 100.0% boost::urls::params_encoded_base::find(boost::urls::params_encoded_base::iterator, boost::urls::pct_string_view, boost::urls::ignore_case_param) const :170 32x 100.0% 100.0% boost::urls::params_encoded_base::find_last(boost::urls::pct_string_view, boost::urls::ignore_case_param) const :183 4x 100.0% 100.0% boost::urls::params_encoded_base::find_last(boost::urls::params_encoded_base::iterator, boost::urls::pct_string_view, boost::urls::ignore_case_param) const :195 9x 100.0% 100.0% boost::urls::params_encoded_base::iterator::iterator(boost::urls::detail::query_ref const&) :209 341x 100.0% 100.0% boost::urls::params_encoded_base::iterator::iterator(boost::urls::detail::query_ref const&, int) :218 300x 100.0% 100.0% boost::urls::params_encoded_base::params_encoded_base(boost::urls::detail::query_ref const&) :233 3540x 100.0% 100.0% boost::urls::params_encoded_base::buffer() const :248 11x 100.0% 100.0% boost::urls::params_encoded_base::empty() const :256 6x 100.0% 100.0% boost::urls::params_encoded_base::size() const :264 348x 100.0% 100.0% boost::urls::params_encoded_base::begin() const :272 341x 100.0% 100.0% boost::urls::params_encoded_base::end() const :281 300x 100.0% 100.0% boost::urls::params_encoded_base::count(boost::urls::pct_string_view, boost::urls::ignore_case_param) const :292 29x 100.0% 100.0% boost::urls::params_encoded_base::find_impl(boost::urls::detail::params_iter_impl, boost::urls::pct_string_view, boost::urls::ignore_case_param) const :317 105x 100.0% 100.0% boost::urls::params_encoded_base::find_last_impl(boost::urls::detail::params_iter_impl, boost::urls::pct_string_view, boost::urls::ignore_case_param) const :348 13x 100.0% 100.0% boost::urls::operator<<(std::ostream&, boost::urls::params_encoded_base const&) :381 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_ENCODED_BASE_HPP
12 #define BOOST_URL_IMPL_PARAMS_ENCODED_BASE_HPP
13
14 #include <boost/url/detail/params_iter_impl.hpp>
15 #include <boost/url/grammar/ci_string.hpp>
16 #include <ostream>
17
18 namespace boost {
19 namespace urls {
20
21 #ifndef BOOST_URL_DOCS
22 class params_ref;
23 #endif
24
25 //------------------------------------------------
26
27 class params_encoded_base::iterator
28 {
29 detail::params_iter_impl it_;
30
31 friend class params_encoded_base;
32 friend class params_encoded_ref;
33
34 iterator(detail::query_ref const& ref) noexcept;
35 iterator(detail::query_ref const& ref, int) noexcept;
36 159x iterator(
37 detail::params_iter_impl const& it)
38 159x : it_(it)
39 {
40 159x }
41
42 public:
43 using value_type =
44 params_encoded_base::value_type;
45 using reference =
46 params_encoded_base::reference;
47 using pointer = reference;
48 using difference_type = std::ptrdiff_t;
49 using iterator_category =
50 std::bidirectional_iterator_tag;
51
52 4x iterator() = default;
53 iterator(iterator const&) = default;
54 iterator& operator=(
55 iterator const&) = default;
56
57 iterator&
58 778x operator++() noexcept
59 {
60 778x it_.increment();
61 778x return *this;
62 }
63
64 iterator
65 303x operator++(int) noexcept
66 {
67 303x auto tmp = *this;
68 303x ++*this;
69 303x return tmp;
70 }
71
72 iterator&
73 602x operator--() noexcept
74 {
75 602x it_.decrement();
76 602x return *this;
77 }
78
79 iterator
80 301x operator--(int) noexcept
81 {
82 301x auto tmp = *this;
83 301x --*this;
84 301x return tmp;
85 }
86
87 reference
88 704x operator*() const
89 {
90 704x return it_.dereference();
91 }
92
93 pointer
94 21x operator->() const
95 {
96 21x return it_.dereference();
97 }
98
99 friend
100 bool
101 643x operator==(
102 iterator const& it0,
103 iterator const& it1) noexcept
104 {
105 643x return it0.it_.equal(it1.it_);
106 }
107
108 friend
109 bool
110 220x operator!=(
111 iterator const& it0,
112 iterator const& it1) noexcept
113 {
114 220x return ! it0.it_.equal(it1.it_);
115 }
116 };
117
118 //------------------------------------------------
119 //
120 // Observers
121 //
122 //------------------------------------------------
123
124 inline
125 bool
126 28x params_encoded_base::
127 contains(
128 pct_string_view key,
129 ignore_case_param ic) const noexcept
130 {
131 28x return find_impl(
132 56x begin().it_, key, ic) != end();
133 }
134
135 inline
136 pct_string_view
137 7x params_encoded_base::
138 get_or(
139 pct_string_view key,
140 pct_string_view value,
141 ignore_case_param ic) const noexcept
142 {
143 7x auto it = find_impl(
144 7x begin().it_, key, ic);
145 7x detail::params_iter_impl end_(ref_, 0);
146 7x if(it.equal(end_))
147 2x return value;
148
149 5x param_pct_view const p = it.dereference();
150 5x if(! p.has_value)
151 1x return pct_string_view();
152
153 4x return p.value;
154 }
155
156 inline
157 auto
158 38x params_encoded_base::
159 find(
160 pct_string_view key,
161 ignore_case_param ic) const noexcept ->
162 iterator
163 {
164 38x return find_impl(
165 76x begin().it_, key, ic);
166 }
167
168 inline
169 auto
170 32x params_encoded_base::
171 find(
172 iterator it,
173 pct_string_view key,
174 ignore_case_param ic) const noexcept ->
175 iterator
176 {
177 64x return find_impl(
178 32x it.it_, key, ic);
179 }
180
181 inline
182 auto
183 4x params_encoded_base::
184 find_last(
185 pct_string_view key,
186 ignore_case_param ic) const noexcept ->
187 iterator
188 {
189 4x return find_last_impl(
190 8x end().it_, key, ic);
191 }
192
193 inline
194 auto
195 9x params_encoded_base::
196 find_last(
197 iterator it,
198 pct_string_view key,
199 ignore_case_param ic) const noexcept ->
200 iterator
201 {
202 18x return find_last_impl(
203 9x it.it_, key, ic);
204 }
205
206 //------------------------------------------------
207
208 inline
209 341x params_encoded_base::
210 iterator::
211 iterator(
212 341x detail::query_ref const& ref) noexcept
213 341x : it_(ref)
214 {
215 341x }
216
217 inline
218 300x params_encoded_base::
219 iterator::
220 iterator(
221 300x detail::query_ref const& ref, int) noexcept
222 300x : it_(ref, 0)
223 {
224 300x }
225
226 //------------------------------------------------
227 //
228 // params_encoded_base
229 //
230 //------------------------------------------------
231
232 inline
233 3540x params_encoded_base::
234 params_encoded_base(
235 3540x detail::query_ref const& ref) noexcept
236 3540x : ref_(ref)
237 {
238 3540x }
239
240 //------------------------------------------------
241 //
242 // Observers
243 //
244 //------------------------------------------------
245
246 inline
247 pct_string_view
248 11x params_encoded_base::
249 buffer() const noexcept
250 {
251 11x return ref_.buffer();
252 }
253
254 inline
255 bool
256 6x params_encoded_base::
257 empty() const noexcept
258 {
259 6x return ref_.nparam() == 0;
260 }
261
262 inline
263 std::size_t
264 348x params_encoded_base::
265 size() const noexcept
266 {
267 348x return ref_.nparam();
268 }
269
270 inline
271 auto
272 341x params_encoded_base::
273 begin() const noexcept ->
274 iterator
275 {
276 341x return { ref_ };
277 }
278
279 inline
280 auto
281 300x params_encoded_base::
282 end() const noexcept ->
283 iterator
284 {
285 300x return { ref_, 0 };
286 }
287
288 //------------------------------------------------
289
290 inline
291 std::size_t
292 29x params_encoded_base::
293 count(
294 pct_string_view key,
295 ignore_case_param ic) const noexcept
296 {
297 29x std::size_t n = 0;
298 29x auto it = find(key, ic);
299 29x auto const end_ = end();
300 57x while(it != end_)
301 {
302 28x ++n;
303 28x ++it;
304 28x it = find(it, key, ic);
305 }
306 29x return n;
307 }
308
309 //------------------------------------------------
310 //
311 // (implementation)
312 //
313 //------------------------------------------------
314
315 inline
316 detail::params_iter_impl
317 105x params_encoded_base::
318 find_impl(
319 detail::params_iter_impl it,
320 pct_string_view key,
321 ignore_case_param ic) const noexcept
322 {
323 105x detail::params_iter_impl end_(ref_, 0);
324 105x if(! ic)
325 {
326 for(;;)
327 {
328 317x if(it.equal(end_))
329 33x return it;
330 284x if(*it.key() == *key)
331 34x return it;
332 250x it.increment();
333 }
334 }
335 for(;;)
336 {
337 129x if(it.equal(end_))
338 10x return it;
339 119x if( grammar::ci_is_equal(
340 238x *it.key(), *key))
341 28x return it;
342 91x it.increment();
343 }
344 }
345
346 inline
347 detail::params_iter_impl
348 13x params_encoded_base::
349 find_last_impl(
350 detail::params_iter_impl it,
351 pct_string_view key,
352 ignore_case_param ic) const noexcept
353 {
354 13x detail::params_iter_impl begin_(ref_);
355 13x if(! ic)
356 {
357 for(;;)
358 {
359 13x if(it.equal(begin_))
360 2x return { ref_, 0 };
361 11x it.decrement();
362 11x if(*it.key() == *key)
363 5x return it;
364 }
365 }
366 for(;;)
367 {
368 9x if(it.equal(begin_))
369 1x return { ref_, 0 };
370 8x it.decrement();
371 8x if(grammar::ci_is_equal(
372 16x *it.key(), *key))
373 5x return it;
374 }
375 }
376
377 //------------------------------------------------
378
379 inline
380 std::ostream&
381 1x operator<<(
382 std::ostream& os,
383 params_encoded_base const& qp)
384 {
385 1x os << qp.buffer();
386 1x return os;
387 }
388
389 } // urls
390 } // boost
391
392 #endif
393