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 <type_traits>
17  
#include <type_traits>
18  

18  

19  
namespace boost {
19  
namespace boost {
20  
namespace urls {
20  
namespace urls {
21  

21  

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

27  

28  
inline
28  
inline
29  
void
29  
void
30  
segments_encoded_ref::
30  
segments_encoded_ref::
31  
clear() noexcept
31  
clear() noexcept
32  
{
32  
{
33  
    erase(begin(), end());
33  
    erase(begin(), end());
34  
}
34  
}
35  

35  

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

53  

54  
    u_->edit_segments(
54  
    u_->edit_segments(
55  
        begin().it_,
55  
        begin().it_,
56  
        end().it_,
56  
        end().it_,
57  
        detail::make_segments_encoded_iter(
57  
        detail::make_segments_encoded_iter(
58  
            first, last));
58  
            first, last));
59  
}
59  
}
60  

60  

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

81  

82  
    return insert(
82  
    return insert(
83  
        before,
83  
        before,
84  
        first,
84  
        first,
85  
        last,
85  
        last,
86  
        typename std::iterator_traits<
86  
        typename std::iterator_traits<
87  
            FwdIt>::iterator_category{});
87  
            FwdIt>::iterator_category{});
88  
}
88  
}
89  

89  

90  
inline
90  
inline
91  
auto
91  
auto
92  
segments_encoded_ref::
92  
segments_encoded_ref::
93  
erase(
93  
erase(
94  
    iterator pos) noexcept ->
94  
    iterator pos) noexcept ->
95  
        iterator
95  
        iterator
96  
{
96  
{
97  
    return erase(pos, std::next(pos));
97  
    return erase(pos, std::next(pos));
98  
}
98  
}
99  

99  

100  
template<class FwdIt>
100  
template<class FwdIt>
101  
auto
101  
auto
102  
segments_encoded_ref::
102  
segments_encoded_ref::
103  
replace(
103  
replace(
104  
    iterator from,
104  
    iterator from,
105  
    iterator to,
105  
    iterator to,
106  
    FwdIt first,
106  
    FwdIt first,
107  
    FwdIt last) ->
107  
    FwdIt last) ->
108  
        iterator
108  
        iterator
109  
{
109  
{
110  
/*  If you get a compile error here, it
110  
/*  If you get a compile error here, it
111  
    means that the iterators you passed
111  
    means that the iterators you passed
112  
    do not meet the requirements stated
112  
    do not meet the requirements stated
113  
    in the documentation.
113  
    in the documentation.
114  
*/
114  
*/
115  
    static_assert(
115  
    static_assert(
116  
        std::is_convertible<
116  
        std::is_convertible<
117  
            typename std::iterator_traits<
117  
            typename std::iterator_traits<
118  
                FwdIt>::reference,
118  
                FwdIt>::reference,
119  
            core::string_view>::value,
119  
            core::string_view>::value,
120  
        "Type requirements not met");
120  
        "Type requirements not met");
121  

121  

122  
    return u_->edit_segments(
122  
    return u_->edit_segments(
123  
        from.it_,
123  
        from.it_,
124  
        to.it_,
124  
        to.it_,
125  
        detail::make_segments_encoded_iter(
125  
        detail::make_segments_encoded_iter(
126  
            first, last));
126  
            first, last));
127  
}
127  
}
128  

128  

129  
//------------------------------------------------
129  
//------------------------------------------------
130  

130  

131  
inline
131  
inline
132  
void
132  
void
133  
segments_encoded_ref::
133  
segments_encoded_ref::
134  
push_back(
134  
push_back(
135  
    pct_string_view s)
135  
    pct_string_view s)
136  
{
136  
{
137  
    insert(end(), s);
137  
    insert(end(), s);
138  
}
138  
}
139  

139  

140  
inline
140  
inline
141  
void
141  
void
142  
segments_encoded_ref::
142  
segments_encoded_ref::
143  
pop_back() noexcept
143  
pop_back() noexcept
144  
{
144  
{
145  
    erase(std::prev(end()));
145  
    erase(std::prev(end()));
146  
}
146  
}
147  

147  

148  
//------------------------------------------------
148  
//------------------------------------------------
149  

149  

150  
template<class FwdIt>
150  
template<class FwdIt>
151  
auto
151  
auto
152  
segments_encoded_ref::
152  
segments_encoded_ref::
153  
insert(
153  
insert(
154  
    iterator before,
154  
    iterator before,
155  
    FwdIt first,
155  
    FwdIt first,
156  
    FwdIt last,
156  
    FwdIt last,
157  
    std::forward_iterator_tag) ->
157  
    std::forward_iterator_tag) ->
158  
        iterator
158  
        iterator
159  
{
159  
{
160  
    return u_->edit_segments(
160  
    return u_->edit_segments(
161  
        before.it_,
161  
        before.it_,
162  
        before.it_,
162  
        before.it_,
163  
        detail::make_segments_encoded_iter(
163  
        detail::make_segments_encoded_iter(
164  
            first, last));
164  
            first, last));
165  
}
165  
}
166  

166  

167  
} // urls
167  
} // urls
168  
} // boost
168  
} // boost
169  

169  

170  
#endif
170  
#endif