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 "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  
assign(std::initializer_list<
77  
assign(std::initializer_list<
78  
    core::string_view> init)
78  
    core::string_view> init)
79  
{
79  
{
80  
    assign(init.begin(), init.end());
80  
    assign(init.begin(), init.end());
81  
}
81  
}
82  

82  

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

95  

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

109  

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

125  

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

138  

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

152  

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

168  

169  
} // urls
169  
} // urls
170  
} // boost
170  
} // boost
171  

171