Line data Source code
1 : //
2 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 : // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4 : //
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)
7 : //
8 : // Official repository: https://github.com/boostorg/url
9 : //
10 :
11 :
12 : #include <boost/url/detail/config.hpp>
13 : #include <boost/url/segments_encoded_base.hpp>
14 : #include <boost/assert.hpp>
15 : #include <ostream>
16 :
17 : namespace boost {
18 : namespace urls {
19 :
20 1368 : segments_encoded_base::
21 : segments_encoded_base(
22 1368 : detail::path_ref const& ref) noexcept
23 1368 : : ref_(ref)
24 : {
25 1368 : }
26 :
27 1783 : segments_encoded_base::
28 : iterator::
29 : iterator(
30 1783 : detail::path_ref const& ref) noexcept
31 1783 : : it_(ref)
32 : {
33 1783 : }
34 :
35 1471 : segments_encoded_base::
36 : iterator::
37 : iterator(
38 : detail::path_ref const& ref,
39 1471 : int) noexcept
40 1471 : : it_(ref, 0)
41 : {
42 1471 : }
43 :
44 : //------------------------------------------------
45 : //
46 : // segments_encoded_base
47 : //
48 : //------------------------------------------------
49 :
50 :
51 :
52 : //------------------------------------------------
53 : //
54 : // Observers
55 : //
56 : //------------------------------------------------
57 :
58 : pct_string_view
59 58 : segments_encoded_base::
60 : buffer() const noexcept
61 : {
62 58 : return ref_.buffer();
63 : }
64 :
65 : bool
66 392 : segments_encoded_base::
67 : is_absolute() const noexcept
68 : {
69 392 : return ref_.buffer().starts_with('/');
70 : }
71 :
72 : bool
73 599 : segments_encoded_base::
74 : empty() const noexcept
75 : {
76 599 : return ref_.nseg() == 0;
77 : }
78 :
79 : std::size_t
80 432 : segments_encoded_base::
81 : size() const noexcept
82 : {
83 432 : return ref_.nseg();
84 : }
85 :
86 : pct_string_view
87 98 : segments_encoded_base::
88 : front() const noexcept
89 : {
90 98 : BOOST_ASSERT(! empty());
91 98 : return *begin();
92 : }
93 :
94 : pct_string_view
95 16 : segments_encoded_base::
96 : back() const noexcept
97 : {
98 16 : BOOST_ASSERT(! empty());
99 16 : return *--end();
100 : }
101 :
102 : auto
103 1783 : segments_encoded_base::
104 : begin() const noexcept ->
105 : iterator
106 : {
107 1783 : return iterator(ref_);
108 : }
109 :
110 : auto
111 1471 : segments_encoded_base::
112 : end() const noexcept ->
113 : iterator
114 : {
115 1471 : return iterator(ref_, 0);
116 : }
117 :
118 : //------------------------------------------------
119 :
120 : std::ostream&
121 15 : operator<<(
122 : std::ostream& os,
123 : segments_encoded_base const& ps)
124 : {
125 15 : os << ps.buffer();
126 15 : return os;
127 : }
128 :
129 : } // urls
130 : } // boost
131 :
|