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

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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_IMPL_PARSE_PATH_IPP
      12             : #define BOOST_URL_IMPL_PARSE_PATH_IPP
      13             : 
      14             : #include <boost/url/detail/config.hpp>
      15             : #include <boost/url/parse_path.hpp>
      16             : #include <boost/url/error.hpp>
      17             : #include "detail/path.hpp"
      18             : #include <boost/url/grammar/parse.hpp>
      19             : #include "boost/url/rfc/detail/path_rules.hpp"
      20             : 
      21             : namespace boost {
      22             : namespace urls {
      23             : 
      24             : system::result<segments_encoded_view>
      25         153 : parse_path(core::string_view s) noexcept
      26             : {
      27         153 :     auto it = s.data();
      28         153 :     auto const end = it + s.size();
      29         153 :     std::size_t dn = 0;
      30         153 :     std::size_t nseg = 0;
      31         153 :     if( it != end &&
      32         150 :             *it != '/')
      33         120 :         ++nseg;
      34         892 :     while(it != end)
      35             :     {
      36         751 :         if(*it == '/')
      37             :         {
      38         330 :             ++it;
      39         330 :             ++dn;
      40         330 :             ++nseg;
      41         330 :             continue;
      42             :         }
      43             :         auto rv = grammar::parse(
      44         421 :             it, end, detail::segment_rule);
      45         421 :         if(! rv)
      46          10 :             return rv.error();
      47         411 :         if(rv->empty())
      48             :         {
      49           2 :             BOOST_URL_RETURN_EC(
      50             :                 grammar::error::mismatch);
      51             :         }
      52         409 :         dn += rv->decoded_size();
      53             :     }
      54             :     // adjust nseg
      55         141 :     nseg = detail::path_segments(s, nseg);
      56         141 :     return segments_encoded_view(
      57         282 :         detail::path_ref(s, dn, nseg));
      58             : }
      59             : 
      60             : } // urls
      61             : } // boost
      62             : 
      63             : #endif

Generated by: LCOV version 1.15