5
5
// http://www.boost.org/LICENSE_1_0.txt)
6
6
7
7
#include " uri_resolve.hpp"
8
- #include < algorithm >
8
+ #include " algorithm_find.hpp "
9
9
10
- #ifdef NETWORK_URI_EXTERNAL_BOOST
11
- #include < boost/algorithm/string/find.hpp>
12
- #include < boost/algorithm/string/erase.hpp>
13
- #include < boost/algorithm/string/replace.hpp>
14
- #include < boost/algorithm/string/predicate.hpp>
15
- namespace network_boost = boost;
16
- #else // NETWORK_URI_EXTERNAL_BOOST
17
- #include " ../boost/algorithm/string/find.hpp"
18
- #include " ../boost/algorithm/string/erase.hpp"
19
- #include " ../boost/algorithm/string/replace.hpp"
20
- #include " ../boost/algorithm/string/predicate.hpp"
21
- #endif // NETWORK_URI_EXTERNAL_BOOST
10
+ using namespace network ::algorithm;
11
+ namespace network_detail = network::detail;
12
+
13
+ namespace {
22
14
23
- namespace network {
24
- namespace detail {
25
15
// remove_dot_segments
26
16
inline void remove_last_segment (std::string &path) {
27
17
while (!path.empty ()) {
@@ -33,57 +23,64 @@ inline void remove_last_segment(std::string &path) {
33
23
}
34
24
}
35
25
26
+ inline bool starts_with (std::string const &str, const char *range) {
27
+ return str.find (range) == 0 ;
28
+ }
29
+
36
30
// implementation of http://tools.ietf.org/html/rfc3986#section-5.2.4
37
31
static std::string remove_dot_segments (std::string input) {
38
32
std::string result;
39
33
40
34
while (!input.empty ()) {
41
- if (network_boost::starts_with (input, " ../" )) {
42
- network_boost::erase_head (input, 3 );
43
- } else if (network_boost::starts_with (input, " ./" )) {
44
- network_boost::erase_head (input, 2 );
45
- } else if (network_boost::starts_with (input, " /./" )) {
46
- network_boost::replace_head (input, 3 , " /" );
35
+ if (starts_with (input, " ../" )) {
36
+ input.erase (0 , 3 );
37
+ } else if (starts_with (input, " ./" )) {
38
+ input.erase (0 , 2 );
39
+ } else if (starts_with (input, " /./" )) {
40
+ input.erase (0 , 2 );
41
+ input.front () = ' /' ;
47
42
} else if (input == " /." ) {
48
- network_boost::replace_head (input, 2 , " /" );
49
- } else if (network_boost::starts_with (input, " /../" )) {
50
- network_boost::erase_head (input, 3 );
43
+ input.erase (0 , 1 );
44
+ input.front () = ' /' ;
45
+ } else if (starts_with (input, " /../" )) {
46
+ input.erase (0 , 3 );
51
47
remove_last_segment (result);
52
- } else if (network_boost::starts_with (input, " /.." )) {
53
- network_boost::replace_head (input, 3 , " /" );
48
+ } else if (starts_with (input, " /.." )) {
49
+ input.erase (0 , 2 );
50
+ input.front () = ' /' ;
54
51
remove_last_segment (result);
55
- } else if (network_boost::algorithm::all (
56
- input, [](char ch) { return ch == ' .' ; })) {
52
+ } else if (all (input, [](char ch) { return ch == ' .' ; })) {
57
53
input.clear ();
58
54
} else {
59
55
int n = (input.front () == ' /' ) ? 1 : 0 ;
60
- auto slash = network_boost:: find_nth (input, " / " , n);
61
- result.append (std::begin ( input), std::begin ( slash) );
62
- input.erase (std::begin (input), std::begin ( slash) );
56
+ std::string::const_iterator slash = find_nth (input, ' / ' , n);
57
+ result.append (input. cbegin ( ), slash);
58
+ input.erase (std::begin (input), slash);
63
59
}
64
60
}
65
61
return result;
66
62
}
67
63
68
- std::string remove_dot_segments (string_view path) {
69
- return remove_dot_segments (path.to_string ());
64
+ } // namespace
65
+
66
+ std::string network_detail::remove_dot_segments (string_view path) {
67
+ return ::remove_dot_segments (path.to_string ());
70
68
}
71
69
72
70
// implementation of http://tools.ietf.org/html/rfc3986#section-5.2.3
73
- std::string merge_paths (const uri &base, const uri &reference) {
71
+ std::string network_detail:: merge_paths (const uri &base, const uri &reference) {
74
72
std::string result;
75
73
76
74
if (!base.has_path () || base.path ().empty ()) {
77
75
result = " /" ;
78
76
} else {
79
77
const auto &base_path = base.path ();
80
- auto last_slash = network_boost::find_last (base_path, " /" );
81
- result.append (std::begin (base_path), std::end (last_slash));
78
+ auto last_slash = algorithm::find_last (base_path, ' /' );
79
+ if (last_slash != base_path.cend ()) ++last_slash;
80
+ result.append (std::begin (base_path), last_slash);
82
81
}
83
82
if (reference.has_path ()) {
84
83
result.append (reference.path ().to_string ());
85
84
}
86
85
return remove_dot_segments (string_view (result));
87
86
}
88
- } // namespace detail
89
- } // namespace network
0 commit comments