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  

11  

12  
#include <boost/url/detail/config.hpp>
12  
#include <boost/url/detail/config.hpp>
13  
#include <boost/url/segments_encoded_base.hpp>
13  
#include <boost/url/segments_encoded_base.hpp>
14  
#include <boost/assert.hpp>
14  
#include <boost/assert.hpp>
15  
#include <ostream>
15  
#include <ostream>
16  

16  

17  
namespace boost {
17  
namespace boost {
18  
namespace urls {
18  
namespace urls {
19  

19  

20  
segments_encoded_base::
20  
segments_encoded_base::
21  
iterator::
21  
iterator::
22  
iterator(
22  
iterator(
23  
    detail::path_ref const& ref) noexcept
23  
    detail::path_ref const& ref) noexcept
24  
    : it_(ref)
24  
    : it_(ref)
25  
{
25  
{
26  
}
26  
}
27  

27  

28  
segments_encoded_base::
28  
segments_encoded_base::
29  
iterator::
29  
iterator::
30  
iterator(
30  
iterator(
31  
    detail::path_ref const& ref,
31  
    detail::path_ref const& ref,
32  
    int) noexcept
32  
    int) noexcept
33  
    : it_(ref, 0)
33  
    : it_(ref, 0)
34  
{
34  
{
35  
}
35  
}
36  

36  

37  
//------------------------------------------------
37  
//------------------------------------------------
38  
//
38  
//
39  
// segments_encoded_base
39  
// segments_encoded_base
40  
//
40  
//
41  
//------------------------------------------------
41  
//------------------------------------------------
42  

42  

43  
segments_encoded_base::
43  
segments_encoded_base::
44  
segments_encoded_base(
44  
segments_encoded_base(
45  
    detail::path_ref const& ref) noexcept
45  
    detail::path_ref const& ref) noexcept
46  
    : ref_(ref)
46  
    : ref_(ref)
47  
{
47  
{
48  
}
48  
}
49  

49  

50  
//------------------------------------------------
50  
//------------------------------------------------
51  
//
51  
//
52  
// Observers
52  
// Observers
53  
//
53  
//
54  
//------------------------------------------------
54  
//------------------------------------------------
55  

55  

56  
pct_string_view
56  
pct_string_view
57  
segments_encoded_base::
57  
segments_encoded_base::
58  
buffer() const noexcept
58  
buffer() const noexcept
59  
{
59  
{
60  
    return ref_.buffer();
60  
    return ref_.buffer();
61  
}
61  
}
62  

62  

63  
bool
63  
bool
64  
segments_encoded_base::
64  
segments_encoded_base::
65  
is_absolute() const noexcept
65  
is_absolute() const noexcept
66  
{
66  
{
67  
    return ref_.buffer().starts_with('/');
67  
    return ref_.buffer().starts_with('/');
68  
}
68  
}
69  

69  

70  
bool
70  
bool
71  
segments_encoded_base::
71  
segments_encoded_base::
72  
empty() const noexcept
72  
empty() const noexcept
73  
{
73  
{
74  
    return ref_.nseg() == 0;
74  
    return ref_.nseg() == 0;
75  
}
75  
}
76  

76  

77  
std::size_t
77  
std::size_t
78  
segments_encoded_base::
78  
segments_encoded_base::
79  
size() const noexcept
79  
size() const noexcept
80  
{
80  
{
81  
    return ref_.nseg();
81  
    return ref_.nseg();
82  
}
82  
}
83  

83  

84  
auto
84  
auto
85  
segments_encoded_base::
85  
segments_encoded_base::
86  
begin() const noexcept ->
86  
begin() const noexcept ->
87  
    iterator
87  
    iterator
88  
{
88  
{
89  
    return iterator(ref_);
89  
    return iterator(ref_);
90  
}
90  
}
91  

91  

92  
auto
92  
auto
93  
segments_encoded_base::
93  
segments_encoded_base::
94  
end() const noexcept ->
94  
end() const noexcept ->
95  
    iterator
95  
    iterator
96  
{
96  
{
97  
    return iterator(ref_, 0);
97  
    return iterator(ref_, 0);
98  
}
98  
}
99  

99  

100  
//------------------------------------------------
100  
//------------------------------------------------
101  

101  

102  
std::ostream&
102  
std::ostream&
103  
operator<<(
103  
operator<<(
104  
    std::ostream& os,
104  
    std::ostream& os,
105  
    segments_encoded_base const& ps)
105  
    segments_encoded_base const& ps)
106  
{
106  
{
107  
    os << ps.buffer();
107  
    os << ps.buffer();
108  
    return os;
108  
    return os;
109  
}
109  
}
110  

110  

111  
} // urls
111  
} // urls
112  
} // boost
112  
} // boost
113  

113