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