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

13  

14  
#include <boost/url/detail/segments_iter_impl.hpp>
14  
#include <boost/url/detail/segments_iter_impl.hpp>
 
15 +
#include <boost/url/encoding_opts.hpp>
15  
#include <boost/assert.hpp>
16  
#include <boost/assert.hpp>
16  
#include <iterator>
17  
#include <iterator>
17  

18  

18  
namespace boost {
19  
namespace boost {
19  
namespace urls {
20  
namespace urls {
20  
namespace detail {
21  
namespace detail {
21  
struct segments_iter_access;
22  
struct segments_iter_access;
22  
}
23  
}
23  

24  

24  
class segments_base::iterator
25  
class segments_base::iterator
25  
{
26  
{
26  
    detail::segments_iter_impl it_;
27  
    detail::segments_iter_impl it_;
27  

28  

28  
    friend class segments_base;
29  
    friend class segments_base;
29  
    friend class segments_ref;
30  
    friend class segments_ref;
30  
    friend struct detail::segments_iter_access;
31  
    friend struct detail::segments_iter_access;
31  

32  

32  
    iterator(detail::path_ref const&) noexcept;
33  
    iterator(detail::path_ref const&) noexcept;
33  
    iterator(detail::path_ref const&, int) noexcept;
34  
    iterator(detail::path_ref const&, int) noexcept;
34  

35  

35  
    iterator(
36  
    iterator(
36  
        detail::segments_iter_impl const& it) noexcept
37  
        detail::segments_iter_impl const& it) noexcept
37  
        : it_(it)
38  
        : it_(it)
38  
    {
39  
    {
39  
    }
40  
    }
40  

41  

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

50  

50  
    iterator() = default;
51  
    iterator() = default;
51  
    iterator(iterator const&) = default;
52  
    iterator(iterator const&) = default;
52  
    iterator& operator=(
53  
    iterator& operator=(
53  
        iterator const&) noexcept = default;
54  
        iterator const&) noexcept = default;
54 -
    BOOST_URL_DECL
 
55  

55  

56  
    reference
56  
    reference
57 -
    operator*() const;
57 +
    operator*() const
 
58 +
    {
 
59 +
        encoding_opts opt;
 
60 +
        opt.space_as_plus = false;
 
61 +
        return it_.dereference().decode(opt);
 
62 +
    }
58  

63  

59  
    // the return value is too expensive
64  
    // the return value is too expensive
60  
    pointer operator->() const = delete;
65  
    pointer operator->() const = delete;
61  

66  

62  
    iterator&
67  
    iterator&
63  
    operator++() noexcept
68  
    operator++() noexcept
64  
    {
69  
    {
65  
        it_.increment();
70  
        it_.increment();
66  
        return *this;
71  
        return *this;
67  
    }
72  
    }
68  

73  

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

80  

76  
    iterator
81  
    iterator
77  
    operator++(int) noexcept
82  
    operator++(int) noexcept
78  
    {
83  
    {
79  
        auto tmp = *this;
84  
        auto tmp = *this;
80  
        ++*this;
85  
        ++*this;
81  
        return tmp;
86  
        return tmp;
82  
    }
87  
    }
83  

88  

84  
    iterator
89  
    iterator
85  
    operator--(int) noexcept
90  
    operator--(int) noexcept
86  
    {
91  
    {
87  
        auto tmp = *this;
92  
        auto tmp = *this;
88  
        --*this;
93  
        --*this;
89  
        return tmp;
94  
        return tmp;
90  
    }
95  
    }
91  

96  

92  
    bool
97  
    bool
93  
    operator==(
98  
    operator==(
94  
        iterator const& other) const noexcept
99  
        iterator const& other) const noexcept
95  
    {
100  
    {
96  
        return it_.equal(other.it_);
101  
        return it_.equal(other.it_);
97  
    }
102  
    }
98  

103  

99  
    bool
104  
    bool
100  
    operator!=(
105  
    operator!=(
101  
        iterator const& other) const noexcept
106  
        iterator const& other) const noexcept
102  
    {
107  
    {
103  
        return ! it_.equal(other.it_);
108  
        return ! it_.equal(other.it_);
104  
    }
109  
    }
105 -

 
106 -
//------------------------------------------------
 
107 -

 
108 -
inline
 
109 -
std::string
 
110 -
segments_base::
 
111 -
front() const noexcept
 
112 -
{
 
113 -
    BOOST_ASSERT(! empty());
 
114 -
    return *begin();
 
115 -
}
 
116 -

 
117 -
inline
 
118 -
std::string
 
119 -
segments_base::
 
120 -
back() const noexcept
 
121 -
{
 
122 -
    BOOST_ASSERT(! empty());
 
123 -
    return *--end();
 
124 -
}
 
125  
};
110  
};
126  

111  

127  
} // urls
112  
} // urls
128  
} // boost
113  
} // boost
129  

114  

130  
#endif
115  
#endif