| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
|
2 |
|
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
|
| 3 |
|
|
3 |
|
|
| 4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
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)
|
5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
|
|
6 |
|
|
| 7 |
|
// Official repository: https://github.com/boostorg/url
|
7 |
|
// Official repository: https://github.com/boostorg/url
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_URL_DETAIL_SEGMENTS_RANGE_HPP
|
10 |
|
#ifndef BOOST_URL_DETAIL_SEGMENTS_RANGE_HPP
|
| 11 |
|
#define BOOST_URL_DETAIL_SEGMENTS_RANGE_HPP
|
11 |
|
#define BOOST_URL_DETAIL_SEGMENTS_RANGE_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/url/detail/config.hpp>
|
13 |
|
#include <boost/url/detail/config.hpp>
|
| 14 |
|
#include <boost/url/detail/url_impl.hpp>
|
14 |
|
#include <boost/url/detail/url_impl.hpp>
|
| 15 |
|
#include <boost/url/segments_base.hpp>
|
15 |
|
#include <boost/url/segments_base.hpp>
|
| 16 |
|
#include <boost/url/segments_encoded_base.hpp>
|
16 |
|
#include <boost/url/segments_encoded_base.hpp>
|
| 17 |
|
#include <boost/core/detail/string_view.hpp>
|
17 |
|
#include <boost/core/detail/string_view.hpp>
|
| 18 |
|
#include <boost/assert.hpp>
|
18 |
|
#include <boost/assert.hpp>
|
| 19 |
|
|
19 |
|
|
| 20 |
|
|
20 |
|
|
| 21 |
|
|
21 |
|
|
| 22 |
|
|
22 |
|
|
| 23 |
|
|
23 |
|
|
| 24 |
|
struct segments_iter_access
|
24 |
|
struct segments_iter_access
|
| 25 |
|
|
25 |
|
|
| 26 |
|
|
26 |
|
|
| 27 |
|
segments_iter_impl const&
|
27 |
|
segments_iter_impl const&
|
| 28 |
|
impl(segments_base::iterator const& it) noexcept
|
28 |
|
impl(segments_base::iterator const& it) noexcept
|
| 29 |
|
|
29 |
|
|
| 30 |
|
|
30 |
|
|
| 31 |
|
|
31 |
|
|
| 32 |
|
|
32 |
|
|
| 33 |
|
|
33 |
|
|
| 34 |
|
segments_iter_impl const&
|
34 |
|
segments_iter_impl const&
|
| 35 |
|
impl(segments_encoded_base::iterator const& it) noexcept
|
35 |
|
impl(segments_encoded_base::iterator const& it) noexcept
|
| 36 |
|
|
36 |
|
|
| 37 |
|
|
37 |
|
|
| 38 |
|
|
38 |
|
|
| 39 |
|
|
39 |
|
|
| 40 |
|
|
40 |
|
|
| 41 |
|
|
41 |
|
|
| 42 |
|
|
42 |
|
|
| 43 |
|
|
43 |
|
|
| 44 |
|
segments_iter_impl const& first,
|
44 |
|
segments_iter_impl const& first,
|
| 45 |
|
segments_iter_impl const& last) noexcept
|
45 |
|
segments_iter_impl const& last) noexcept
|
| 46 |
|
|
46 |
|
|
| 47 |
|
BOOST_ASSERT(first.ref.alias_of(last.ref));
|
47 |
|
BOOST_ASSERT(first.ref.alias_of(last.ref));
|
| 48 |
|
path_ref const& ref = first.ref;
|
48 |
|
path_ref const& ref = first.ref;
|
| 49 |
|
|
49 |
|
|
| 50 |
|
std::size_t const i0 = first.index;
|
50 |
|
std::size_t const i0 = first.index;
|
| 51 |
|
std::size_t const i1 = last.index;
|
51 |
|
std::size_t const i1 = last.index;
|
| 52 |
|
|
52 |
|
|
| 53 |
|
std::size_t const nseg = i1 - i0;
|
53 |
|
std::size_t const nseg = i1 - i0;
|
| 54 |
|
|
54 |
|
|
| 55 |
|
bool const absolute = ref.buffer().starts_with('/');
|
55 |
|
bool const absolute = ref.buffer().starts_with('/');
|
| 56 |
|
|
56 |
|
|
| 57 |
|
|
57 |
|
|
| 58 |
|
|
58 |
|
|
| 59 |
|
|
59 |
|
|
| 60 |
|
|
60 |
|
|
| 61 |
|
|
61 |
|
|
| 62 |
|
|
62 |
|
|
| 63 |
|
// [begin, begin): don't include the leading '/'
|
63 |
|
// [begin, begin): don't include the leading '/'
|
| 64 |
|
// for absolute, start right after the leading '/';
|
64 |
|
// for absolute, start right after the leading '/';
|
| 65 |
|
|
65 |
|
|
| 66 |
|
|
66 |
|
|
| 67 |
|
|
67 |
|
|
| 68 |
|
|
68 |
|
|
| 69 |
|
// for relative, start at the first segment character.
|
69 |
|
// for relative, start at the first segment character.
|
| 70 |
|
|
70 |
|
|
| 71 |
|
|
71 |
|
|
| 72 |
|
|
72 |
|
|
| 73 |
|
|
73 |
|
|
| 74 |
|
|
74 |
|
|
| 75 |
|
|
75 |
|
|
| 76 |
|
|
76 |
|
|
| 77 |
|
// [it, it) in the middle:
|
77 |
|
// [it, it) in the middle:
|
| 78 |
|
// skip the separator before segment i0
|
78 |
|
// skip the separator before segment i0
|
| 79 |
|
|
79 |
|
|
| 80 |
|
|
80 |
|
|
| 81 |
|
|
81 |
|
|
| 82 |
|
core::string_view const sub(ref.data() + off0, 0);
|
82 |
|
core::string_view const sub(ref.data() + off0, 0);
|
| 83 |
|
|
83 |
|
|
| 84 |
|
|
84 |
|
|
| 85 |
|
|
85 |
|
|
| 86 |
|
// General case: non-empty range
|
86 |
|
// General case: non-empty range
|
| 87 |
|
|
87 |
|
|
| 88 |
|
|
88 |
|
|
| 89 |
|
|
89 |
|
|
| 90 |
|
|
90 |
|
|
| 91 |
|
|
91 |
|
|
| 92 |
|
|
92 |
|
|
| 93 |
|
|
93 |
|
|
| 94 |
|
|
94 |
|
|
| 95 |
|
|
95 |
|
|
| 96 |
|
|
96 |
|
|
| 97 |
|
|
97 |
|
|
| 98 |
|
// relative: start at first segment
|
98 |
|
// relative: start at first segment
|
| 99 |
|
|
99 |
|
|
| 100 |
|
|
100 |
|
|
| 101 |
|
|
101 |
|
|
| 102 |
|
|
102 |
|
|
| 103 |
|
|
103 |
|
|
| 104 |
|
// include the separator preceding segment i0
|
104 |
|
// include the separator preceding segment i0
|
| 105 |
|
|
105 |
|
|
| 106 |
|
|
106 |
|
|
| 107 |
|
|
107 |
|
|
| 108 |
|
|
108 |
|
|
| 109 |
|
|
109 |
|
|
| 110 |
|
|
110 |
|
|
| 111 |
|
|
111 |
|
|
| 112 |
|
|
112 |
|
|
| 113 |
|
|
113 |
|
|
| 114 |
|
|
114 |
|
|
| 115 |
|
|
115 |
|
|
| 116 |
|
// stop before the slash preceding i1
|
116 |
|
// stop before the slash preceding i1
|
| 117 |
|
|
117 |
|
|
| 118 |
|
|
118 |
|
|
| 119 |
|
|
119 |
|
|
| 120 |
|
BOOST_ASSERT(off1 >= off0);
|
120 |
|
BOOST_ASSERT(off1 >= off0);
|
| 121 |
|
core::string_view const sub(ref.data() + off0, off1 - off0);
|
121 |
|
core::string_view const sub(ref.data() + off0, off1 - off0);
|
| 122 |
|
|
122 |
|
|
| 123 |
|
// decoded sizes reuse iterator bookkeeping instead of rescanning
|
123 |
|
// decoded sizes reuse iterator bookkeeping instead of rescanning
|
| 124 |
|
std::size_t start_dn = (i0 == 0) ? 0 : first.decoded_prefix_size();
|
124 |
|
std::size_t start_dn = (i0 == 0) ? 0 : first.decoded_prefix_size();
|
| 125 |
|
std::size_t const end_dn = last.decoded_prefix_size(); // already excludes segment at `last`
|
125 |
|
std::size_t const end_dn = last.decoded_prefix_size(); // already excludes segment at `last`
|
| 126 |
|
BOOST_ASSERT(end_dn >= start_dn);
|
126 |
|
BOOST_ASSERT(end_dn >= start_dn);
|
| 127 |
|
std::size_t const dn_sum = end_dn - start_dn;
|
127 |
|
std::size_t const dn_sum = end_dn - start_dn;
|
| 128 |
|
|
128 |
|
|
| 129 |
|
return {sub, dn_sum, nseg};
|
129 |
|
return {sub, dn_sum, nseg};
|
| 130 |
|
|
130 |
|
|
| 131 |
|
|
131 |
|
|
| 132 |
|
|
132 |
|
|
| 133 |
|
|
133 |
|
|
| 134 |
|
|
134 |
|
|
| 135 |
|
make_subref(Iter const& first, Iter const& last) noexcept
|
135 |
|
make_subref(Iter const& first, Iter const& last) noexcept
|
| 136 |
|
|
136 |
|
|
| 137 |
|
auto const& f = segments_iter_access::impl(first);
|
137 |
|
auto const& f = segments_iter_access::impl(first);
|
| 138 |
|
auto const& l = segments_iter_access::impl(last);
|
138 |
|
auto const& l = segments_iter_access::impl(last);
|
| 139 |
|
return make_subref_from_impls(f, l);
|
139 |
|
return make_subref_from_impls(f, l);
|
| 140 |
|
|
140 |
|
|
| 141 |
|
|
141 |
|
|
| 142 |
|
|
142 |
|
|
| 143 |
|
|
143 |
|
|
| 144 |
|
|
144 |
|
|
| 145 |
|
|
145 |
|
|
| 146 |
|
|
146 |
|
|