GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/rfc/detail/h16_rule.cpp
Date: 2024-03-08 17:32:04
Exec Total Coverage
Lines: 32 33 97.0%
Functions: 1 1 100.0%
Branches: 15 16 93.8%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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 #include <boost/url/detail/config.hpp>
11 #include "h16_rule.hpp"
12 #include <boost/url/grammar/charset.hpp>
13 #include <boost/url/grammar/error.hpp>
14 #include <boost/url/grammar/hexdig_chars.hpp>
15 #include <boost/assert.hpp>
16
17 namespace boost {
18 namespace urls {
19 namespace detail {
20
21 auto
22 932 h16_rule_t::
23 parse(
24 char const*& it,
25 char const* end
26 ) const noexcept ->
27 system::result<value_type>
28 {
29 // VFALCO it might be impossible for
30 // this condition to be true (coverage)
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 932 times.
932 if(it == end)
32 {
33 // end
34 BOOST_URL_RETURN_EC(
35 grammar::error::invalid);
36 }
37
38 std::uint16_t v;
39 for(;;)
40 {
41 932 auto d = grammar::hexdig_value(*it);
42
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 907 times.
932 if(d < 0)
43 {
44 // expected HEXDIG
45 25 BOOST_URL_RETURN_EC(
46 grammar::error::invalid);
47 }
48 907 v = d;
49 907 ++it;
50
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 832 times.
907 if(it == end)
51 75 break;
52 832 d = grammar::hexdig_value(*it);
53
2/2
✓ Branch 0 taken 556 times.
✓ Branch 1 taken 276 times.
832 if(d < 0)
54 556 break;
55 276 v = (16 * v) + d;
56 276 ++it;
57
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 272 times.
276 if(it == end)
58 4 break;
59 272 d = grammar::hexdig_value(*it);
60
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 268 times.
272 if(d < 0)
61 4 break;
62 268 v = (16 * v) + d;
63 268 ++it;
64
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 264 times.
268 if(it == end)
65 4 break;
66 264 d = grammar::hexdig_value(*it);
67
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 213 times.
264 if(d < 0)
68 51 break;
69 213 v = (16 * v) + d;
70 213 ++it;
71 213 break;
72 }
73 907 return value_type{
74 static_cast<
75 907 unsigned char>(v / 256),
76 static_cast<
77 907 unsigned char>(v % 256)};
78 }
79
80 } // detail
81 } // urls
82 } // boost
83
84