GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/detail/any_segments_iter.cpp
Date: 2024-01-19 15:42:54
Exec Total Coverage
Lines: 70 70 100.0%
Functions: 12 12 100.0%
Branches: 18 20 90.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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/url
8 //
9
10 #ifndef BOOST_URL_DETAIL_IMPL_ANY_SEGMENTS_ITER_IPP
11 #define BOOST_URL_DETAIL_IMPL_ANY_SEGMENTS_ITER_IPP
12
13 #include <boost/url/detail/config.hpp>
14 #include "../rfc/detail/charsets.hpp"
15 #include <boost/url/detail/any_segments_iter.hpp>
16 #include <boost/core/detail/string_view.hpp>
17 #include <boost/url/encode.hpp>
18 #include <boost/url/rfc/pchars.hpp>
19
20 namespace boost {
21 namespace urls {
22 namespace detail {
23
24 //------------------------------------------------
25 //
26 // segment_iter
27 //
28 //------------------------------------------------
29
30 74 segment_iter::
31 segment_iter(
32 74 core::string_view s_) noexcept
33 74 : any_segments_iter(s_)
34 {
35 74 front = s;
36 74 fast_nseg = 1;
37 74 }
38
39 void
40 74 segment_iter::
41 rewind() noexcept
42 {
43 74 at_end_ = false;
44 74 }
45
46 bool
47 148 segment_iter::
48 measure(
49 std::size_t& n) noexcept
50 {
51
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 74 times.
148 if(at_end_)
52 74 return false;
53 74 encoding_opts opt;
54 74 opt.space_as_plus = false;
55 74 n += encoded_size(
56 s,
57
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 72 times.
74 encode_colons ?
58 nocolon_pchars :
59 pchars,
60 opt);
61 74 at_end_ = true;
62 74 return true;
63 }
64
65 void
66 74 segment_iter::
67 copy(
68 char*& dest,
69 char const* end) noexcept
70 {
71 74 encoding_opts opt;
72 74 opt.space_as_plus = false;
73 74 dest += encode(
74 dest,
75 74 end - dest,
76 s,
77
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 72 times.
74 encode_colons ?
78 nocolon_pchars :
79 pchars,
80 opt);
81 74 }
82
83 //------------------------------------------------
84 //
85 // segments_iter_base
86 //
87 //------------------------------------------------
88
89 void
90 188 segments_iter_base::
91 measure_impl(
92 std::size_t& n,
93 core::string_view s,
94 bool encode_colons) noexcept
95 {
96 188 encoding_opts opt;
97 188 opt.space_as_plus = false;
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 188 times.
188 n += encoded_size(
99 s,
100 encode_colons ?
101 nocolon_pchars :
102 pchars,
103 opt);
104 188 }
105
106 void
107 188 segments_iter_base::
108 copy_impl(
109 char*& dest,
110 char const* end,
111 core::string_view s,
112 bool encode_colons) noexcept
113 {
114 188 encoding_opts opt;
115 188 opt.space_as_plus = false;
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 188 times.
188 dest += encode(
117 dest,
118 188 end - dest,
119 s,
120 encode_colons ?
121 nocolon_pchars :
122 pchars,
123 opt);
124 188 }
125
126 //------------------------------------------------
127 //
128 // segment_encoded_iter
129 //
130 //------------------------------------------------
131
132 72 segment_encoded_iter::
133 segment_encoded_iter(
134 72 pct_string_view const& s_) noexcept
135 72 : any_segments_iter(s_)
136 {
137 72 front = s;
138 72 fast_nseg = 1;
139 72 }
140
141 void
142 72 segment_encoded_iter::
143 rewind() noexcept
144 {
145 72 at_end_ = false;
146 72 }
147
148 bool
149 144 segment_encoded_iter::
150 measure(
151 std::size_t& n) noexcept
152 {
153
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
144 if(at_end_)
154 72 return false;
155 72 encoding_opts opt;
156 72 opt.space_as_plus = false;
157 72 n += detail::re_encoded_size_unsafe(
158 s,
159
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 70 times.
72 encode_colons ?
160 nocolon_pchars :
161 pchars,
162 opt);
163 72 at_end_ = true;
164 72 return true;
165 }
166
167 void
168 72 segment_encoded_iter::
169 copy(
170 char*& dest,
171 char const* end) noexcept
172 {
173 72 encoding_opts opt;
174 72 opt.space_as_plus = false;
175 72 detail::re_encode_unsafe(
176 dest,
177 end,
178 s,
179
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 70 times.
72 encode_colons ?
180 nocolon_pchars :
181 pchars,
182 opt);
183 72 }
184
185 //------------------------------------------------
186 //
187 // segments_encoded_iter_base
188 //
189 //------------------------------------------------
190
191 void
192 399 segments_encoded_iter_base::
193 measure_impl(
194 std::size_t& n,
195 core::string_view s,
196 bool encode_colons) noexcept
197 {
198 399 encoding_opts opt;
199 399 opt.space_as_plus = false;
200
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 398 times.
399 n += detail::re_encoded_size_unsafe(
201 s,
202 encode_colons ?
203 nocolon_pchars :
204 pchars,
205 opt);
206 399 }
207
208 void
209 397 segments_encoded_iter_base::
210 copy_impl(
211 char*& dest,
212 char const* end,
213 core::string_view s,
214 bool encode_colons) noexcept
215 {
216 397 encoding_opts opt;
217 397 opt.space_as_plus = false;
218
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 396 times.
397 detail::re_encode_unsafe(
219 dest,
220 end,
221 s,
222 encode_colons ?
223 nocolon_pchars :
224 pchars,
225 opt);
226 397 }
227
228 } // detail
229 } // urls
230 } // boost
231
232 #endif
233