src/detail/url_impl.cpp
94.4% Lines (101/107)
100.0% Functions (16/16)
94.1% Branches (32/34)
src/detail/url_impl.cpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2022 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 | #include <boost/url/detail/config.hpp> | ||
| 12 | #include <boost/url/detail/url_impl.hpp> | ||
| 13 | |||
| 14 | namespace boost { | ||
| 15 | namespace urls { | ||
| 16 | namespace detail { | ||
| 17 | |||
| 18 | //------------------------------------------------ | ||
| 19 | // | ||
| 20 | // path_ref | ||
| 21 | // | ||
| 22 | //------------------------------------------------ | ||
| 23 | |||
| 24 | 2 | path_ref:: | |
| 25 | path_ref() noexcept = default; | ||
| 26 | |||
| 27 | 2096 | path_ref:: | |
| 28 | path_ref( | ||
| 29 | 2096 | url_impl const& impl) noexcept | |
| 30 | { | ||
| 31 |
2/2✓ Branch 0 taken 1594 times.
✓ Branch 1 taken 502 times.
|
2096 | if(impl.from_ == url_impl::from::url) |
| 32 | { | ||
| 33 | 1594 | impl_ = &impl; | |
| 34 | } | ||
| 35 | else | ||
| 36 | { | ||
| 37 | 502 | core::string_view s = impl.get(id_path); | |
| 38 | 502 | data_ = s.data(); | |
| 39 | 502 | size_ = s.size(); | |
| 40 | 502 | nseg_ = impl.nseg_; | |
| 41 | 502 | dn_ = impl.decoded_[id_path]; | |
| 42 | } | ||
| 43 | 2096 | } | |
| 44 | |||
| 45 | 181 | path_ref:: | |
| 46 | path_ref( | ||
| 47 | core::string_view s, | ||
| 48 | std::size_t dn, | ||
| 49 | 181 | std::size_t nseg) noexcept | |
| 50 | 362 | : data_(s.data()) | |
| 51 | 181 | , size_(s.size()) | |
| 52 | 181 | , nseg_(nseg) | |
| 53 | 181 | , dn_(dn) | |
| 54 | { | ||
| 55 | 181 | } | |
| 56 | |||
| 57 | pct_string_view | ||
| 58 | 4738 | path_ref:: | |
| 59 | buffer() const noexcept | ||
| 60 | { | ||
| 61 |
2/2✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 2346 times.
|
4738 | if(impl_) |
| 62 | 2392 | return make_pct_string_view_unsafe( | |
| 63 | 2392 | impl_->cs_ + | |
| 64 | 2392 | impl_->offset(id_path), | |
| 65 | 2392 | impl_->len(id_path), | |
| 66 | 4784 | impl_->decoded_[id_path]); | |
| 67 | 2346 | return make_pct_string_view_unsafe( | |
| 68 | 2346 | data_, size_, dn_); | |
| 69 | } | ||
| 70 | |||
| 71 | std::size_t | ||
| 72 | 4487 | path_ref:: | |
| 73 | size() const noexcept | ||
| 74 | { | ||
| 75 |
2/2✓ Branch 0 taken 3116 times.
✓ Branch 1 taken 1371 times.
|
4487 | if(impl_) |
| 76 | 3116 | return impl_->len(id_path); | |
| 77 | 1371 | return size_; | |
| 78 | } | ||
| 79 | |||
| 80 | char const* | ||
| 81 | 12995 | path_ref:: | |
| 82 | data() const noexcept | ||
| 83 | { | ||
| 84 |
2/2✓ Branch 0 taken 7472 times.
✓ Branch 1 taken 5523 times.
|
12995 | if(impl_) |
| 85 | 7472 | return impl_->cs_ + | |
| 86 | 7472 | impl_->offset(id_path); | |
| 87 | 5523 | return data_; | |
| 88 | } | ||
| 89 | |||
| 90 | char const* | ||
| 91 | 4460 | path_ref:: | |
| 92 | end() const noexcept | ||
| 93 | { | ||
| 94 |
2/2✓ Branch 0 taken 2842 times.
✓ Branch 1 taken 1618 times.
|
4460 | if(impl_) |
| 95 | 2842 | return impl_->cs_ + | |
| 96 | 2842 | impl_->offset(id_query); | |
| 97 | 1618 | return data_ + size_; | |
| 98 | } | ||
| 99 | |||
| 100 | std::size_t | ||
| 101 | 9622 | path_ref:: | |
| 102 | nseg() const noexcept | ||
| 103 | { | ||
| 104 |
2/2✓ Branch 0 taken 6161 times.
✓ Branch 1 taken 3461 times.
|
9622 | if(impl_) |
| 105 | 6161 | return impl_->nseg_; | |
| 106 | 3461 | return nseg_; | |
| 107 | } | ||
| 108 | |||
| 109 | std::size_t | ||
| 110 | 2040 | path_ref:: | |
| 111 | decoded_size() const noexcept | ||
| 112 | { | ||
| 113 |
2/2✓ Branch 0 taken 1359 times.
✓ Branch 1 taken 681 times.
|
2040 | if(impl_) |
| 114 | 1359 | return impl_->decoded_[id_path]; | |
| 115 | 681 | return dn_; | |
| 116 | } | ||
| 117 | |||
| 118 | //------------------------------------------------ | ||
| 119 | // | ||
| 120 | // query_ref | ||
| 121 | // | ||
| 122 | //------------------------------------------------ | ||
| 123 | |||
| 124 | 255 | query_ref:: | |
| 125 | query_ref( | ||
| 126 | core::string_view s, | ||
| 127 | std::size_t dn, | ||
| 128 | 255 | std::size_t nparam) noexcept | |
| 129 | 510 | : data_(s.data()) | |
| 130 | 255 | , size_(s.size()) | |
| 131 | 255 | , nparam_(nparam) | |
| 132 | 255 | , dn_(dn) | |
| 133 | { | ||
| 134 | 255 | } | |
| 135 | |||
| 136 | 479 | query_ref:: | |
| 137 | query_ref( | ||
| 138 | 479 | url_impl const& impl) noexcept | |
| 139 | { | ||
| 140 |
2/2✓ Branch 0 taken 362 times.
✓ Branch 1 taken 117 times.
|
479 | if(impl.from_ == url_impl::from::url) |
| 141 | { | ||
| 142 | 362 | impl_ = &impl; | |
| 143 | } | ||
| 144 | else | ||
| 145 | { | ||
| 146 | 117 | core::string_view s = impl.get(id_query); | |
| 147 |
2/2✓ Branch 1 taken 111 times.
✓ Branch 2 taken 6 times.
|
117 | if (!s.empty()) |
| 148 | { | ||
| 149 | 111 | s.remove_prefix(1); | |
| 150 | 111 | question_mark_ = true; | |
| 151 | } | ||
| 152 | 117 | data_ = s.data(); | |
| 153 | 117 | size_ = s.size(); | |
| 154 | 117 | nparam_ = impl.nparam_; | |
| 155 | 117 | dn_ = impl.decoded_[id_query]; | |
| 156 | } | ||
| 157 | 479 | } | |
| 158 | |||
| 159 | pct_string_view | ||
| 160 | 24 | query_ref:: | |
| 161 | buffer() const noexcept | ||
| 162 | { | ||
| 163 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 22 times.
|
24 | if(impl_) |
| 164 | { | ||
| 165 | 2 | auto pos = impl_->offset_[id_query]; | |
| 166 | 2 | auto pos1 = impl_->offset_[id_frag]; | |
| 167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if(pos < pos1) |
| 168 | { | ||
| 169 | ✗ | ++pos; // no '?' | |
| 170 | ✗ | return make_pct_string_view_unsafe( | |
| 171 | ✗ | impl_->cs_ + pos, | |
| 172 | ✗ | pos1 - pos, | |
| 173 | ✗ | impl_->decoded_[id_query]); | |
| 174 | } | ||
| 175 | // empty | ||
| 176 | 2 | return make_pct_string_view_unsafe( | |
| 177 | 2 | impl_->cs_ + pos, | |
| 178 | 0, | ||
| 179 | 2 | 0); | |
| 180 | } | ||
| 181 | // no '?' | ||
| 182 | 22 | return make_pct_string_view_unsafe( | |
| 183 | 22 | data_, size_, dn_); | |
| 184 | } | ||
| 185 | |||
| 186 | // with '?' | ||
| 187 | std::size_t | ||
| 188 | 5562 | query_ref:: | |
| 189 | size() const noexcept | ||
| 190 | { | ||
| 191 |
2/2✓ Branch 0 taken 2029 times.
✓ Branch 1 taken 3533 times.
|
5562 | if(impl_) |
| 192 | 2029 | return impl_->len(id_query); | |
| 193 |
2/2✓ Branch 0 taken 3496 times.
✓ Branch 1 taken 37 times.
|
3533 | if(size_ > 0) |
| 194 | 3496 | return size_ + 1; | |
| 195 | 37 | return question_mark_; | |
| 196 | } | ||
| 197 | |||
| 198 | // no '?' | ||
| 199 | char const* | ||
| 200 | 6034 | query_ref:: | |
| 201 | begin() const noexcept | ||
| 202 | { | ||
| 203 |
2/2✓ Branch 0 taken 2288 times.
✓ Branch 1 taken 3746 times.
|
6034 | if(impl_) |
| 204 | { | ||
| 205 | // using the offset array here | ||
| 206 | 2288 | auto pos = impl_->offset_[id_query]; | |
| 207 | 2288 | auto pos1 = impl_->offset_[id_frag]; | |
| 208 |
1/2✓ Branch 0 taken 2288 times.
✗ Branch 1 not taken.
|
2288 | if(pos < pos1) |
| 209 | 2288 | return impl_->cs_ + pos + 1; // no '?' | |
| 210 | // empty | ||
| 211 | ✗ | return impl_->cs_ + pos; | |
| 212 | } | ||
| 213 | 3746 | return data_; | |
| 214 | } | ||
| 215 | |||
| 216 | char const* | ||
| 217 | 2380 | query_ref:: | |
| 218 | end() const noexcept | ||
| 219 | { | ||
| 220 |
2/2✓ Branch 0 taken 917 times.
✓ Branch 1 taken 1463 times.
|
2380 | if(impl_) |
| 221 | 917 | return impl_->cs_ + | |
| 222 | 917 | impl_->offset(id_frag); | |
| 223 | 1463 | return data_ + size_; | |
| 224 | } | ||
| 225 | |||
| 226 | std::size_t | ||
| 227 | 8862 | query_ref:: | |
| 228 | nparam() const noexcept | ||
| 229 | { | ||
| 230 |
2/2✓ Branch 0 taken 3171 times.
✓ Branch 1 taken 5691 times.
|
8862 | if(impl_) |
| 231 | 3171 | return impl_->nparam_; | |
| 232 | 5691 | return nparam_; | |
| 233 | } | ||
| 234 | |||
| 235 | } // detail | ||
| 236 | } // urls | ||
| 237 | } // boost | ||
| 238 |