include/boost/url/rfc/detail/impl/h16_rule.hpp

97.0% Lines (32/33) 100.0% Functions (1/1) 93.8% Branches (15/16)
include/boost/url/rfc/detail/impl/h16_rule.hpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 // Copyright (c) 2024 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_RFC_DETAIL_IMPL_H16_RULE_HPP
12 #define BOOST_URL_RFC_DETAIL_IMPL_H16_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/grammar/error.hpp>
16 #include <boost/url/grammar/hexdig_chars.hpp>
17
18 namespace boost {
19 namespace urls {
20 namespace detail {
21
22 inline BOOST_URL_CXX20_CONSTEXPR
23 auto
24 948 h16_rule_t::
25 parse(
26 char const*& it,
27 char const* end
28 ) const noexcept ->
29 system::result<value_type>
30 {
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 948 times.
948 if(it == end)
32 {
33 BOOST_URL_CONSTEXPR_RETURN_EC(
34 grammar::error::invalid);
35 }
36
37 std::uint16_t v;
38 for(;;)
39 {
40 948 auto d = grammar::hexdig_value(*it);
41
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 927 times.
948 if(d < 0)
42 {
43 21 BOOST_URL_CONSTEXPR_RETURN_EC(
44 grammar::error::invalid);
45 }
46 927 v = d;
47 927 ++it;
48
2/2
✓ Branch 0 taken 77 times.
✓ Branch 1 taken 850 times.
927 if(it == end)
49 77 break;
50 850 d = grammar::hexdig_value(*it);
51
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 286 times.
850 if(d < 0)
52 564 break;
53 286 v = (16 * v) + d;
54 286 ++it;
55
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 282 times.
286 if(it == end)
56 4 break;
57 282 d = grammar::hexdig_value(*it);
58
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 278 times.
282 if(d < 0)
59 4 break;
60 278 v = (16 * v) + d;
61 278 ++it;
62
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 274 times.
278 if(it == end)
63 4 break;
64 274 d = grammar::hexdig_value(*it);
65
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 223 times.
274 if(d < 0)
66 51 break;
67 223 v = (16 * v) + d;
68 223 ++it;
69 223 break;
70 }
71 927 return value_type{
72 static_cast<
73 927 unsigned char>(v / 256),
74 static_cast<
75 927 unsigned char>(v % 256)};
76 }
77
78 } // detail
79 } // urls
80 } // boost
81
82
83 #endif
84