| 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 | encoding_opts opt; | |
| 154 | 72 | opt.space_as_plus = false; | |
| 155 | 72 | n += detail::re_encoded_size_unsafe( | |
| 156 | s, | ||
| 157 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 70 times.
|
72 | encode_colons ? |
| 158 | nocolon_pchars : | ||
| 159 | pchars, | ||
| 160 | opt); | ||
| 161 | 72 | at_end_ = true; | |
| 162 | 72 | return true; | |
| 163 | } | ||
| 164 | |||
| 165 | void | ||
| 166 | 72 | segment_encoded_iter:: | |
| 167 | copy( | ||
| 168 | char*& dest, | ||
| 169 | char const* end) noexcept | ||
| 170 | { | ||
| 171 | 72 | encoding_opts opt; | |
| 172 | 72 | opt.space_as_plus = false; | |
| 173 | 72 | detail::re_encode_unsafe( | |
| 174 | dest, | ||
| 175 | end, | ||
| 176 | s, | ||
| 177 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 70 times.
|
72 | encode_colons ? |
| 178 | nocolon_pchars : | ||
| 179 | pchars, | ||
| 180 | opt); | ||
| 181 | 72 | } | |
| 182 | |||
| 183 | //------------------------------------------------ | ||
| 184 | // | ||
| 185 | // segments_encoded_iter_base | ||
| 186 | // | ||
| 187 | //------------------------------------------------ | ||
| 188 | |||
| 189 | void | ||
| 190 | 399 | segments_encoded_iter_base:: | |
| 191 | measure_impl( | ||
| 192 | std::size_t& n, | ||
| 193 | core::string_view s, | ||
| 194 | bool encode_colons) noexcept | ||
| 195 | { | ||
| 196 | 399 | encoding_opts opt; | |
| 197 | 399 | opt.space_as_plus = false; | |
| 198 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 398 times.
|
399 | n += detail::re_encoded_size_unsafe( |
| 199 | s, | ||
| 200 | encode_colons ? | ||
| 201 | nocolon_pchars : | ||
| 202 | pchars, | ||
| 203 | opt); | ||
| 204 | 399 | } | |
| 205 | |||
| 206 | void | ||
| 207 | 397 | segments_encoded_iter_base:: | |
| 208 | copy_impl( | ||
| 209 | char*& dest, | ||
| 210 | char const* end, | ||
| 211 | core::string_view s, | ||
| 212 | bool encode_colons) noexcept | ||
| 213 | { | ||
| 214 | 397 | encoding_opts opt; | |
| 215 | 397 | opt.space_as_plus = false; | |
| 216 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 396 times.
|
397 | detail::re_encode_unsafe( |
| 217 | dest, | ||
| 218 | end, | ||
| 219 | s, | ||
| 220 | encode_colons ? | ||
| 221 | nocolon_pchars : | ||
| 222 | pchars, | ||
| 223 | opt); | ||
| 224 | 397 | } | |
| 225 | |||
| 226 | } // detail | ||
| 227 | } // urls | ||
| 228 | } // boost | ||
| 229 | |||
| 230 |