include/boost/url/impl/segments_base.hpp

100.0% Lines (58/58) 100.0% List of functions (20/20)
segments_base.hpp
f(x) Functions (20)
Function Calls Lines Blocks
boost::urls::segments_base::iterator::iterator(boost::urls::detail::segments_iter_impl const&) :37 1826x 100.0% 100.0% boost::urls::segments_base::iterator::operator*[abi:cxx11]() const :58 8096x 100.0% 67.0% boost::urls::segments_base::iterator::operator++() :69 8693x 100.0% 100.0% boost::urls::segments_base::iterator::operator--() :76 250x 100.0% 100.0% boost::urls::segments_base::iterator::operator++(int) :83 48x 100.0% 100.0% boost::urls::segments_base::iterator::operator--(int) :91 21x 100.0% 100.0% boost::urls::segments_base::iterator::operator==(boost::urls::segments_base::iterator const&) const :99 66x 100.0% 100.0% boost::urls::segments_base::iterator::operator!=(boost::urls::segments_base::iterator const&) const :106 13872x 100.0% 100.0% boost::urls::segments_base::iterator::iterator(boost::urls::detail::path_ref const&) :116 7187x 100.0% 100.0% boost::urls::segments_base::iterator::iterator(boost::urls::detail::path_ref const&, int) :125 14603x 100.0% 100.0% boost::urls::segments_base::segments_base(boost::urls::detail::path_ref const&) :141 7009x 100.0% 100.0% boost::urls::segments_base::buffer() const :150 79x 100.0% 100.0% boost::urls::segments_base::is_absolute() const :158 41x 100.0% 100.0% boost::urls::segments_base::empty() const :166 1893x 100.0% 100.0% boost::urls::segments_base::size() const :174 708x 100.0% 100.0% boost::urls::segments_base::front[abi:cxx11]() const :182 29x 100.0% 89.0% boost::urls::segments_base::back[abi:cxx11]() const :191 22x 100.0% 90.0% boost::urls::segments_base::begin() const :200 7187x 100.0% 100.0% boost::urls::segments_base::end() const :209 14603x 100.0% 100.0% boost::urls::operator<<(std::ostream&, boost::urls::segments_base const&) :220 15x 100.0% 100.0%
Line TLA Hits 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 #ifndef BOOST_URL_IMPL_SEGMENTS_BASE_HPP
12 #define BOOST_URL_IMPL_SEGMENTS_BASE_HPP
13
14 #include <boost/url/detail/segments_iter_impl.hpp>
15 #include <boost/url/encoding_opts.hpp>
16 #include <boost/assert.hpp>
17 #include <iterator>
18 #include <ostream>
19
20 namespace boost {
21 namespace urls {
22 namespace detail {
23 struct segments_iter_access;
24 }
25
26 class segments_base::iterator
27 {
28 detail::segments_iter_impl it_;
29
30 friend class segments_base;
31 friend class segments_ref;
32 friend struct detail::segments_iter_access;
33
34 iterator(detail::path_ref const&) noexcept;
35 iterator(detail::path_ref const&, int) noexcept;
36
37 1826x iterator(
38 detail::segments_iter_impl const& it) noexcept
39 1826x : it_(it)
40 {
41 1826x }
42
43 public:
44 using value_type = segments_base::value_type;
45 using reference = segments_base::reference;
46 using pointer = reference;
47 using difference_type =
48 segments_base::difference_type;
49 using iterator_category =
50 std::bidirectional_iterator_tag;
51
52 iterator() = default;
53 iterator(iterator const&) = default;
54 iterator& operator=(
55 iterator const&) noexcept = default;
56
57 reference
58 8096x operator*() const
59 {
60 8096x encoding_opts opt;
61 8096x opt.space_as_plus = false;
62 8096x return it_.dereference().decode(opt);
63 }
64
65 // the return value is too expensive
66 pointer operator->() const = delete;
67
68 iterator&
69 8693x operator++() noexcept
70 {
71 8693x it_.increment();
72 8693x return *this;
73 }
74
75 iterator&
76 250x operator--() noexcept
77 {
78 250x it_.decrement();
79 250x return *this;
80 }
81
82 iterator
83 48x operator++(int) noexcept
84 {
85 48x auto tmp = *this;
86 48x ++*this;
87 48x return tmp;
88 }
89
90 iterator
91 21x operator--(int) noexcept
92 {
93 21x auto tmp = *this;
94 21x --*this;
95 21x return tmp;
96 }
97
98 bool
99 66x operator==(
100 iterator const& other) const noexcept
101 {
102 66x return it_.equal(other.it_);
103 }
104
105 bool
106 13872x operator!=(
107 iterator const& other) const noexcept
108 {
109 13872x return ! it_.equal(other.it_);
110 }
111 };
112
113 //------------------------------------------------
114
115 inline
116 7187x segments_base::
117 iterator::
118 iterator(
119 7187x detail::path_ref const& ref) noexcept
120 7187x : it_(ref)
121 {
122 7187x }
123
124 inline
125 14603x segments_base::
126 iterator::
127 iterator(
128 detail::path_ref const& ref,
129 14603x int) noexcept
130 14603x : it_(ref, 0)
131 {
132 14603x }
133
134 //------------------------------------------------
135 //
136 // segments_base
137 //
138 //------------------------------------------------
139
140 inline
141 7009x segments_base::
142 segments_base(
143 7009x detail::path_ref const& ref) noexcept
144 7009x : ref_(ref)
145 {
146 7009x }
147
148 inline
149 pct_string_view
150 79x segments_base::
151 buffer() const noexcept
152 {
153 79x return ref_.buffer();
154 }
155
156 inline
157 bool
158 41x segments_base::
159 is_absolute() const noexcept
160 {
161 41x return ref_.buffer().starts_with('/');
162 }
163
164 inline
165 bool
166 1893x segments_base::
167 empty() const noexcept
168 {
169 1893x return ref_.nseg() == 0;
170 }
171
172 inline
173 std::size_t
174 708x segments_base::
175 size() const noexcept
176 {
177 708x return ref_.nseg();
178 }
179
180 inline
181 std::string
182 29x segments_base::
183 front() const
184 {
185 29x BOOST_ASSERT(! empty());
186 29x return *begin();
187 }
188
189 inline
190 std::string
191 22x segments_base::
192 back() const
193 {
194 22x BOOST_ASSERT(! empty());
195 22x return *--end();
196 }
197
198 inline
199 auto
200 7187x segments_base::
201 begin() const noexcept ->
202 iterator
203 {
204 7187x return iterator(ref_);
205 }
206
207 inline
208 auto
209 14603x segments_base::
210 end() const noexcept ->
211 iterator
212 {
213 14603x return iterator(ref_, 0);
214 }
215
216 //------------------------------------------------
217
218 inline
219 std::ostream&
220 15x operator<<(
221 std::ostream& os,
222 segments_base const& ps)
223 {
224 15x os << ps.buffer();
225 15x return os;
226 }
227
228 } // urls
229 } // boost
230
231 #endif
232