LCOV - code coverage report
Current view: top level - url/detail - path.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 60 60
Test Date: 2026-10-16 04:17:11 Functions: 100.0 % 3 3

           TLA  Line data    Source code
       1                 : //
       2                 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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_DETAIL_PATH_HPP
      11                 : #define BOOST_URL_DETAIL_PATH_HPP
      12                 : 
      13                 : #include <boost/url/detail/config.hpp>
      14                 : #include <boost/core/detail/string_view.hpp>
      15                 : 
      16                 : namespace boost {
      17                 : namespace urls {
      18                 : namespace detail {
      19                 : 
      20                 : // Return the number of characters at
      21                 : // the front of the path that are reserved
      22                 : inline
      23                 : std::size_t
      24 HIT       17085 : path_prefix(
      25                 :     char const* p,
      26                 :     std::size_t n) noexcept
      27                 : {
      28           17085 :     switch(n)
      29                 :     {
      30            3041 :     case 0:
      31            3041 :         return 0;
      32                 : 
      33            1642 :     case 1:
      34            1642 :         if(p[0] == '/')
      35            1289 :             return 1;
      36             353 :         return 0;
      37                 : 
      38             922 :     case 2:
      39             922 :         if(p[0] == '/')
      40             547 :             return 1;
      41             375 :         if( p[0] == '.' &&
      42             212 :             p[1] == '/')
      43              77 :             return 2;
      44             298 :         return 0;
      45                 : 
      46           11480 :     default:
      47           11480 :         if(p[0] == '/')
      48                 :         {
      49            7928 :             if( p[1] == '.' &&
      50             984 :                 p[2] == '/')
      51             525 :                 return 3;
      52            7403 :             return 1;
      53                 :         }
      54            3552 :         if( p[0] == '.' &&
      55            1280 :             p[1] == '/')
      56             728 :             return 2;
      57            2824 :         break;
      58                 :     }
      59            2824 :     return 0;
      60                 : }
      61                 : 
      62                 : // VFALCO DEPRECATED
      63                 : inline
      64                 : std::size_t
      65           17085 : path_prefix(
      66                 :     core::string_view s) noexcept
      67                 : {
      68           17085 :     return path_prefix(
      69           17085 :         s.data(), s.size());
      70                 : }
      71                 : 
      72                 : // returns the number of adjusted
      73                 : // segments based on the malleable prefix.
      74                 : BOOST_URL_CXX14_CONSTEXPR_OR_INLINE
      75                 : std::size_t
      76           21378 : path_segments(
      77                 :     core::string_view s,
      78                 :     std::size_t nseg) noexcept
      79                 : {
      80           21378 :     switch(s.size())
      81                 :     {
      82            3525 :     case 0:
      83            3525 :         BOOST_ASSERT(nseg == 0);
      84            3525 :         return 0;
      85                 : 
      86            3365 :     case 1:
      87            3365 :         BOOST_ASSERT(nseg == 1);
      88            3365 :         if(s[0] == '/')
      89            1579 :             return 0;
      90            1786 :         return 1;
      91                 : 
      92            1664 :     case 2:
      93            1664 :         if(s[0] == '/')
      94             237 :             return nseg;
      95            1490 :         if( s[0] == '.' &&
      96              63 :             s[1] == '/')
      97                 :         {
      98              15 :             BOOST_ASSERT(nseg > 1);
      99              15 :             return nseg - 1;
     100                 :         }
     101            1412 :         return nseg;
     102                 : 
     103           12824 :     default:
     104           12824 :         if(s[0] == '/')
     105                 :         {
     106            5745 :             if( s[1] == '.' &&
     107             186 :                 s[2] == '/')
     108                 :             {
     109              98 :                 BOOST_ASSERT(nseg > 1);
     110              98 :                 return nseg - 1;
     111                 :             }
     112            5461 :             return nseg;
     113                 :         }
     114            7499 :         if( s[0] == '.' &&
     115             234 :             s[1] == '/')
     116                 :         {
     117             110 :             BOOST_ASSERT(nseg > 1);
     118             110 :             return nseg - 1;
     119                 :         }
     120            7155 :         break;
     121                 :     }
     122            7155 :     return nseg;
     123                 : }
     124                 : 
     125                 : // Trim reserved characters from
     126                 : // the front of the path.
     127                 : inline
     128                 : core::string_view
     129                 : clean_path(
     130                 :     core::string_view s) noexcept
     131                 : {
     132                 :     s.remove_prefix(
     133                 :         path_prefix(s));
     134                 :     return s;
     135                 : }
     136                 : 
     137                 : } // detail
     138                 : } // urls
     139                 : } // boost
     140                 : 
     141                 : #endif
        

Generated by: LCOV version 2.3