LCOV - code coverage report
Current view: top level - libs/url/src/rfc/detail - h16_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 32 33 97.0 %
Date: 2024-02-29 20:02:55 Functions: 1 1 100.0 %

          Line data    Source code
       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         932 :     if(it == end)
      35             :     {
      36             :         // end
      37           0 :         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         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         907 :         if(it == end)
      54          75 :             break;
      55         832 :         d = grammar::hexdig_value(*it);
      56         832 :         if(d < 0)
      57         556 :             break;
      58         276 :         v = (16 * v) + d;
      59         276 :         ++it;
      60         276 :         if(it == end)
      61           4 :             break;
      62         272 :         d = grammar::hexdig_value(*it);
      63         272 :         if(d < 0)
      64           4 :             break;
      65         268 :         v = (16 * v) + d;
      66         268 :         ++it;
      67         268 :         if(it == end)
      68           4 :             break;
      69         264 :         d = grammar::hexdig_value(*it);
      70         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

Generated by: LCOV version 1.15