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 4368 : path_prefix(
25 : char const* p,
26 : std::size_t n) noexcept
27 : {
28 4368 : switch(n)
29 : {
30 311 : case 0:
31 311 : return 0;
32 :
33 240 : case 1:
34 240 : if(p[0] == '/')
35 155 : return 1;
36 85 : return 0;
37 :
38 259 : case 2:
39 259 : if(p[0] == '/')
40 158 : return 1;
41 101 : if( p[0] == '.' &&
42 86 : p[1] == '/')
43 57 : return 2;
44 44 : return 0;
45 :
46 3558 : default:
47 3558 : if(p[0] == '/')
48 : {
49 1906 : if( p[1] == '.' &&
50 433 : p[2] == '/')
51 234 : return 3;
52 1672 : return 1;
53 : }
54 1652 : if( p[0] == '.' &&
55 638 : p[1] == '/')
56 351 : return 2;
57 1301 : break;
58 : }
59 1301 : return 0;
60 : }
61 :
62 : // VFALCO DEPRECATED
63 : inline
64 : std::size_t
65 4368 : path_prefix(
66 : core::string_view s) noexcept
67 : {
68 4368 : return path_prefix(
69 4368 : 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 3906 : path_segments(
77 : core::string_view s,
78 : std::size_t nseg) noexcept
79 : {
80 3906 : switch(s.size())
81 : {
82 1184 : case 0:
83 1184 : BOOST_ASSERT(nseg == 0);
84 1184 : return 0;
85 :
86 565 : case 1:
87 565 : BOOST_ASSERT(nseg == 1);
88 565 : if(s[0] == '/')
89 505 : return 0;
90 60 : return 1;
91 :
92 182 : case 2:
93 182 : if(s[0] == '/')
94 140 : return nseg;
95 66 : if( s[0] == '.' &&
96 24 : s[1] == '/')
97 : {
98 14 : BOOST_ASSERT(nseg > 1);
99 14 : return nseg - 1;
100 : }
101 28 : return nseg;
102 :
103 1975 : default:
104 1975 : if(s[0] == '/')
105 : {
106 1095 : if( s[1] == '.' &&
107 67 : s[2] == '/')
108 : {
109 45 : BOOST_ASSERT(nseg > 1);
110 45 : return nseg - 1;
111 : }
112 983 : return nseg;
113 : }
114 1024 : if( s[0] == '.' &&
115 77 : s[1] == '/')
116 : {
117 39 : BOOST_ASSERT(nseg > 1);
118 39 : return nseg - 1;
119 : }
120 908 : break;
121 : }
122 908 : 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
|