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_REF_HPP
11  
#ifndef BOOST_URL_IMPL_SEGMENTS_REF_HPP
12  
#define BOOST_URL_IMPL_SEGMENTS_REF_HPP
12  
#define BOOST_URL_IMPL_SEGMENTS_REF_HPP
13  

13  

14  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/detail/config.hpp>
15  
#include <boost/url/detail/any_segments_iter.hpp>
15  
#include <boost/url/detail/any_segments_iter.hpp>
16  
#include <boost/url/detail/segments_iter_impl.hpp>
16  
#include <boost/url/detail/segments_iter_impl.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 -
inline
 
28 -
void
 
29 -
segments_ref::
 
30 -
clear() noexcept
 
31 -
{
 
32 -
    erase(begin(), end());
 
33 -
}
 
34 -

 
35  

27  

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

44  

53  
    u_->edit_segments(
45  
    u_->edit_segments(
54  
        begin().it_,
46  
        begin().it_,
55  
        end().it_,
47  
        end().it_,
56  
        detail::make_segments_iter(
48  
        detail::make_segments_iter(
57  
            first, last));
49  
            first, last));
58  
}
50  
}
59  

51  

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

72  

81  
    return insert(
73  
    return insert(
82  
        before,
74  
        before,
83  
        first,
75  
        first,
84  
        last,
76  
        last,
85  
        typename std::iterator_traits<
77  
        typename std::iterator_traits<
86  
            FwdIt>::iterator_category{});
78  
            FwdIt>::iterator_category{});
87  
}
79  
}
88 -
inline
 
89 -
auto
 
90 -
segments_ref::
 
91 -
erase(
 
92 -
    iterator pos) noexcept ->
 
93 -
        iterator
 
94 -
{
 
95 -
    return erase(pos, std::next(pos));
 
96 -
}
 
97 -

 
98  

80  

99  
template<class FwdIt>
81  
template<class FwdIt>
100  
auto
82  
auto
101  
segments_ref::
83  
segments_ref::
102  
replace(
84  
replace(
103  
    iterator from,
85  
    iterator from,
104  
    iterator to,
86  
    iterator to,
105  
    FwdIt first,
87  
    FwdIt first,
106  
    FwdIt last) ->
88  
    FwdIt last) ->
107  
        iterator
89  
        iterator
108  
{
90  
{
109  
/*  If you get a compile error here, it
91  
/*  If you get a compile error here, it
110  
    means that the iterators you passed
92  
    means that the iterators you passed
111  
    do not meet the requirements stated
93  
    do not meet the requirements stated
112  
    in the documentation.
94  
    in the documentation.
113  
*/
95  
*/
114  
    static_assert(
96  
    static_assert(
115  
        std::is_convertible<
97  
        std::is_convertible<
116  
            typename std::iterator_traits<
98  
            typename std::iterator_traits<
117  
                FwdIt>::reference,
99  
                FwdIt>::reference,
118  
            core::string_view>::value,
100  
            core::string_view>::value,
119  
        "Type requirements not met");
101  
        "Type requirements not met");
120  

102  

121  
    return u_->edit_segments(
103  
    return u_->edit_segments(
122  
        from.it_,
104  
        from.it_,
123  
        to.it_,
105  
        to.it_,
124  
        detail::make_segments_iter(
106  
        detail::make_segments_iter(
125 -
}
 
126 -

 
127 -
//------------------------------------------------
 
128 -

 
129 -
inline
 
130 -
void
 
131 -
segments_ref::
 
132 -
push_back(
 
133 -
    core::string_view s)
 
134 -
{
 
135 -
    insert(end(), s);
 
136 -
}
 
137 -

 
138 -
inline
 
139 -
void
 
140 -
segments_ref::
 
141 -
pop_back() noexcept
 
142 -
{
 
143 -
    erase(std::prev(end()));
 
144  
            first, last));
107  
            first, last));
145  
}
108  
}
146  

109  

147  
//------------------------------------------------
110  
//------------------------------------------------
148  

111  

149  
template<class FwdIt>
112  
template<class FwdIt>
150  
auto
113  
auto
151  
segments_ref::
114  
segments_ref::
152  
insert(
115  
insert(
153  
    iterator before,
116  
    iterator before,
154  
    FwdIt first,
117  
    FwdIt first,
155  
    FwdIt last,
118  
    FwdIt last,
156  
    std::forward_iterator_tag) ->
119  
    std::forward_iterator_tag) ->
157  
        iterator
120  
        iterator
158  
{
121  
{
159  
    return u_->edit_segments(
122  
    return u_->edit_segments(
160  
        before.it_,
123  
        before.it_,
161  
        before.it_,
124  
        before.it_,
162  
        detail::make_segments_iter(
125  
        detail::make_segments_iter(
163  
            first, last));
126  
            first, last));
164  
}
127  
}
165  

128  

166  
} // urls
129  
} // urls
167  
} // boost
130  
} // boost
168  

131  

169  
#endif
132  
#endif