GCC Code Coverage Report


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