include/boost/url/impl/decode_view.hpp

100.0% Lines (63 / 63) 100.0% Functions (17 / 17)
decode_view.hpp
f(x) Functions (17)
Function Calls Lines Blocks
boost::urls::decode_view::iterator::iterator(char const*, bool) :27 17759x 100.0% 100.0% boost::urls::decode_view::iterator::iterator(char const*, unsigned long, bool) :38 7534x 100.0% 100.0% boost::urls::decode_view::iterator::iterator() :58 2x 100.0% 100.0% boost::urls::decode_view::iterator::operator++() :70 1178739x 100.0% 86.0% boost::urls::decode_view::iterator::operator--() :81 3601x 100.0% 88.0% boost::urls::decode_view::iterator::operator++(int) :93 11275x 100.0% 100.0% boost::urls::decode_view::iterator::base() :109 22x 100.0% 100.0% boost::urls::decode_view::iterator::operator==(boost::urls::decode_view::iterator const&) const :115 1171656x 100.0% 100.0% boost::urls::decode_view::iterator::operator!=(boost::urls::decode_view::iterator const&) const :122 1171106x 100.0% 100.0% boost::urls::decode_view::begin() const :133 17759x 100.0% 100.0% boost::urls::decode_view::end() const :142 7534x 100.0% 100.0% boost::urls::decode_view::front() const :151 3552x 100.0% 86.0% boost::urls::decode_view::back() const :161 3533x 100.0% 88.0% int boost::urls::detail::decoded_strcmp<boost::core::basic_string_view<char> >(boost::urls::decode_view, boost::core::basic_string_view<char>) :174 9547x 100.0% 100.0% int boost::urls::detail::decoded_strcmp<boost::urls::decode_view>(boost::urls::decode_view, boost::urls::decode_view) :174 332x 100.0% 96.0% boost::urls::decode_view::compare(boost::core::basic_string_view<char>) const :203 9547x 100.0% 100.0% boost::urls::decode_view::compare(boost::urls::decode_view) const :215 332x 100.0% 100.0%
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/url
8 //
9
10 #ifndef BOOST_URL_IMPL_PCT_ENCODED_VIEW_HPP
11 #define BOOST_URL_IMPL_PCT_ENCODED_VIEW_HPP
12
13 #include <boost/url/grammar/type_traits.hpp>
14 #include <boost/core/detail/static_assert.hpp>
15
16 namespace boost {
17 namespace urls {
18
19 class decode_view::iterator
20 {
21 char const* begin_ = nullptr;
22 char const* pos_ = nullptr;
23 bool space_as_plus_ = true;
24
25 friend decode_view;
26
27 17759x iterator(
28 char const* str,
29 bool space_as_plus) noexcept
30 17759x : begin_(str)
31 17759x , pos_(str)
32 17759x , space_as_plus_(
33 space_as_plus)
34 {
35 17759x }
36
37 // end ctor
38 7534x iterator(
39 char const* str,
40 size_type n,
41 bool space_as_plus) noexcept
42 7534x : begin_(str)
43 7534x , pos_(str + n)
44 7534x , space_as_plus_(space_as_plus)
45 {
46 7534x }
47
48 public:
49 using value_type = char;
50 using reference = char;
51 using pointer = void const*;
52 using const_reference = char;
53 using size_type = std::size_t;
54 using difference_type = std::ptrdiff_t;
55 using iterator_category =
56 std::bidirectional_iterator_tag;
57
58 2x iterator() = default;
59
60 iterator(iterator const&) = default;
61
62 iterator&
63 operator=(iterator const&) = default;
64
65 BOOST_URL_DECL
66 reference
67 operator*() const noexcept;
68
69 iterator&
70 1178739x operator++() noexcept
71 {
72 1178739x BOOST_ASSERT(pos_ != nullptr);
73 1178739x if (*pos_ != '%')
74 956307x ++pos_;
75 else
76 222432x pos_ += 3;
77 1178739x return *this;
78 }
79
80 iterator&
81 3601x operator--() noexcept
82 {
83 3601x BOOST_ASSERT(pos_ != begin_);
84 3601x if (pos_ - begin_ < 3 ||
85 3593x pos_[-3] != '%')
86 2958x --pos_;
87 else
88 643x pos_ -= 3;
89 3601x return *this;
90 }
91
92 iterator
93 11275x operator++(int) noexcept
94 {
95 11275x auto tmp = *this;
96 11275x ++*this;
97 11275x return tmp;
98 }
99
100 iterator
101 operator--(int) noexcept
102 {
103 auto tmp = *this;
104 --*this;
105 return tmp;
106 }
107
108 char const*
109 22x base()
110 {
111 22x return pos_;
112 }
113
114 bool
115 1171656x operator==(
116 iterator const& other) const noexcept
117 {
118 1171656x return pos_ == other.pos_;
119 }
120
121 bool
122 1171106x operator!=(
123 iterator const& other) const noexcept
124 {
125 1171106x return !(*this == other);
126 }
127 };
128
129 //------------------------------------------------
130
131 inline
132 auto
133 17759x decode_view::
134 begin() const noexcept ->
135 const_iterator
136 {
137 17759x return {p_, space_as_plus_};
138 }
139
140 inline
141 auto
142 7534x decode_view::
143 end() const noexcept ->
144 const_iterator
145 {
146 7534x return {p_, n_, space_as_plus_};
147 }
148
149 inline
150 auto
151 3552x decode_view::
152 front() const noexcept ->
153 const_reference
154 {
155 3552x BOOST_ASSERT( !empty() );
156 3552x return *begin();
157 }
158
159 inline
160 auto
161 3533x decode_view::
162 back() const noexcept ->
163 const_reference
164 {
165 3533x BOOST_ASSERT( !empty() );
166 3533x return *--end();
167 }
168
169 namespace detail {
170
171 template <class T>
172 BOOST_CXX14_CONSTEXPR
173 int
174 9879x decoded_strcmp(decode_view s0, T s1)
175 {
176 9879x auto const n0 = s0.size();
177 9879x auto const n1 = s1.size();
178 9879x auto n = (std::min)(n0, n1);
179 9879x auto it0 = s0.begin();
180 9879x auto it1 = s1.begin();
181 13671x while (n != 0)
182 {
183 10612x --n;
184 10612x const char c0 = *it0++;
185 10612x const char c1 = *it1++;
186 10612x if (c0 == c1)
187 3792x continue;
188 6820x return 1 - 2 * (static_cast<unsigned char>(c0)
189 13640x < static_cast<unsigned char>(c1));
190 }
191 3059x return 1 - (n0 == n1) - 2 * (n0 < n1);
192 }
193
194 } // detail
195
196
197 #if defined(BOOST_NO_CXX14_CONSTEXPR)
198 inline
199 #else
200 BOOST_CXX14_CONSTEXPR
201 #endif
202 int
203 9547x decode_view::
204 compare(core::string_view other) const noexcept
205 {
206 9547x return detail::decoded_strcmp(*this, other);
207 }
208
209 #if defined(BOOST_NO_CXX14_CONSTEXPR)
210 inline
211 #else
212 BOOST_CXX14_CONSTEXPR
213 #endif
214 int
215 332x decode_view::
216 compare(decode_view other) const noexcept
217 {
218 332x return detail::decoded_strcmp(*this, other);
219 }
220
221 } // urls
222 } // boost
223
224 #endif
225