GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/params_encoded_base.cpp
Date: 2024-09-08 09:46:49
Exec Total Coverage
Lines: 62 62 100.0%
Functions: 12 12 100.0%
Branches: 23 24 95.8%

Line Branch Exec Source
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
12 #include <boost/url/detail/config.hpp>
13 #include <boost/url/decode_view.hpp>
14 #include <boost/url/params_encoded_base.hpp>
15 #include <boost/url/grammar/ci_string.hpp>
16 #include <ostream>
17
18 namespace boost {
19 namespace urls {
20
21 277 params_encoded_base::
22 iterator::
23 iterator(
24 277 detail::query_ref const& ref) noexcept
25 277 : it_(ref)
26 {
27 277 }
28
29 217 params_encoded_base::
30 iterator::
31 iterator(
32 217 detail::query_ref const& ref, int) noexcept
33 217 : it_(ref, 0)
34 {
35 217 }
36
37 //------------------------------------------------
38 //
39 // params_encoded_base
40 //
41 //------------------------------------------------
42
43 864 params_encoded_base::
44 params_encoded_base(
45 864 detail::query_ref const& ref) noexcept
46 864 : ref_(ref)
47 {
48 864 }
49
50 //------------------------------------------------
51 //
52 // Observers
53 //
54 //------------------------------------------------
55
56 pct_string_view
57 441 params_encoded_base::
58 buffer() const noexcept
59 {
60 441 return ref_.buffer();
61 }
62
63 bool
64 5 params_encoded_base::
65 empty() const noexcept
66 {
67 5 return ref_.nparam() == 0;
68 }
69
70 std::size_t
71 724 params_encoded_base::
72 size() const noexcept
73 {
74 724 return ref_.nparam();
75 }
76
77 auto
78 277 params_encoded_base::
79 begin() const noexcept ->
80 iterator
81 {
82 277 return { ref_ };
83 }
84
85 auto
86 217 params_encoded_base::
87 end() const noexcept ->
88 iterator
89 {
90 217 return { ref_, 0 };
91 }
92
93 //------------------------------------------------
94
95 std::size_t
96 29 params_encoded_base::
97 count(
98 pct_string_view key,
99 ignore_case_param ic) const noexcept
100 {
101 29 std::size_t n = 0;
102 29 auto it = find(key, ic);
103 29 auto const end_ = end();
104
2/2
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 29 times.
57 while(it != end_)
105 {
106 28 ++n;
107 28 ++it;
108 28 it = find(it, key, ic);
109 }
110 29 return n;
111 }
112
113 //------------------------------------------------
114 //
115 // (implementation)
116 //
117 //------------------------------------------------
118
119 detail::params_iter_impl
120 98 params_encoded_base::
121 find_impl(
122 detail::params_iter_impl it,
123 pct_string_view key,
124 ignore_case_param ic) const noexcept
125 {
126 98 detail::params_iter_impl end_(ref_, 0);
127
2/2
✓ Branch 1 taken 61 times.
✓ Branch 2 taken 37 times.
98 if(! ic)
128 {
129 for(;;)
130 {
131
2/2
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 268 times.
299 if(it.equal(end_))
132 31 return it;
133
2/2
✓ Branch 4 taken 30 times.
✓ Branch 5 taken 238 times.
268 if(*it.key() == *key)
134 30 return it;
135 238 it.increment();
136 }
137 }
138 for(;;)
139 {
140
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 118 times.
128 if(it.equal(end_))
141 10 return it;
142 118 if( grammar::ci_is_equal(
143
2/2
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 91 times.
236 *it.key(), *key))
144 27 return it;
145 91 it.increment();
146 }
147 }
148
149 detail::params_iter_impl
150 13 params_encoded_base::
151 find_last_impl(
152 detail::params_iter_impl it,
153 pct_string_view key,
154 ignore_case_param ic) const noexcept
155 {
156 13 detail::params_iter_impl begin_(ref_);
157
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 6 times.
13 if(! ic)
158 {
159 for(;;)
160 {
161
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 11 times.
13 if(it.equal(begin_))
162 2 return { ref_, 0 };
163 11 it.decrement();
164
2/2
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 6 times.
11 if(*it.key() == *key)
165 5 return it;
166 }
167 }
168 for(;;)
169 {
170
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8 times.
9 if(it.equal(begin_))
171 1 return { ref_, 0 };
172 8 it.decrement();
173 8 if(grammar::ci_is_equal(
174
2/2
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 3 times.
16 *it.key(), *key))
175 5 return it;
176 }
177 }
178
179 //------------------------------------------------
180
181 std::ostream&
182 1 operator<<(
183 std::ostream& os,
184 params_encoded_base const& qp)
185 {
186
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 os << qp.buffer();
187 1 return os;
188 }
189
190 } // urls
191 } // boost
192
193