src/detail/any_segments_iter.cpp

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