LCOV - code coverage report
Current view: top level - libs/url/src/rfc - query_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 30 30 100.0 %
Date: 2024-03-05 20:06:56 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             : 
      11             : #include <boost/url/detail/config.hpp>
      12             : #include <boost/url/rfc/query_rule.hpp>
      13             : #include "detail/charsets.hpp"
      14             : #include <boost/url/error.hpp>
      15             : #include <boost/url/grammar/hexdig_chars.hpp>
      16             : 
      17             : namespace boost {
      18             : namespace urls {
      19             : 
      20             : auto
      21         561 : query_rule_t::
      22             : parse(
      23             :     char const*& it,
      24             :     char const* end
      25             :         ) const noexcept ->
      26             :     system::result<value_type>
      27             : {
      28         561 :     if(it == end)
      29             :     {
      30             :         // empty string = 0 params
      31          32 :         return params_encoded_view(
      32          64 :             detail::query_ref(
      33          32 :                 core::string_view(it, 0), 0, 0));
      34             :     }
      35         529 :     auto const it0 = it;
      36         529 :     std::size_t dn = 0;
      37         529 :     std::size_t nparam = 1;
      38        6920 :     while(it != end)
      39             :     {
      40        6567 :         if(*it == '&')
      41             :         {
      42         454 :             ++nparam;
      43         454 :             ++it;
      44         454 :             continue;
      45             :         }
      46        6113 :         if(detail::query_chars(*it))
      47             :         {
      48        5843 :             ++it;
      49        5843 :             continue;
      50             :         }
      51         270 :         if(*it == '%')
      52             :         {
      53         106 :             if(end - it < 3)
      54             :             {
      55             :                 // missing HEXDIG
      56           9 :                 BOOST_URL_RETURN_EC(
      57             :                     error::missing_pct_hexdig);
      58             :             }
      59         193 :             if (!grammar::hexdig_chars(it[1]) ||
      60          96 :                 !grammar::hexdig_chars(it[2]))
      61             :             {
      62             :                 // expected HEXDIG
      63           3 :                 BOOST_URL_RETURN_EC(
      64             :                     error::bad_pct_hexdig);
      65             :             }
      66          94 :             it += 3;
      67          94 :             dn += 2;
      68          94 :             continue;
      69             :         }
      70             :         // got reserved character
      71         164 :         break;
      72             :     }
      73         517 :     std::size_t const n(it - it0);
      74         517 :     return params_encoded_view(
      75        1034 :         detail::query_ref(
      76             :             core::string_view(it0, n),
      77             :             n - dn,
      78         517 :             nparam));
      79             : }
      80             : 
      81             : } // urls
      82             : } // boost
      83             : 

Generated by: LCOV version 1.15