GCC Code Coverage Report


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