GCC Code Coverage Report


Directory: libs/url/
File: src/decode_view.cpp
Date: 2025-11-10 19:06:22
Exec Total Coverage
Lines: 92 92 100.0%
Functions: 10 10 100.0%
Branches: 41 46 89.1%

Line Branch Exec Source
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
11 #include <boost/url/detail/config.hpp>
12 #include <boost/url/decode_view.hpp>
13 #include <boost/url/grammar/hexdig_chars.hpp>
14 #include <ostream>
15
16 namespace boost {
17 namespace urls {
18
19 //------------------------------------------------
20
21 auto
22 6341 decode_view::
23 iterator::
24 operator*() const noexcept ->
25 reference
26 {
27
2/2
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 6288 times.
6341 if (space_as_plus_ &&
28
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 47 times.
53 *pos_ == '+')
29 6 return ' ';
30
2/2
✓ Branch 0 taken 5959 times.
✓ Branch 1 taken 376 times.
6335 if (*pos_ != '%')
31 5959 return *pos_;
32 376 auto d0 = grammar::hexdig_value(pos_[1]);
33 376 auto d1 = grammar::hexdig_value(pos_[2]);
34 return static_cast<char>(
35 376 ((static_cast<
36 376 unsigned char>(d0) << 4) +
37 376 (static_cast<
38 376 unsigned char>(d1))));
39 }
40
41 void
42 2 decode_view::
43 write(std::ostream& os) const
44 {
45 2 auto it = begin();
46 2 auto const end_ = end();
47
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 2 times.
23 while(it != end_)
48
1/2
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
21 os.put(*it++);
49 2 }
50
51 void
52 1 decode_view::
53 remove_prefix( size_type n )
54 {
55 1 auto it = begin();
56 1 auto n0 = n;
57
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 while (n)
58 {
59 2 ++it;
60 2 --n;
61 }
62 1 n_ -= (it.base() - begin().base());
63 1 dn_ -= n0;
64 1 p_ = it.base();
65 1 }
66
67 void
68 1 decode_view::
69 remove_suffix( size_type n )
70 {
71 1 auto it = end();
72 1 auto n0 = n;
73
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 while (n)
74 {
75 5 --it;
76 5 --n;
77 }
78 1 n_ -= (end().base() - it.base());
79 1 dn_ -= n0;
80 1 }
81
82 bool
83 3 decode_view::
84 starts_with( core::string_view s ) const noexcept
85 {
86
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (s.size() > size())
87 1 return false;
88 2 auto it0 = begin();
89 2 auto it1 = s.begin();
90 2 std::size_t n = s.size();
91
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 while (n)
92 {
93
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
10 if (*it0 != *it1)
94 1 return false;
95 9 ++it0;
96 9 ++it1;
97 9 --n;
98 }
99 1 return true;
100 }
101
102 bool
103 3 decode_view::
104 ends_with( core::string_view s ) const noexcept
105 {
106
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (s.size() > size())
107 1 return false;
108 2 auto it0 = end();
109 2 auto it1 = s.end();
110 2 std::size_t n = s.size();
111 2 --it0;
112 2 --it1;
113
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1 times.
14 while (n - 1)
114 {
115
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
13 if (*it0 != *it1)
116 1 return false;
117 12 --it0;
118 12 --it1;
119 12 --n;
120 }
121 1 return *it0 == *it1;
122 }
123
124 bool
125 1 decode_view::
126 starts_with( char ch ) const noexcept
127 {
128 return
129
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 !empty() &&
130 2 front() == ch;
131 }
132
133 bool
134 1 decode_view::
135 ends_with( char ch ) const noexcept
136 {
137 return
138
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 !empty() &&
139 2 back() == ch;
140 }
141
142 decode_view::const_iterator
143 2 decode_view::
144 find( char ch ) const noexcept
145 {
146 2 auto it = begin();
147 2 auto end = this->end();
148
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 times.
8 while (it != end)
149 {
150
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 6 times.
7 if (*it == ch)
151 1 return it;
152 6 ++it;
153 }
154 1 return it;
155 }
156
157 decode_view::const_iterator
158 5 decode_view::
159 rfind( char ch ) const noexcept
160 {
161
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
5 if (empty())
162 1 return end();
163 4 auto it = end();
164 4 auto begin = this->begin();
165 4 --it;
166
2/2
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 2 times.
27 while (it != begin)
167 {
168
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 23 times.
25 if (*it == ch)
169 2 return it;
170 23 --it;
171 }
172
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 if (*it == ch)
173 1 return it;
174 1 return end();
175 }
176
177 } // urls
178 } // boost
179
180