LCOV - code coverage report
Current view: top level - url/rfc/detail/impl - h16_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 31 31
Test Date: 2026-02-25 21:00:01 Functions: 100.0 % 1 1

           TLA  Line data    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                 : BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
      23                 : auto
      24 HIT         948 : h16_rule_t::
      25                 : parse(
      26                 :     char const*& it,
      27                 :     char const* end
      28                 :         ) const noexcept ->
      29                 :     system::result<value_type>
      30                 : {
      31                 :     // LCOV_EXCL_START
      32                 :     // h16 is only called from ipv6_address_rule
      33                 :     // which ensures at least one char is available
      34                 :     if(it == end)
      35                 :     {
      36                 :         BOOST_URL_CONSTEXPR_RETURN_EC(
      37                 :             grammar::error::invalid);
      38                 :     }
      39                 :     // LCOV_EXCL_STOP
      40                 : 
      41                 :     std::uint16_t v;
      42                 :     for(;;)
      43                 :     {
      44             948 :         auto d = grammar::hexdig_value(*it);
      45             948 :         if(d < 0)
      46                 :         {
      47                 :             // expected HEXDIG
      48              21 :             BOOST_URL_CONSTEXPR_RETURN_EC(
      49                 :                 grammar::error::invalid);
      50                 :         }
      51             927 :         v = d;
      52             927 :         ++it;
      53             927 :         if(it == end)
      54              77 :             break;
      55             850 :         d = grammar::hexdig_value(*it);
      56             850 :         if(d < 0)
      57             564 :             break;
      58             286 :         v = (16 * v) + d;
      59             286 :         ++it;
      60             286 :         if(it == end)
      61               4 :             break;
      62             282 :         d = grammar::hexdig_value(*it);
      63             282 :         if(d < 0)
      64               4 :             break;
      65             278 :         v = (16 * v) + d;
      66             278 :         ++it;
      67             278 :         if(it == end)
      68               4 :             break;
      69             274 :         d = grammar::hexdig_value(*it);
      70             274 :         if(d < 0)
      71              51 :             break;
      72             223 :         v = (16 * v) + d;
      73             223 :         ++it;
      74             223 :         break;
      75                 :     }
      76             927 :     return value_type{
      77                 :         static_cast<
      78             927 :             unsigned char>(v / 256),
      79                 :         static_cast<
      80             927 :             unsigned char>(v % 256)};
      81                 : }
      82                 : 
      83                 : } // detail
      84                 : } // urls
      85                 : } // boost
      86                 : 
      87                 : 
      88                 : #endif
        

Generated by: LCOV version 2.3