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

84  

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

97  

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

111  

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

126  

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

139  

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

153  

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

169  

170  
} // urls
170  
} // urls
171  
} // boost
171  
} // boost
172  

172