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_DETAIL_SEGMENTS_ITER_IMPL_HPP
11  
#ifndef BOOST_URL_DETAIL_SEGMENTS_ITER_IMPL_HPP
12  
#define BOOST_URL_DETAIL_SEGMENTS_ITER_IMPL_HPP
12  
#define BOOST_URL_DETAIL_SEGMENTS_ITER_IMPL_HPP
13  

13  

14  
#include <boost/url/detail/parts_base.hpp>
14  
#include <boost/url/detail/parts_base.hpp>
15  
#include <boost/url/detail/url_impl.hpp>
15  
#include <boost/url/detail/url_impl.hpp>
16  
#include <boost/core/detail/string_view.hpp>
16  
#include <boost/core/detail/string_view.hpp>
17  
#include <string>
17  
#include <string>
18  

18  

19  
namespace boost {
19  
namespace boost {
20  
namespace urls {
20  
namespace urls {
21  
namespace detail {
21  
namespace detail {
22  

22  

23  
struct segments_iter_impl
23  
struct segments_iter_impl
24  
    : private parts_base
24  
    : private parts_base
25  
{
25  
{
26  
    path_ref ref; // parent path data the iterator aliases
26  
    path_ref ref; // parent path data the iterator aliases
27  
    std::size_t pos = 0; // encoded offset of current segment start
27  
    std::size_t pos = 0; // encoded offset of current segment start
28  
    std::size_t next = 0; // encoded offset one past current segment
28  
    std::size_t next = 0; // encoded offset one past current segment
29  
    std::size_t index = 0; // segment index within the parent path
29  
    std::size_t index = 0; // segment index within the parent path
30  
    std::size_t dn = 0; // decoded length of current segment
30  
    std::size_t dn = 0; // decoded length of current segment
31  
    std::size_t decoded_prefix = 0; // decoded chars preceding current segment
31  
    std::size_t decoded_prefix = 0; // decoded chars preceding current segment
32  
private:
32  
private:
33  
    pct_string_view s_;
33  
    pct_string_view s_;
34  
public:
34  
public:
35  

35  

36  
    segments_iter_impl() = default;
36  
    segments_iter_impl() = default;
37  
    segments_iter_impl(
37  
    segments_iter_impl(
38  
        segments_iter_impl const&) noexcept = default;
38  
        segments_iter_impl const&) noexcept = default;
39  
    segments_iter_impl& operator=(
39  
    segments_iter_impl& operator=(
40  
        segments_iter_impl const&) noexcept = default;
40  
        segments_iter_impl const&) noexcept = default;
41  

41  

42  
    // begin
42  
    // begin
43  
    segments_iter_impl(
43  
    segments_iter_impl(
44  
        detail::path_ref const&) noexcept;
44  
        detail::path_ref const&) noexcept;
45  

45  

46  
    // end
46  
    // end
47  
    segments_iter_impl(
47  
    segments_iter_impl(
48  
        detail::path_ref const&,
48  
        detail::path_ref const&,
49  
        int) noexcept;
49  
        int) noexcept;
50  

50  

51  
    // at index
51  
    // at index
52  
    segments_iter_impl(
52  
    segments_iter_impl(
53  
        url_impl const& u_,
53  
        url_impl const& u_,
54  
        std::size_t pos_,
54  
        std::size_t pos_,
55  
        std::size_t i_) noexcept;
55  
        std::size_t i_) noexcept;
56  

56  

57  
    void update() noexcept;
57  
    void update() noexcept;
58  

58  

59  
    BOOST_URL_DECL
59  
    BOOST_URL_DECL
60  
    void
60  
    void
61  
    increment() noexcept;
61  
    increment() noexcept;
62  

62  

63  
    BOOST_URL_DECL
63  
    BOOST_URL_DECL
64  
    void
64  
    void
65  
    decrement() noexcept;
65  
    decrement() noexcept;
66  

66  

67  
    pct_string_view
67  
    pct_string_view
68  
    dereference() const noexcept
68  
    dereference() const noexcept
69  
    {
69  
    {
70  
        return s_;
70  
        return s_;
71  
    }
71  
    }
72  

72  

73  
    std::size_t
73  
    std::size_t
74  
    decoded_prefix_size() const noexcept
74  
    decoded_prefix_size() const noexcept
75  
    {
75  
    {
76  
        return decoded_prefix;
76  
        return decoded_prefix;
77  
    }
77  
    }
78  

78  

79  
    bool
79  
    bool
80  
    equal(
80  
    equal(
81  
        segments_iter_impl const& other) const noexcept
81  
        segments_iter_impl const& other) const noexcept
82  
    {
82  
    {
83  
        BOOST_ASSERT(ref.alias_of(other.ref));
83  
        BOOST_ASSERT(ref.alias_of(other.ref));
84  
        return index == other.index;
84  
        return index == other.index;
85  
    }
85  
    }
86  
};
86  
};
87  

87  

88  
} // detail
88  
} // detail
89  
} // urls
89  
} // urls
90  
} // boost
90  
} // boost
91  

91  

92  
#endif
92  
#endif