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