100.00% Lines (31/31) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3   // Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com) 3   // Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com)
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 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) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/boostorg/url 8   // Official repository: https://github.com/boostorg/url
9   // 9   //
10   10  
11   #ifndef BOOST_URL_RFC_DETAIL_IMPL_H16_RULE_HPP 11   #ifndef BOOST_URL_RFC_DETAIL_IMPL_H16_RULE_HPP
12   #define BOOST_URL_RFC_DETAIL_IMPL_H16_RULE_HPP 12   #define BOOST_URL_RFC_DETAIL_IMPL_H16_RULE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/grammar/error.hpp> 15   #include <boost/url/grammar/error.hpp>
16   #include <boost/url/grammar/hexdig_chars.hpp> 16   #include <boost/url/grammar/hexdig_chars.hpp>
17   17  
18   namespace boost { 18   namespace boost {
19   namespace urls { 19   namespace urls {
20   namespace detail { 20   namespace detail {
21   21  
22   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE 22   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
23   auto 23   auto
HITCBC 24   1318 h16_rule_t:: 24   1318 h16_rule_t::
25   parse( 25   parse(
26   char const*& it, 26   char const*& it,
27   char const* end 27   char const* end
28   ) const noexcept -> 28   ) const noexcept ->
29   system::result<value_type> 29   system::result<value_type>
30   { 30   {
31   // LCOV_EXCL_START 31   // LCOV_EXCL_START
32   // h16 is only called from ipv6_address_rule 32   // h16 is only called from ipv6_address_rule
33   // which ensures at least one char is available 33   // which ensures at least one char is available
34   if(it == end) 34   if(it == end)
35   { 35   {
36   BOOST_URL_CONSTEXPR_RETURN_EC( 36   BOOST_URL_CONSTEXPR_RETURN_EC(
37   grammar::error::invalid); 37   grammar::error::invalid);
38   } 38   }
39   // LCOV_EXCL_STOP 39   // LCOV_EXCL_STOP
40   40  
41   std::uint16_t v; 41   std::uint16_t v;
42   for(;;) 42   for(;;)
43   { 43   {
HITCBC 44   1318 auto d = grammar::hexdig_value(*it); 44   1318 auto d = grammar::hexdig_value(*it);
HITCBC 45   1318 if(d < 0) 45   1318 if(d < 0)
46   { 46   {
47   // expected HEXDIG 47   // expected HEXDIG
HITCBC 48   21 BOOST_URL_CONSTEXPR_RETURN_EC( 48   21 BOOST_URL_CONSTEXPR_RETURN_EC(
49   grammar::error::invalid); 49   grammar::error::invalid);
50   } 50   }
HITCBC 51   1297 v = d; 51   1297 v = d;
HITCBC 52   1297 ++it; 52   1297 ++it;
HITCBC 53   1297 if(it == end) 53   1297 if(it == end)
HITCBC 54   78 break; 54   78 break;
HITCBC 55   1219 d = grammar::hexdig_value(*it); 55   1219 d = grammar::hexdig_value(*it);
HITCBC 56   1219 if(d < 0) 56   1219 if(d < 0)
HITCBC 57   571 break; 57   571 break;
HITCBC 58   648 v = (16 * v) + d; 58   648 v = (16 * v) + d;
HITCBC 59   648 ++it; 59   648 ++it;
HITCBC 60   648 if(it == end) 60   648 if(it == end)
HITCBC 61   4 break; 61   4 break;
HITCBC 62   644 d = grammar::hexdig_value(*it); 62   644 d = grammar::hexdig_value(*it);
HITCBC 63   644 if(d < 0) 63   644 if(d < 0)
HITCBC 64   5 break; 64   5 break;
HITCBC 65   639 v = (16 * v) + d; 65   639 v = (16 * v) + d;
HITCBC 66   639 ++it; 66   639 ++it;
HITCBC 67   639 if(it == end) 67   639 if(it == end)
HITCBC 68   7 break; 68   7 break;
HITCBC 69   632 d = grammar::hexdig_value(*it); 69   632 d = grammar::hexdig_value(*it);
HITCBC 70   632 if(d < 0) 70   632 if(d < 0)
HITCBC 71   76 break; 71   76 break;
HITCBC 72   556 v = (16 * v) + d; 72   556 v = (16 * v) + d;
HITCBC 73   556 ++it; 73   556 ++it;
HITCBC 74   556 break; 74   556 break;
75   } 75   }
HITCBC 76   1297 return value_type{ 76   1297 return value_type{
77   static_cast< 77   static_cast<
HITCBC 78   1297 unsigned char>(v / 256), 78   1297 unsigned char>(v / 256),
79   static_cast< 79   static_cast<
HITCBC 80   1297 unsigned char>(v % 256)}; 80   1297 unsigned char>(v % 256)};
81   } 81   }
82   82  
83   } // detail 83   } // detail
84   } // urls 84   } // urls
85   } // boost 85   } // boost
86   86  
87   87  
88   #endif 88   #endif