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: 97.0 % 33 32
Test Date: 2026-02-13 15:53:22 Functions: 100.0 % 1 1

            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              : 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          948 :     if(it == end)
      32              :     {
      33            0 :         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          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          927 :         if(it == end)
      49           77 :             break;
      50          850 :         d = grammar::hexdig_value(*it);
      51          850 :         if(d < 0)
      52          564 :             break;
      53          286 :         v = (16 * v) + d;
      54          286 :         ++it;
      55          286 :         if(it == end)
      56            4 :             break;
      57          282 :         d = grammar::hexdig_value(*it);
      58          282 :         if(d < 0)
      59            4 :             break;
      60          278 :         v = (16 * v) + d;
      61          278 :         ++it;
      62          278 :         if(it == end)
      63            4 :             break;
      64          274 :         d = grammar::hexdig_value(*it);
      65          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
        

Generated by: LCOV version 2.3