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  

27  

28  
inline
28  
inline
29  
void
29  
void
30  
segments_ref::
30  
segments_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_ref::
38  
segments_ref::
39  
assign(FwdIt first, FwdIt last)
39  
assign(FwdIt first, FwdIt last)
40  
{
40  
{
41  
/*  If you get a compile error here, it
41  
/*  If you get a compile error here, it
42  
    means that the iterators you passed
42  
    means that the iterators you passed
43  
    do not meet the requirements stated
43  
    do not meet the requirements stated
44  
    in the documentation.
44  
    in the documentation.
45  
*/
45  
*/
46  
    static_assert(
46  
    static_assert(
47  
        std::is_convertible<
47  
        std::is_convertible<
48  
            typename std::iterator_traits<
48  
            typename std::iterator_traits<
49  
                FwdIt>::reference,
49  
                FwdIt>::reference,
50  
            core::string_view>::value,
50  
            core::string_view>::value,
51  
        "Type requirements not met");
51  
        "Type requirements not met");
52  

52  

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

59  

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

80  

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

88  

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

98  

99  
template<class FwdIt>
99  
template<class FwdIt>
100  
auto
100  
auto
101  
segments_ref::
101  
segments_ref::
102  
replace(
102  
replace(
103  
    iterator from,
103  
    iterator from,
104  
    iterator to,
104  
    iterator to,
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  
            core::string_view>::value,
118  
            core::string_view>::value,
119  
        "Type requirements not met");
119  
        "Type requirements not met");
120  

120  

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

127  

128  
//------------------------------------------------
128  
//------------------------------------------------
129  

129  

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

138  

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

146  

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

148  

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

165  

166  
} // urls
166  
} // urls
167  
} // boost
167  
} // boost
168  

168  

169  
#endif
169  
#endif