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_PARAMS_ENCODED_REF_HPP
11  
#ifndef BOOST_URL_IMPL_PARAMS_ENCODED_REF_HPP
12  
#define BOOST_URL_IMPL_PARAMS_ENCODED_REF_HPP
12  
#define BOOST_URL_IMPL_PARAMS_ENCODED_REF_HPP
13  

13  

14  
#include <boost/url/detail/except.hpp>
14  
#include <boost/url/detail/except.hpp>
15  
#include <boost/assert.hpp>
15  
#include <boost/assert.hpp>
16  

16  

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

19  

20  
//------------------------------------------------
20  
//------------------------------------------------
21  
//
21  
//
22  
// Modifiers
22  
// Modifiers
23  
//
23  
//
24  
//------------------------------------------------
24  
//------------------------------------------------
25  

25  

26  
inline
26  
inline
27  
void
27  
void
28  
params_encoded_ref::
28  
params_encoded_ref::
29  
clear() noexcept
29  
clear() noexcept
30  
{
30  
{
31  
    u_->remove_query();
31  
    u_->remove_query();
32  
}
32  
}
33  

33  

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

50  

51  
    assign(first, last,
51  
    assign(first, last,
52  
        typename std::iterator_traits<
52  
        typename std::iterator_traits<
53  
            FwdIt>::iterator_category{});
53  
            FwdIt>::iterator_category{});
54  
}
54  
}
55  

55  

56  
inline
56  
inline
57  
auto
57  
auto
58  
params_encoded_ref::
58  
params_encoded_ref::
59  
append(
59  
append(
60  
    param_pct_view const& p) ->
60  
    param_pct_view const& p) ->
61  
        iterator
61  
        iterator
62  
{
62  
{
63  
    return insert(end(), p);
63  
    return insert(end(), p);
64  
}
64  
}
65  

65  

66  
inline
66  
inline
67  
auto
67  
auto
68  
params_encoded_ref::
68  
params_encoded_ref::
69  
append(
69  
append(
70  
    std::initializer_list<
70  
    std::initializer_list<
71  
        param_pct_view> init) ->
71  
        param_pct_view> init) ->
72  
    iterator
72  
    iterator
73  
{
73  
{
74  
    return insert(end(), init);
74  
    return insert(end(), init);
75  
}
75  
}
76  

76  

77  
template<class FwdIt>
77  
template<class FwdIt>
78  
auto
78  
auto
79  
params_encoded_ref::
79  
params_encoded_ref::
80  
append(
80  
append(
81  
    FwdIt first, FwdIt last) ->
81  
    FwdIt first, FwdIt last) ->
82  
    iterator
82  
    iterator
83  
{
83  
{
84  
/*  If you get a compile error here, it
84  
/*  If you get a compile error here, it
85  
    means that the iterators you passed
85  
    means that the iterators you passed
86  
    do not meet the requirements stated
86  
    do not meet the requirements stated
87  
    in the documentation.
87  
    in the documentation.
88  
*/
88  
*/
89  
    static_assert(
89  
    static_assert(
90  
        std::is_convertible<
90  
        std::is_convertible<
91  
            typename std::iterator_traits<
91  
            typename std::iterator_traits<
92  
                FwdIt>::reference,
92  
                FwdIt>::reference,
93  
            param_view>::value,
93  
            param_view>::value,
94  
        "Type requirements not met");
94  
        "Type requirements not met");
95  

95  

96  
    return insert(
96  
    return insert(
97  
        end(), first, last);
97  
        end(), first, last);
98  
}
98  
}
99  

99  

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

120  

121  
    return insert(
121  
    return insert(
122  
        before,
122  
        before,
123  
        first,
123  
        first,
124  
        last,
124  
        last,
125  
        typename std::iterator_traits<
125  
        typename std::iterator_traits<
126  
            FwdIt>::iterator_category{});
126  
            FwdIt>::iterator_category{});
127  
}
127  
}
128  

128  

129  
template<class FwdIt>
129  
template<class FwdIt>
130  
auto
130  
auto
131  
params_encoded_ref::
131  
params_encoded_ref::
132  
replace(
132  
replace(
133  
    iterator from,
133  
    iterator from,
134  
    iterator to,
134  
    iterator to,
135  
    FwdIt first,
135  
    FwdIt first,
136  
    FwdIt last) ->
136  
    FwdIt last) ->
137  
        iterator
137  
        iterator
138  
{
138  
{
139  
/*  If you get a compile error here, it
139  
/*  If you get a compile error here, it
140  
    means that the iterators you passed
140  
    means that the iterators you passed
141  
    do not meet the requirements stated
141  
    do not meet the requirements stated
142  
    in the documentation.
142  
    in the documentation.
143  
*/
143  
*/
144  
    static_assert(
144  
    static_assert(
145  
        std::is_convertible<
145  
        std::is_convertible<
146  
            typename std::iterator_traits<
146  
            typename std::iterator_traits<
147  
                FwdIt>::reference,
147  
                FwdIt>::reference,
148  
            param_view>::value,
148  
            param_view>::value,
149  
        "Type requirements not met");
149  
        "Type requirements not met");
150  

150  

151  
    return u_->edit_params(
151  
    return u_->edit_params(
152  
        from.it_, to.it_,
152  
        from.it_, to.it_,
153  
        detail::make_params_encoded_iter(
153  
        detail::make_params_encoded_iter(
154  
            first, last));
154  
            first, last));
155  
}
155  
}
156  

156  

157  
//------------------------------------------------
157  
//------------------------------------------------
158  
//
158  
//
159  
// implementation
159  
// implementation
160  
//
160  
//
161  
//------------------------------------------------
161  
//------------------------------------------------
162  

162  

163  
template<class FwdIt>
163  
template<class FwdIt>
164  
void
164  
void
165  
params_encoded_ref::
165  
params_encoded_ref::
166  
assign(FwdIt first, FwdIt last,
166  
assign(FwdIt first, FwdIt last,
167  
    std::forward_iterator_tag)
167  
    std::forward_iterator_tag)
168  
{
168  
{
169  
    u_->edit_params(
169  
    u_->edit_params(
170  
        begin().it_,
170  
        begin().it_,
171  
        end().it_,
171  
        end().it_,
172  
        detail::make_params_encoded_iter(
172  
        detail::make_params_encoded_iter(
173  
            first, last));
173  
            first, last));
174  
}
174  
}
175  

175  

176  
template<class FwdIt>
176  
template<class FwdIt>
177  
auto
177  
auto
178  
params_encoded_ref::
178  
params_encoded_ref::
179  
insert(
179  
insert(
180  
    iterator before,
180  
    iterator before,
181  
    FwdIt first,
181  
    FwdIt first,
182  
    FwdIt last,
182  
    FwdIt last,
183  
    std::forward_iterator_tag) ->
183  
    std::forward_iterator_tag) ->
184  
        iterator
184  
        iterator
185  
{
185  
{
186  
    return u_->edit_params(
186  
    return u_->edit_params(
187  
        before.it_,
187  
        before.it_,
188  
        before.it_,
188  
        before.it_,
189  
        detail::make_params_encoded_iter(
189  
        detail::make_params_encoded_iter(
190  
            first, last));
190  
            first, last));
191  
}
191  
}
192  

192  

193  
} // urls
193  
} // urls
194  
} // boost
194  
} // boost
195  

195  

196  
#endif
196  
#endif