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_ref.hpp>
13  
#include <boost/url/segments_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  
#include <boost/assert.hpp>
16  
#include <boost/assert.hpp>
17  

17  

18  
namespace boost {
18  
namespace boost {
19  
namespace urls {
19  
namespace urls {
20  

20  

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

26  

27  
segments_ref::
27  
segments_ref::
28  
segments_ref(
28  
segments_ref(
29  
    url_base& u) noexcept
29  
    url_base& u) noexcept
30  
    : segments_base(
30  
    : segments_base(
31  
        detail::path_ref(u.impl_))
31  
        detail::path_ref(u.impl_))
32  
    , u_(&u)
32  
    , u_(&u)
33  
{
33  
{
34  
}
34  
}
35  

35  

36  
segments_ref::
36  
segments_ref::
37  
operator
37  
operator
38  
segments_view() const noexcept
38  
segments_view() const noexcept
39  
{
39  
{
40  
    return segments_view(ref_);
40  
    return segments_view(ref_);
41  
}
41  
}
42  

42  

43  
segments_ref&
43  
segments_ref&
44  
segments_ref::
44  
segments_ref::
45  
operator=(segments_ref const& other)
45  
operator=(segments_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_ref&
52  
segments_ref&
53  
segments_ref::
53  
segments_ref::
54  
operator=(segments_view const& other)
54  
operator=(segments_view const& other)
55  
{
55  
{
56  
    assign(other.begin(), other.end());
56  
    assign(other.begin(), other.end());
57  
    return *this;
57  
    return *this;
58  
}
58  
}
59  

59  

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

68  

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

74  

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

 
82 +
void
 
83 +
segments_ref::
77  
assign(std::initializer_list<
84  
assign(std::initializer_list<
78  
    core::string_view> init)
85  
    core::string_view> init)
79  
{
86  
{
80  
    assign(init.begin(), init.end());
87  
    assign(init.begin(), init.end());
81  
}
88  
}
82  

89  

83  
auto
90  
auto
84  
segments_ref::
91  
segments_ref::
85  
insert(
92  
insert(
86  
    iterator before,
93  
    iterator before,
87  
    core::string_view s) ->
94  
    core::string_view s) ->
88  
        iterator
95  
        iterator
89  
{
96  
{
90  
    return u_->edit_segments(
97  
    return u_->edit_segments(
91  
        before.it_,
98  
        before.it_,
92  
        before.it_,
99  
        before.it_,
93  
        detail::segment_iter(s));
100  
        detail::segment_iter(s));
94  
}
101  
}
95  

102  

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

116  

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

131  

126  
auto
132  
auto
127  
segments_ref::
133  
segments_ref::
128  
replace(
134  
replace(
129  
    iterator pos,
135  
    iterator pos,
130  
    core::string_view s) ->
136  
    core::string_view s) ->
131  
        iterator
137  
        iterator
132  
{
138  
{
133  
    return u_->edit_segments(
139  
    return u_->edit_segments(
134  
        pos.it_,
140  
        pos.it_,
135  
        std::next(pos).it_,
141  
        std::next(pos).it_,
136  
        detail::segment_iter(s));
142  
        detail::segment_iter(s));
137  
}
143  
}
138  

144  

139  
auto
145  
auto
140  
segments_ref::
146  
segments_ref::
141  
replace(
147  
replace(
142  
    iterator from,
148  
    iterator from,
143  
    iterator to,
149  
    iterator to,
144  
    core::string_view s) ->
150  
    core::string_view s) ->
145  
        iterator
151  
        iterator
146  
{
152  
{
147  
    return u_->edit_segments(
153  
    return u_->edit_segments(
148  
        from.it_,
154  
        from.it_,
149  
        to.it_,
155  
        to.it_,
150  
        detail::segment_iter(s));
156  
        detail::segment_iter(s));
151  
}
157  
}
152  

158  

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

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

 
184 +
void
 
185 +
segments_ref::
 
186 +
push_back(
 
187 +
    core::string_view s)
 
188 +
{
 
189 +
    insert(end(), s);
 
190 +
}
 
191 +

 
192 +
void
 
193 +
segments_ref::
 
194 +
pop_back() noexcept
 
195 +
{
 
196 +
    erase(std::prev(end()));
167  
}
197  
}
168  

198  

169  
} // urls
199  
} // urls
170  
} // boost
200  
} // boost
171  

201