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 13284 : path_prefix(
25 : char const* p,
26 : std::size_t n) noexcept
27 : {
28 13284 : switch(n)
29 : {
30 2904 : case 0:
31 2904 : return 0;
32 :
33 1389 : case 1:
34 1389 : if(p[0] == '/')
35 1168 : return 1;
36 221 : return 0;
37 :
38 543 : case 2:
39 543 : if(p[0] == '/')
40 368 : return 1;
41 175 : if( p[0] == '.' &&
42 88 : p[1] == '/')
43 59 : return 2;
44 116 : return 0;
45 :
46 8448 : default:
47 8448 : if(p[0] == '/')
48 : {
49 6488 : if( p[1] == '.' &&
50 562 : p[2] == '/')
51 354 : return 3;
52 6134 : return 1;
53 : }
54 1960 : if( p[0] == '.' &&
55 641 : p[1] == '/')
56 351 : return 2;
57 1609 : break;
58 : }
59 1609 : return 0;
60 : }
61 :
62 : // VFALCO DEPRECATED
63 : inline
64 : std::size_t
65 13284 : path_prefix(
66 : core::string_view s) noexcept
67 : {
68 13284 : return path_prefix(
69 13284 : 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 19986 : path_segments(
77 : core::string_view s,
78 : std::size_t nseg) noexcept
79 : {
80 19986 : switch(s.size())
81 : {
82 3386 : case 0:
83 3386 : BOOST_ASSERT(nseg == 0);
84 3386 : return 0;
85 :
86 3160 : case 1:
87 3160 : BOOST_ASSERT(nseg == 1);
88 3160 : if(s[0] == '/')
89 1394 : return 0;
90 1766 : return 1;
91 :
92 1571 : case 2:
93 1571 : if(s[0] == '/')
94 159 : return nseg;
95 1465 : if( s[0] == '.' &&
96 53 : s[1] == '/')
97 : {
98 14 : BOOST_ASSERT(nseg > 1);
99 14 : return nseg - 1;
100 : }
101 1398 : return nseg;
102 :
103 11869 : default:
104 11869 : if(s[0] == '/')
105 : {
106 4919 : if( s[1] == '.' &&
107 67 : s[2] == '/')
108 : {
109 45 : BOOST_ASSERT(nseg > 1);
110 45 : return nseg - 1;
111 : }
112 4807 : return nseg;
113 : }
114 7168 : if( s[0] == '.' &&
115 151 : s[1] == '/')
116 : {
117 42 : BOOST_ASSERT(nseg > 1);
118 42 : return nseg - 1;
119 : }
120 6975 : break;
121 : }
122 6975 : 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
|