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  

11  

12  
#include <boost/url/detail/config.hpp>
12  
#include <boost/url/detail/config.hpp>
13  
#include <boost/url/segments_encoded_ref.hpp>
13  
#include <boost/url/segments_encoded_ref.hpp>
14  
#include <boost/url/url.hpp>
14  
#include <boost/url/url.hpp>
15 -
#include "detail/path.hpp"
15 +
#include <boost/url/detail/path.hpp>
16  

16  

17  
namespace boost {
17  
namespace boost {
18  
namespace urls {
18  
namespace urls {
19  

19  

20  
//------------------------------------------------
20  
//------------------------------------------------
21  
//
21  
//
22  
// Special Members
22  
// Special Members
23  
//
23  
//
24  
//------------------------------------------------
24  
//------------------------------------------------
25  

25  

26  
segments_encoded_ref::
26  
segments_encoded_ref::
27  
segments_encoded_ref(
27  
segments_encoded_ref(
28  
    url_base& u) noexcept
28  
    url_base& u) noexcept
29  
    : segments_encoded_base(
29  
    : segments_encoded_base(
30  
        detail::path_ref(u.impl_))
30  
        detail::path_ref(u.impl_))
31  
    , u_(&u)
31  
    , u_(&u)
32  
{
32  
{
33  
}
33  
}
34  

34  

35  
segments_encoded_ref::
35  
segments_encoded_ref::
36  
operator
36  
operator
37  
segments_encoded_view() const noexcept
37  
segments_encoded_view() const noexcept
38  
{
38  
{
39  
    return segments_encoded_view(ref_);
39  
    return segments_encoded_view(ref_);
40  
}
40  
}
41  

41  

42  
segments_encoded_ref&
42  
segments_encoded_ref&
43  
segments_encoded_ref::
43  
segments_encoded_ref::
44  
operator=(
44  
operator=(
45  
    segments_encoded_ref const& other)
45  
    segments_encoded_ref const& other)
46  
{
46  
{
47  
    if (!ref_.alias_of(other.ref_))
47  
    if (!ref_.alias_of(other.ref_))
48  
        assign(other.begin(), other.end());
48  
        assign(other.begin(), other.end());
49  
    return *this;
49  
    return *this;
50  
}
50  
}
51  

51  

52  
segments_encoded_ref&
52  
segments_encoded_ref&
53  
segments_encoded_ref::
53  
segments_encoded_ref::
54  
operator=(
54  
operator=(
55  
    segments_encoded_view const& other)
55  
    segments_encoded_view const& other)
56  
{
56  
{
57  
    assign(other.begin(), other.end());
57  
    assign(other.begin(), other.end());
58  
    return *this;
58  
    return *this;
59  
}
59  
}
60  

60  

61  
segments_encoded_ref&
61  
segments_encoded_ref&
62  
segments_encoded_ref::
62  
segments_encoded_ref::
63  
operator=(std::initializer_list<
63  
operator=(std::initializer_list<
64  
    pct_string_view> init)
64  
    pct_string_view> init)
65  
{
65  
{
66  
    assign(init.begin(), init.end());
66  
    assign(init.begin(), init.end());
67  
    return *this;
67  
    return *this;
68  
}
68  
}
69  

69  

70  
//------------------------------------------------
70  
//------------------------------------------------
71  
//
71  
//
72  
// Modifiers
72  
// Modifiers
73  
//
73  
//
74  
//------------------------------------------------
74  
//------------------------------------------------
75  

75  

76  
void
76  
void
77  
segments_encoded_ref::
77  
segments_encoded_ref::
 
78 +
clear() noexcept
 
79 +
{
 
80 +
    erase(begin(), end());
 
81 +
}
 
82 +

 
83 +
void
 
84 +
segments_encoded_ref::
78  
assign(
85  
assign(
79  
    std::initializer_list<
86  
    std::initializer_list<
80  
        pct_string_view> init)
87  
        pct_string_view> init)
81  
{
88  
{
82  
    assign(init.begin(), init.end());
89  
    assign(init.begin(), init.end());
83  
}
90  
}
84  

91  

85  
auto
92  
auto
86  
segments_encoded_ref::
93  
segments_encoded_ref::
87  
insert(
94  
insert(
88  
    iterator before,
95  
    iterator before,
89  
    pct_string_view s) ->
96  
    pct_string_view s) ->
90  
        iterator
97  
        iterator
91  
{
98  
{
92  
    return u_->edit_segments(
99  
    return u_->edit_segments(
93  
        before.it_,
100  
        before.it_,
94  
        before.it_,
101  
        before.it_,
95  
        detail::segment_encoded_iter(s));
102  
        detail::segment_encoded_iter(s));
96  
}
103  
}
97  

104  

98  
auto
105  
auto
99  
segments_encoded_ref::
106  
segments_encoded_ref::
100  
insert(
107  
insert(
101  
    iterator before,
108  
    iterator before,
102  
    std::initializer_list<
109  
    std::initializer_list<
103  
            pct_string_view> init) ->
110  
            pct_string_view> init) ->
104  
        iterator
111  
        iterator
105  
{
112  
{
106  
    return insert(
113  
    return insert(
107  
        before,
114  
        before,
108  
        init.begin(),
115  
        init.begin(),
109  
        init.end());
116  
        init.end());
110  
}
117  
}
111  

118  

112  
auto
119  
auto
113  
segments_encoded_ref::
120  
segments_encoded_ref::
114  
erase(
121  
erase(
115  
    iterator first,
122  
    iterator first,
116  
    iterator last) noexcept ->
123  
    iterator last) noexcept ->
117  
        iterator
124  
        iterator
118  
{
125  
{
119  
    core::string_view s;
126  
    core::string_view s;
120  
    return u_->edit_segments(
127  
    return u_->edit_segments(
121  
        first.it_,
128  
        first.it_,
122  
        last.it_,
129  
        last.it_,
123  
        detail::make_segments_encoded_iter(
130  
        detail::make_segments_encoded_iter(
124  
            &s, &s));
131  
            &s, &s));
125  
}
132  
}
126  

133  

127  
auto
134  
auto
128  
segments_encoded_ref::
135  
segments_encoded_ref::
129  
replace(
136  
replace(
130  
    iterator pos,
137  
    iterator pos,
131  
    pct_string_view s) ->
138  
    pct_string_view s) ->
132  
        iterator
139  
        iterator
133  
{
140  
{
134  
    return u_->edit_segments(
141  
    return u_->edit_segments(
135  
        pos.it_,
142  
        pos.it_,
136  
        std::next(pos).it_,
143  
        std::next(pos).it_,
137  
        detail::segment_encoded_iter(s));
144  
        detail::segment_encoded_iter(s));
138  
}
145  
}
139  

146  

140  
auto
147  
auto
141  
segments_encoded_ref::
148  
segments_encoded_ref::
142  
replace(
149  
replace(
143  
    iterator from,
150  
    iterator from,
144  
    iterator to,
151  
    iterator to,
145  
    pct_string_view s) ->
152  
    pct_string_view s) ->
146  
        iterator
153  
        iterator
147  
{
154  
{
148  
    return u_->edit_segments(
155  
    return u_->edit_segments(
149  
        from.it_,
156  
        from.it_,
150  
        to.it_,
157  
        to.it_,
151  
        detail::segment_encoded_iter(s));
158  
        detail::segment_encoded_iter(s));
152  
}
159  
}
153  

160  

154  
auto
161  
auto
155  
segments_encoded_ref::
162  
segments_encoded_ref::
156  
replace(
163  
replace(
157  
    iterator from,
164  
    iterator from,
158  
    iterator to,
165  
    iterator to,
159  
    std::initializer_list<
166  
    std::initializer_list<
160  
        pct_string_view> init) ->
167  
        pct_string_view> init) ->
161  
    iterator
168  
    iterator
162  
{
169  
{
163  
    return replace(
170  
    return replace(
164  
        from,
171  
        from,
165  
        to,
172  
        to,
166  
        init.begin(),
173  
        init.begin(),
167  
        init.end());
174  
        init.end());
 
175 +
}
 
176 +

 
177 +
auto
 
178 +
segments_encoded_ref::
 
179 +
erase(
 
180 +
    iterator pos) noexcept ->
 
181 +
        iterator
 
182 +
{
 
183 +
    return erase(pos, std::next(pos));
 
184 +
}
 
185 +

 
186 +
void
 
187 +
segments_encoded_ref::
 
188 +
push_back(
 
189 +
    pct_string_view s)
 
190 +
{
 
191 +
    insert(end(), s);
 
192 +
}
 
193 +

 
194 +
void
 
195 +
segments_encoded_ref::
 
196 +
pop_back() noexcept
 
197 +
{
 
198 +
    erase(std::prev(end()));
168  
}
199  
}
169  

200  

170  
} // urls
201  
} // urls
171  
} // boost
202  
} // boost
172  

203