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

Generated by: LCOV version 1.15