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   13319 path_prefix( 24   13319 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   13319 switch(n) 28   13319 switch(n)
29   { 29   {
HITCBC 30   2904 case 0: 30   2904 case 0:
HITCBC 31   2904 return 0; 31   2904 return 0;
32   32  
HITCBC 33   1389 case 1: 33   1389 case 1:
HITCBC 34   1389 if(p[0] == '/') 34   1389 if(p[0] == '/')
HITCBC 35   1168 return 1; 35   1168 return 1;
HITCBC 36   221 return 0; 36   221 return 0;
37   37  
HITCBC 38   543 case 2: 38   543 case 2:
HITCBC 39   543 if(p[0] == '/') 39   543 if(p[0] == '/')
HITCBC 40   368 return 1; 40   368 return 1;
HITCBC 41   175 if( p[0] == '.' && 41   175 if( p[0] == '.' &&
HITCBC 42   88 p[1] == '/') 42   88 p[1] == '/')
HITCBC 43   59 return 2; 43   59 return 2;
HITCBC 44   116 return 0; 44   116 return 0;
45   45  
HITCBC 46   8483 default: 46   8483 default:
HITCBC 47   8483 if(p[0] == '/') 47   8483 if(p[0] == '/')
48   { 48   {
HITCBC 49   6517 if( p[1] == '.' && 49   6517 if( p[1] == '.' &&
HITCBC 50   562 p[2] == '/') 50   562 p[2] == '/')
HITCBC 51   354 return 3; 51   354 return 3;
HITCBC 52   6163 return 1; 52   6163 return 1;
53   } 53   }
HITCBC 54   1966 if( p[0] == '.' && 54   1966 if( p[0] == '.' &&
HITCBC 55   641 p[1] == '/') 55   641 p[1] == '/')
HITCBC 56   351 return 2; 56   351 return 2;
HITCBC 57   1615 break; 57   1615 break;
58   } 58   }
HITCBC 59   1615 return 0; 59   1615 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   13319 path_prefix( 65   13319 path_prefix(
66   core::string_view s) noexcept 66   core::string_view s) noexcept
67   { 67   {
HITCBC 68   13319 return path_prefix( 68   13319 return path_prefix(
HITCBC 69   13319 s.data(), s.size()); 69   13319 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   20058 path_segments( 76   20062 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   20058 switch(s.size()) 80   20062 switch(s.size())
81   { 81   {
HITCBC 82   3386 case 0: 82   3390 case 0:
HITCBC 83   3386 BOOST_ASSERT(nseg == 0); 83   3390 BOOST_ASSERT(nseg == 0);
HITCBC 84   3386 return 0; 84   3390 return 0;
85   85  
HITCBC 86   3172 case 1: 86   3172 case 1:
HITCBC 87   3172 BOOST_ASSERT(nseg == 1); 87   3172 BOOST_ASSERT(nseg == 1);
HITCBC 88   3172 if(s[0] == '/') 88   3172 if(s[0] == '/')
HITCBC 89   1400 return 0; 89   1400 return 0;
HITCBC 90   1772 return 1; 90   1772 return 1;
91   91  
HITCBC 92   1571 case 2: 92   1571 case 2:
HITCBC 93   1571 if(s[0] == '/') 93   1571 if(s[0] == '/')
HITCBC 94   159 return nseg; 94   159 return nseg;
HITCBC 95   1465 if( s[0] == '.' && 95   1465 if( s[0] == '.' &&
HITCBC 96   53 s[1] == '/') 96   53 s[1] == '/')
97   { 97   {
HITCBC 98   14 BOOST_ASSERT(nseg > 1); 98   14 BOOST_ASSERT(nseg > 1);
HITCBC 99   14 return nseg - 1; 99   14 return nseg - 1;
100   } 100   }
HITCBC 101   1398 return nseg; 101   1398 return nseg;
102   102  
HITCBC 103   11929 default: 103   11929 default:
HITCBC 104   11929 if(s[0] == '/') 104   11929 if(s[0] == '/')
105   { 105   {
HITCBC 106   4950 if( s[1] == '.' && 106   4950 if( s[1] == '.' &&
HITCBC 107   73 s[2] == '/') 107   73 s[2] == '/')
108   { 108   {
HITCBC 109   51 BOOST_ASSERT(nseg > 1); 109   51 BOOST_ASSERT(nseg > 1);
HITCBC 110   51 return nseg - 1; 110   51 return nseg - 1;
111   } 111   }
HITCBC 112   4826 return nseg; 112   4826 return nseg;
113   } 113   }
HITCBC 114   7213 if( s[0] == '.' && 114   7213 if( s[0] == '.' &&
HITCBC 115   161 s[1] == '/') 115   161 s[1] == '/')
116   { 116   {
HITCBC 117   52 BOOST_ASSERT(nseg > 1); 117   52 BOOST_ASSERT(nseg > 1);
HITCBC 118   52 return nseg - 1; 118   52 return nseg - 1;
119   } 119   }
HITCBC 120   7000 break; 120   7000 break;
121   } 121   }
HITCBC 122   7000 return nseg; 122   7000 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