LCOV - code coverage report
Current view: top level - url/rfc/impl - pct_encoded_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 36 36
Test Date: 2026-02-13 15:53:22 Functions: 100.0 % 6 6

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
       3              : // Copyright (c) 2022 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_IMPL_PCT_ENCODED_RULE_HPP
      12              : #define BOOST_URL_RFC_IMPL_PCT_ENCODED_RULE_HPP
      13              : 
      14              : #include <boost/url/grammar/charset.hpp>
      15              : #include <boost/url/grammar/error.hpp>
      16              : #include <boost/url/grammar/hexdig_chars.hpp>
      17              : 
      18              : namespace boost {
      19              : namespace urls {
      20              : 
      21              : namespace detail {
      22              : 
      23              : template<class CharSet>
      24              : BOOST_URL_CXX14_CONSTEXPR
      25              : auto
      26         9964 : parse_encoded(
      27              :     char const*& it,
      28              :     char const* end,
      29              :     CharSet const& cs) noexcept ->
      30              :         system::result<pct_string_view>
      31              : {
      32         9964 :     auto const start = it;
      33         9964 :     std::size_t n = 0;
      34          356 :     for(;;)
      35              :     {
      36        10320 :         auto it0 = it;
      37        10320 :         it = grammar::find_if_not(
      38              :             it0, end, cs);
      39        10320 :         n += it - it0;
      40        10320 :         if(it == end || *it != '%')
      41              :             break;
      42          455 :         bool at_end = false;
      43          212 :         for(;;)
      44              :         {
      45          667 :             ++it;
      46          667 :             if(it == end)
      47              :             {
      48              :                 // expected HEXDIG
      49           14 :                 BOOST_URL_CONSTEXPR_RETURN_EC(
      50              :                     grammar::error::invalid);
      51              :             }
      52          653 :             auto r = grammar::hexdig_value(*it);
      53          653 :             if(r < 0)
      54              :             {
      55              :                 // expected HEXDIG
      56           12 :                 BOOST_URL_CONSTEXPR_RETURN_EC(
      57              :                     grammar::error::invalid);
      58              :             }
      59          641 :             ++it;
      60          641 :             if(it == end)
      61              :             {
      62              :                 // expected HEXDIG
      63            5 :                 BOOST_URL_CONSTEXPR_RETURN_EC(
      64              :                     grammar::error::invalid);
      65              :             }
      66          636 :             r = grammar::hexdig_value(*it);
      67          636 :             if(r < 0)
      68              :             {
      69              :                 // expected HEXDIG
      70            8 :                 BOOST_URL_CONSTEXPR_RETURN_EC(
      71              :                     grammar::error::invalid);
      72              :             }
      73          628 :             ++n;
      74          628 :             ++it;
      75          628 :             if(it == end)
      76              :             {
      77           60 :                 at_end = true;
      78           60 :                 break;
      79              :             }
      80          568 :             if(*it != '%')
      81          356 :                 break;
      82              :         }
      83          416 :         if(at_end)
      84           60 :             break;
      85              :     }
      86         9925 :     return make_pct_string_view_unsafe(
      87         9925 :         start, it - start, n);
      88              : }
      89              : 
      90              : } // detail
      91              : 
      92              : //------------------------------------------------
      93              : 
      94              : template<class CharSet>
      95              : BOOST_URL_CXX14_CONSTEXPR
      96              : auto
      97         9964 : implementation_defined::pct_encoded_rule_t<CharSet>::
      98              : parse(
      99              :     char const*& it,
     100              :     char const* end) const noexcept ->
     101              :         system::result<value_type>
     102              : {
     103         9964 :     return detail::parse_encoded(
     104         9964 :         it, end, cs_);
     105              : }
     106              : 
     107              : } // urls
     108              : } // boost
     109              : 
     110              : #endif
        

Generated by: LCOV version 2.3