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_BASE_HPP
11  
#ifndef BOOST_URL_IMPL_PARAMS_ENCODED_BASE_HPP
12  
#define BOOST_URL_IMPL_PARAMS_ENCODED_BASE_HPP
12  
#define BOOST_URL_IMPL_PARAMS_ENCODED_BASE_HPP
13  

13  

14  
#include <boost/url/detail/params_iter_impl.hpp>
14  
#include <boost/url/detail/params_iter_impl.hpp>
15  

15  

16  
namespace boost {
16  
namespace boost {
17  
namespace urls {
17  
namespace urls {
18  

18  

19  
#ifndef BOOST_URL_DOCS
19  
#ifndef BOOST_URL_DOCS
20  
class params_ref;
20  
class params_ref;
21  
#endif
21  
#endif
22  

22  

23  
//------------------------------------------------
23  
//------------------------------------------------
24  

24  

25  
class params_encoded_base::iterator
25  
class params_encoded_base::iterator
26  
{
26  
{
27  
    detail::params_iter_impl it_;
27  
    detail::params_iter_impl it_;
28  

28  

29  
    friend class params_encoded_base;
29  
    friend class params_encoded_base;
30  
    friend class params_encoded_ref;
30  
    friend class params_encoded_ref;
31  

31  

32  
    iterator(detail::query_ref const& ref) noexcept;
32  
    iterator(detail::query_ref const& ref) noexcept;
33  
    iterator(detail::query_ref const& ref, int) noexcept;
33  
    iterator(detail::query_ref const& ref, int) noexcept;
34  
    iterator(
34  
    iterator(
35  
        detail::params_iter_impl const& it)
35  
        detail::params_iter_impl const& it)
36  
        : it_(it)
36  
        : it_(it)
37  
    {
37  
    {
38  
    }
38  
    }
39  

39  

40  
public:
40  
public:
41  
    using value_type =
41  
    using value_type =
42  
        params_encoded_base::value_type;
42  
        params_encoded_base::value_type;
43  
    using reference =
43  
    using reference =
44  
        params_encoded_base::reference;
44  
        params_encoded_base::reference;
45  
    using pointer = reference;
45  
    using pointer = reference;
46  
    using difference_type = std::ptrdiff_t;
46  
    using difference_type = std::ptrdiff_t;
47  
    using iterator_category =
47  
    using iterator_category =
48  
        std::bidirectional_iterator_tag;
48  
        std::bidirectional_iterator_tag;
49  

49  

50  
    iterator() = default;
50  
    iterator() = default;
51  
    iterator(iterator const&) = default;
51  
    iterator(iterator const&) = default;
52  
    iterator& operator=(
52  
    iterator& operator=(
53  
        iterator const&) = default;
53  
        iterator const&) = default;
54  

54  

55  
    iterator&
55  
    iterator&
56  
    operator++() noexcept
56  
    operator++() noexcept
57  
    {
57  
    {
58  
        it_.increment();
58  
        it_.increment();
59  
        return *this;
59  
        return *this;
60  
    }
60  
    }
61  

61  

62  
    iterator
62  
    iterator
63  
    operator++(int) noexcept
63  
    operator++(int) noexcept
64  
    {
64  
    {
65  
        auto tmp = *this;
65  
        auto tmp = *this;
66  
        ++*this;
66  
        ++*this;
67  
        return tmp;
67  
        return tmp;
68  
    }
68  
    }
69  

69  

70  
    iterator&
70  
    iterator&
71  
    operator--() noexcept
71  
    operator--() noexcept
72  
    {
72  
    {
73  
        it_.decrement();
73  
        it_.decrement();
74  
        return *this;
74  
        return *this;
75  
    }
75  
    }
76  

76  

77  
    iterator
77  
    iterator
78  
    operator--(int) noexcept
78  
    operator--(int) noexcept
79  
    {
79  
    {
80  
        auto tmp = *this;
80  
        auto tmp = *this;
81  
        --*this;
81  
        --*this;
82  
        return tmp;
82  
        return tmp;
83  
    }
83  
    }
84  

84  

85  
    reference
85  
    reference
86  
    operator*() const
86  
    operator*() const
87  
    {
87  
    {
88  
        return it_.dereference();
88  
        return it_.dereference();
89  
    }
89  
    }
90  

90  

91  
    pointer
91  
    pointer
92  
    operator->() const
92  
    operator->() const
93  
    {
93  
    {
94  
        return it_.dereference();
94  
        return it_.dereference();
95  
    }
95  
    }
96  

96  

97  
    friend
97  
    friend
98  
    bool
98  
    bool
99  
    operator==(
99  
    operator==(
100  
        iterator const& it0,
100  
        iterator const& it0,
101  
        iterator const& it1) noexcept
101  
        iterator const& it1) noexcept
102  
    {
102  
    {
103  
        return it0.it_.equal(it1.it_);
103  
        return it0.it_.equal(it1.it_);
104  
    }
104  
    }
105  

105  

106  
    friend
106  
    friend
107  
    bool
107  
    bool
108  
    operator!=(
108  
    operator!=(
109  
        iterator const& it0,
109  
        iterator const& it0,
110  
        iterator const& it1) noexcept
110  
        iterator const& it1) noexcept
111  
    {
111  
    {
112  
        return ! it0.it_.equal(it1.it_);
112  
        return ! it0.it_.equal(it1.it_);
113  
    }
113  
    }
114  
};
114  
};
115  

115  

116  
//------------------------------------------------
116  
//------------------------------------------------
117  
//
117  
//
118  
// Observers
118  
// Observers
119  
//
119  
//
120  
//------------------------------------------------
120  
//------------------------------------------------
121  

121  

122  
inline
122  
inline
123  
bool
123  
bool
124  
params_encoded_base::
124  
params_encoded_base::
125  
contains(
125  
contains(
126  
    pct_string_view key,
126  
    pct_string_view key,
127  
    ignore_case_param ic) const noexcept
127  
    ignore_case_param ic) const noexcept
128  
{
128  
{
129  
    return find_impl(
129  
    return find_impl(
130  
        begin().it_, key, ic) != end();
130  
        begin().it_, key, ic) != end();
131  
}
131  
}
132  

132  

133  
inline
133  
inline
134  
pct_string_view
134  
pct_string_view
135  
params_encoded_base::
135  
params_encoded_base::
136  
get_or(
136  
get_or(
137  
    pct_string_view key,
137  
    pct_string_view key,
138  
    pct_string_view value,
138  
    pct_string_view value,
139  
    ignore_case_param ic) const noexcept
139  
    ignore_case_param ic) const noexcept
140  
{
140  
{
141  
    auto it = find_impl(
141  
    auto it = find_impl(
142  
        begin().it_, key, ic);
142  
        begin().it_, key, ic);
143  
    detail::params_iter_impl end_(ref_, 0);
143  
    detail::params_iter_impl end_(ref_, 0);
144  
    if(it.equal(end_))
144  
    if(it.equal(end_))
145  
        return value;
145  
        return value;
146  

146  

147  
    param_pct_view const p = it.dereference();
147  
    param_pct_view const p = it.dereference();
148  
    if(! p.has_value)
148  
    if(! p.has_value)
149  
        return pct_string_view();
149  
        return pct_string_view();
150  

150  

151  
    return p.value;
151  
    return p.value;
152  
}
152  
}
153  

153  

154  
inline
154  
inline
155  
auto
155  
auto
156  
params_encoded_base::
156  
params_encoded_base::
157  
find(
157  
find(
158  
    pct_string_view key,
158  
    pct_string_view key,
159  
    ignore_case_param ic) const noexcept ->
159  
    ignore_case_param ic) const noexcept ->
160  
        iterator
160  
        iterator
161  
{
161  
{
162  
    return find_impl(
162  
    return find_impl(
163  
        begin().it_, key, ic);
163  
        begin().it_, key, ic);
164  
}
164  
}
165  

165  

166  
inline
166  
inline
167  
auto
167  
auto
168  
params_encoded_base::
168  
params_encoded_base::
169  
find(
169  
find(
170  
    iterator it,
170  
    iterator it,
171  
    pct_string_view key,
171  
    pct_string_view key,
172  
    ignore_case_param ic) const noexcept ->
172  
    ignore_case_param ic) const noexcept ->
173  
        iterator
173  
        iterator
174  
{
174  
{
175  
    return find_impl(
175  
    return find_impl(
176  
        it.it_, key, ic);
176  
        it.it_, key, ic);
177  
}
177  
}
178  

178  

179  
inline
179  
inline
180  
auto
180  
auto
181  
params_encoded_base::
181  
params_encoded_base::
182  
find_last(
182  
find_last(
183  
    pct_string_view key,
183  
    pct_string_view key,
184  
    ignore_case_param ic) const noexcept ->
184  
    ignore_case_param ic) const noexcept ->
185  
        iterator
185  
        iterator
186  
{
186  
{
187  
    return find_last_impl(
187  
    return find_last_impl(
188  
        end().it_, key, ic);
188  
        end().it_, key, ic);
189  
}
189  
}
190  

190  

191  
inline
191  
inline
192  
auto
192  
auto
193  
params_encoded_base::
193  
params_encoded_base::
194  
find_last(
194  
find_last(
195  
    iterator it,
195  
    iterator it,
196  
    pct_string_view key,
196  
    pct_string_view key,
197  
    ignore_case_param ic) const noexcept ->
197  
    ignore_case_param ic) const noexcept ->
198  
        iterator
198  
        iterator
199  
{
199  
{
200  
    return find_last_impl(
200  
    return find_last_impl(
201  
        it.it_, key, ic);
201  
        it.it_, key, ic);
202  
}
202  
}
203  

203  

204  
} // urls
204  
} // urls
205  
} // boost
205  
} // boost
206  

206  

207  
#endif
207  
#endif