1  
//
1  
//
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3  
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
3  
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_REF_HPP
11  
#ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_REF_HPP
12  
#define BOOST_URL_IMPL_SEGMENTS_ENCODED_REF_HPP
12  
#define BOOST_URL_IMPL_SEGMENTS_ENCODED_REF_HPP
13  

13  

14  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/detail/config.hpp>
15  
#include <boost/url/detail/segments_iter_impl.hpp>
15  
#include <boost/url/detail/segments_iter_impl.hpp>
16  
#include <boost/url/detail/any_segments_iter.hpp>
16  
#include <boost/url/detail/any_segments_iter.hpp>
17  
#include <boost/url/detail/path.hpp>
17  
#include <boost/url/detail/path.hpp>
18  
#include <type_traits>
18  
#include <type_traits>
19  

19  

20  
namespace boost {
20  
namespace boost {
21  
namespace urls {
21  
namespace urls {
22  

22  

23  
//------------------------------------------------
23  
//------------------------------------------------
24  
//
24  
//
25  
// Modifiers
25  
// Modifiers
26  
//
26  
//
27  
//------------------------------------------------
27  
//------------------------------------------------
28  

28  

29  
template<class FwdIt>
29  
template<class FwdIt>
30  
void
30  
void
31  
segments_encoded_ref::
31  
segments_encoded_ref::
32  
assign(
32  
assign(
33  
    FwdIt first, FwdIt last)
33  
    FwdIt first, FwdIt last)
34  
{
34  
{
35  
/*  If you get a compile error here, it
35  
/*  If you get a compile error here, it
36  
    means that the iterators you passed
36  
    means that the iterators you passed
37  
    do not meet the requirements stated
37  
    do not meet the requirements stated
38  
    in the documentation.
38  
    in the documentation.
39  
*/
39  
*/
40  
    static_assert(
40  
    static_assert(
41  
        std::is_convertible<
41  
        std::is_convertible<
42  
            typename std::iterator_traits<
42  
            typename std::iterator_traits<
43  
                FwdIt>::reference,
43  
                FwdIt>::reference,
44  
            core::string_view>::value,
44  
            core::string_view>::value,
45  
        "Type requirements not met");
45  
        "Type requirements not met");
46  

46  

47  
    u_->edit_segments(
47  
    u_->edit_segments(
48  
        begin().it_,
48  
        begin().it_,
49  
        end().it_,
49  
        end().it_,
50  
        detail::make_segments_encoded_iter(
50  
        detail::make_segments_encoded_iter(
51  
            first, last));
51  
            first, last));
52  
}
52  
}
53  

53  

54  
template<class FwdIt>
54  
template<class FwdIt>
55  
auto
55  
auto
56  
segments_encoded_ref::
56  
segments_encoded_ref::
57  
insert(
57  
insert(
58  
    iterator before,
58  
    iterator before,
59  
    FwdIt first,
59  
    FwdIt first,
60  
    FwdIt last) ->
60  
    FwdIt last) ->
61  
        iterator
61  
        iterator
62  
{
62  
{
63  
/*  If you get a compile error here, it
63  
/*  If you get a compile error here, it
64  
    means that the iterators you passed
64  
    means that the iterators you passed
65  
    do not meet the requirements stated
65  
    do not meet the requirements stated
66  
    in the documentation.
66  
    in the documentation.
67  
*/
67  
*/
68  
    static_assert(
68  
    static_assert(
69  
        std::is_convertible<
69  
        std::is_convertible<
70  
            typename std::iterator_traits<
70  
            typename std::iterator_traits<
71  
                FwdIt>::reference,
71  
                FwdIt>::reference,
72  
            core::string_view>::value,
72  
            core::string_view>::value,
73  
        "Type requirements not met");
73  
        "Type requirements not met");
74  

74  

75  
    return insert(
75  
    return insert(
76  
        before,
76  
        before,
77  
        first,
77  
        first,
78  
        last,
78  
        last,
79  
        typename std::iterator_traits<
79  
        typename std::iterator_traits<
80  
            FwdIt>::iterator_category{});
80  
            FwdIt>::iterator_category{});
81  
}
81  
}
82  

82  

83  
template<class FwdIt>
83  
template<class FwdIt>
84  
auto
84  
auto
85  
segments_encoded_ref::
85  
segments_encoded_ref::
86  
replace(
86  
replace(
87  
    iterator from,
87  
    iterator from,
88  
    iterator to,
88  
    iterator to,
89  
    FwdIt first,
89  
    FwdIt first,
90  
    FwdIt last) ->
90  
    FwdIt last) ->
91  
        iterator
91  
        iterator
92  
{
92  
{
93  
/*  If you get a compile error here, it
93  
/*  If you get a compile error here, it
94  
    means that the iterators you passed
94  
    means that the iterators you passed
95  
    do not meet the requirements stated
95  
    do not meet the requirements stated
96  
    in the documentation.
96  
    in the documentation.
97  
*/
97  
*/
98  
    static_assert(
98  
    static_assert(
99  
        std::is_convertible<
99  
        std::is_convertible<
100  
            typename std::iterator_traits<
100  
            typename std::iterator_traits<
101  
                FwdIt>::reference,
101  
                FwdIt>::reference,
102  
            core::string_view>::value,
102  
            core::string_view>::value,
103  
        "Type requirements not met");
103  
        "Type requirements not met");
104  

104  

105  
    return u_->edit_segments(
105  
    return u_->edit_segments(
106  
        from.it_,
106  
        from.it_,
107  
        to.it_,
107  
        to.it_,
108  
        detail::make_segments_encoded_iter(
108  
        detail::make_segments_encoded_iter(
109  
            first, last));
109  
            first, last));
110  
}
110  
}
111  

111  

112  
//------------------------------------------------
112  
//------------------------------------------------
113  

113  

114  
template<class FwdIt>
114  
template<class FwdIt>
115  
auto
115  
auto
116  
segments_encoded_ref::
116  
segments_encoded_ref::
117  
insert(
117  
insert(
118  
    iterator before,
118  
    iterator before,
119  
    FwdIt first,
119  
    FwdIt first,
120  
    FwdIt last,
120  
    FwdIt last,
121  
    std::forward_iterator_tag) ->
121  
    std::forward_iterator_tag) ->
122  
        iterator
122  
        iterator
123  
{
123  
{
124  
    return u_->edit_segments(
124  
    return u_->edit_segments(
125  
        before.it_,
125  
        before.it_,
126  
        before.it_,
126  
        before.it_,
127  
        detail::make_segments_encoded_iter(
127  
        detail::make_segments_encoded_iter(
128  
            first, last));
128  
            first, last));
129  
}
129  
}
130  

130  

131  
//------------------------------------------------
131  
//------------------------------------------------
132  
//
132  
//
133  
// Special Members
133  
// Special Members
134  
//
134  
//
135  
//------------------------------------------------
135  
//------------------------------------------------
136  

136  

137  
inline
137  
inline
138  
segments_encoded_ref::
138  
segments_encoded_ref::
139  
segments_encoded_ref(
139  
segments_encoded_ref(
140  
    url_base& u) noexcept
140  
    url_base& u) noexcept
141  
    : segments_encoded_base(
141  
    : segments_encoded_base(
142  
        detail::path_ref(u.impl_))
142  
        detail::path_ref(u.impl_))
143  
    , u_(&u)
143  
    , u_(&u)
144  
{
144  
{
145  
}
145  
}
146  

146  

147  
inline
147  
inline
148  
segments_encoded_ref::
148  
segments_encoded_ref::
149  
operator
149  
operator
150  
segments_encoded_view() const noexcept
150  
segments_encoded_view() const noexcept
151  
{
151  
{
152  
    return segments_encoded_view(ref_);
152  
    return segments_encoded_view(ref_);
153  
}
153  
}
154  

154  

155  
inline
155  
inline
156  
segments_encoded_ref&
156  
segments_encoded_ref&
157  
segments_encoded_ref::
157  
segments_encoded_ref::
158  
operator=(
158  
operator=(
159  
    segments_encoded_ref const& other)
159  
    segments_encoded_ref const& other)
160  
{
160  
{
161  
    if (!ref_.alias_of(other.ref_))
161  
    if (!ref_.alias_of(other.ref_))
162  
        assign(other.begin(), other.end());
162  
        assign(other.begin(), other.end());
163  
    return *this;
163  
    return *this;
164  
}
164  
}
165  

165  

166  
inline
166  
inline
167  
segments_encoded_ref&
167  
segments_encoded_ref&
168  
segments_encoded_ref::
168  
segments_encoded_ref::
169  
operator=(
169  
operator=(
170  
    segments_encoded_view const& other)
170  
    segments_encoded_view const& other)
171  
{
171  
{
172  
    assign(other.begin(), other.end());
172  
    assign(other.begin(), other.end());
173  
    return *this;
173  
    return *this;
174  
}
174  
}
175  

175  

176  
inline
176  
inline
177  
segments_encoded_ref&
177  
segments_encoded_ref&
178  
segments_encoded_ref::
178  
segments_encoded_ref::
179  
operator=(std::initializer_list<
179  
operator=(std::initializer_list<
180  
    pct_string_view> init)
180  
    pct_string_view> init)
181  
{
181  
{
182  
    assign(init.begin(), init.end());
182  
    assign(init.begin(), init.end());
183  
    return *this;
183  
    return *this;
184  
}
184  
}
185  

185  

186  
//------------------------------------------------
186  
//------------------------------------------------
187  
//
187  
//
188  
// Modifiers
188  
// Modifiers
189  
//
189  
//
190  
//------------------------------------------------
190  
//------------------------------------------------
191  

191  

192  
inline
192  
inline
193  
void
193  
void
194  
segments_encoded_ref::
194  
segments_encoded_ref::
195  
clear() noexcept
195  
clear() noexcept
196  
{
196  
{
197  
    erase(begin(), end());
197  
    erase(begin(), end());
198  
}
198  
}
199  

199  

200  
inline
200  
inline
201  
void
201  
void
202  
segments_encoded_ref::
202  
segments_encoded_ref::
203  
assign(
203  
assign(
204  
    std::initializer_list<
204  
    std::initializer_list<
205  
        pct_string_view> init)
205  
        pct_string_view> init)
206  
{
206  
{
207  
    assign(init.begin(), init.end());
207  
    assign(init.begin(), init.end());
208  
}
208  
}
209  

209  

210  
inline
210  
inline
211  
auto
211  
auto
212  
segments_encoded_ref::
212  
segments_encoded_ref::
213  
insert(
213  
insert(
214  
    iterator before,
214  
    iterator before,
215  
    pct_string_view s) ->
215  
    pct_string_view s) ->
216  
        iterator
216  
        iterator
217  
{
217  
{
218  
    return u_->edit_segments(
218  
    return u_->edit_segments(
219  
        before.it_,
219  
        before.it_,
220  
        before.it_,
220  
        before.it_,
221  
        detail::segment_encoded_iter(s));
221  
        detail::segment_encoded_iter(s));
222  
}
222  
}
223  

223  

224  
inline
224  
inline
225  
auto
225  
auto
226  
segments_encoded_ref::
226  
segments_encoded_ref::
227  
insert(
227  
insert(
228  
    iterator before,
228  
    iterator before,
229  
    std::initializer_list<
229  
    std::initializer_list<
230  
            pct_string_view> init) ->
230  
            pct_string_view> init) ->
231  
        iterator
231  
        iterator
232  
{
232  
{
233  
    return insert(
233  
    return insert(
234  
        before,
234  
        before,
235  
        init.begin(),
235  
        init.begin(),
236  
        init.end());
236  
        init.end());
237  
}
237  
}
238  

238  

239  
inline
239  
inline
240  
auto
240  
auto
241  
segments_encoded_ref::
241  
segments_encoded_ref::
242  
erase(
242  
erase(
243  
    iterator first,
243  
    iterator first,
244  
    iterator last) noexcept ->
244  
    iterator last) noexcept ->
245  
        iterator
245  
        iterator
246  
{
246  
{
247  
    core::string_view s;
247  
    core::string_view s;
248  
    return u_->edit_segments(
248  
    return u_->edit_segments(
249  
        first.it_,
249  
        first.it_,
250  
        last.it_,
250  
        last.it_,
251  
        detail::make_segments_encoded_iter(
251  
        detail::make_segments_encoded_iter(
252  
            &s, &s));
252  
            &s, &s));
253  
}
253  
}
254  

254  

255  
inline
255  
inline
256  
auto
256  
auto
257  
segments_encoded_ref::
257  
segments_encoded_ref::
258  
replace(
258  
replace(
259  
    iterator pos,
259  
    iterator pos,
260  
    pct_string_view s) ->
260  
    pct_string_view s) ->
261  
        iterator
261  
        iterator
262  
{
262  
{
263  
    return u_->edit_segments(
263  
    return u_->edit_segments(
264  
        pos.it_,
264  
        pos.it_,
265  
        std::next(pos).it_,
265  
        std::next(pos).it_,
266  
        detail::segment_encoded_iter(s));
266  
        detail::segment_encoded_iter(s));
267  
}
267  
}
268  

268  

269  
inline
269  
inline
270  
auto
270  
auto
271  
segments_encoded_ref::
271  
segments_encoded_ref::
272  
replace(
272  
replace(
273  
    iterator from,
273  
    iterator from,
274  
    iterator to,
274  
    iterator to,
275  
    pct_string_view s) ->
275  
    pct_string_view s) ->
276  
        iterator
276  
        iterator
277  
{
277  
{
278  
    return u_->edit_segments(
278  
    return u_->edit_segments(
279  
        from.it_,
279  
        from.it_,
280  
        to.it_,
280  
        to.it_,
281  
        detail::segment_encoded_iter(s));
281  
        detail::segment_encoded_iter(s));
282  
}
282  
}
283  

283  

284  
inline
284  
inline
285  
auto
285  
auto
286  
segments_encoded_ref::
286  
segments_encoded_ref::
287  
replace(
287  
replace(
288  
    iterator from,
288  
    iterator from,
289  
    iterator to,
289  
    iterator to,
290  
    std::initializer_list<
290  
    std::initializer_list<
291  
        pct_string_view> init) ->
291  
        pct_string_view> init) ->
292  
    iterator
292  
    iterator
293  
{
293  
{
294  
    return replace(
294  
    return replace(
295  
        from,
295  
        from,
296  
        to,
296  
        to,
297  
        init.begin(),
297  
        init.begin(),
298  
        init.end());
298  
        init.end());
299  
}
299  
}
300  

300  

301  
inline
301  
inline
302  
auto
302  
auto
303  
segments_encoded_ref::
303  
segments_encoded_ref::
304  
erase(
304  
erase(
305  
    iterator pos) noexcept ->
305  
    iterator pos) noexcept ->
306  
        iterator
306  
        iterator
307  
{
307  
{
308  
    return erase(pos, std::next(pos));
308  
    return erase(pos, std::next(pos));
309  
}
309  
}
310  

310  

311  
inline
311  
inline
312  
void
312  
void
313  
segments_encoded_ref::
313  
segments_encoded_ref::
314  
push_back(
314  
push_back(
315  
    pct_string_view s)
315  
    pct_string_view s)
316  
{
316  
{
317  
    insert(end(), s);
317  
    insert(end(), s);
318  
}
318  
}
319  

319  

320  
inline
320  
inline
321  
void
321  
void
322  
segments_encoded_ref::
322  
segments_encoded_ref::
323  
pop_back() noexcept
323  
pop_back() noexcept
324  
{
324  
{
325  
    erase(std::prev(end()));
325  
    erase(std::prev(end()));
326  
}
326  
}
327  

327  

328  
} // urls
328  
} // urls
329  
} // boost
329  
} // boost
330  

330  

331  
#endif
331  
#endif