LCOV - code coverage report
Current view: top level - libs/url/src/rfc/detail - hier_part_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 53 54 98.1 %
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 "hier_part_rule.hpp"
      13             : #include "boost/url/rfc/detail/path_rules.hpp"
      14             : #include <boost/url/grammar/parse.hpp>
      15             : #include <boost/url/grammar/parse.hpp>
      16             : 
      17             : namespace boost {
      18             : namespace urls {
      19             : namespace detail {
      20             : 
      21             : auto
      22        2249 : hier_part_rule_t::
      23             : parse(
      24             :     char const*& it,
      25             :     char const* const end
      26             :         ) const noexcept ->
      27             :     system::result<value_type>
      28             : {
      29        4498 :     value_type t;
      30        2249 :     if(it == end)
      31             :     {
      32             :         // path-empty
      33          44 :         return t;
      34             :     }
      35        2205 :     if(end - it == 1)
      36             :     {
      37          36 :         if(*it == '/')
      38             :         {
      39             :             // path-absolute
      40             :             t.path = make_pct_string_view_unsafe(
      41          26 :                 it, 1, 1);
      42          26 :             t.segment_count = 1;
      43          26 :             ++it;
      44          26 :             return t;
      45             :         }
      46             :         // path-rootless
      47             :         auto rv = grammar::parse(
      48          10 :             it, end, segment_rule);
      49          10 :         if(! rv)
      50           0 :             return rv.error();
      51          10 :         t.path = *rv;
      52          10 :         t.segment_count = !t.path.empty();
      53          10 :         return t;
      54             :     }
      55        2169 :     if( it[0] == '/' &&
      56        1568 :         it[1] == '/')
      57             :     {
      58             :         // "//" authority
      59        1472 :         it += 2;
      60             :         auto rv = grammar::parse(
      61        1472 :             it, end, authority_rule);
      62        1472 :         if(! rv)
      63          30 :             return rv.error();
      64        1442 :         t.authority = *rv;
      65        1442 :         t.has_authority = true;
      66             :     }
      67             :     // the authority requires an absolute path
      68             :     // or an empty path
      69        2139 :     if(it == end || (
      70        1733 :         t.has_authority && (
      71        1036 :             *it != '/' &&
      72         146 :             *it != '?' &&
      73         103 :             *it != '#')))
      74             :     {
      75             :         // path-empty
      76         495 :         return t;
      77             :     }
      78        1644 :     auto const it0 = it;
      79        1644 :     std::size_t dn = 0;
      80        1644 :     if(*it != '/')
      81             :     {
      82             :         auto rv = grammar::parse(
      83         658 :             it, end, segment_rule);
      84         658 :         if(! rv)
      85           2 :             return rv.error();
      86         656 :         if(rv->empty())
      87          75 :             return t;
      88         581 :         dn += rv->decoded_size();
      89         581 :         ++t.segment_count;
      90             :     }
      91        4353 :     while(it != end)
      92             :     {
      93        2978 :         if(*it == '/')
      94             :         {
      95        1665 :             ++dn;
      96        1665 :             ++it;
      97        1665 :             ++t.segment_count;
      98        1665 :             continue;
      99             :         }
     100             :         auto rv = grammar::parse(
     101        1313 :             it, end, segment_rule);
     102        1313 :         if(! rv)
     103           4 :             return rv.error();
     104        1309 :         if(rv->empty())
     105         188 :             break;
     106        1121 :         dn += rv->decoded_size();
     107             :     }
     108             :     t.path = make_pct_string_view_unsafe(
     109        1563 :         it0, it - it0, dn);
     110        1563 :     return t;
     111             : }
     112             : 
     113             : } // detail
     114             : } // urls
     115             : } // boost
     116             : 

Generated by: LCOV version 1.15