Skip to content

Commit ab5864a

Browse files
committed
Replace boost usage
1 parent e8a2ca8 commit ab5864a

File tree

2 files changed

+46
-59
lines changed

2 files changed

+46
-59
lines changed

src/detail/uri_normalize.cpp

+11-21
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,23 @@
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

6+
#include "uri_normalize.hpp"
7+
#include "uri_percent_encode.hpp"
8+
#include "algorithm.hpp"
9+
#include "algorithm_split.hpp"
610
#include <iterator>
711
#include <vector>
812
#include <algorithm>
913

10-
#ifdef NETWORK_URI_EXTERNAL_BOOST
11-
#include <boost/algorithm/string/split.hpp>
12-
#include <boost/algorithm/string/join.hpp>
13-
namespace network_boost = boost;
14-
#else // NETWORK_URI_EXTERNAL_BOOST
15-
#include "../boost/algorithm/string/split.hpp"
16-
#include "../boost/algorithm/string/join.hpp"
17-
#endif // NETWORK_URI_EXTERNAL_BOOST
18-
19-
#include "uri_normalize.hpp"
20-
#include "uri_percent_encode.hpp"
21-
#include "algorithm.hpp"
14+
using namespace network::algorithm;
15+
namespace network_detail = network::detail;
2216

23-
namespace network {
24-
namespace detail {
25-
std::string normalize_path_segments(string_view path) {
17+
std::string network_detail::normalize_path_segments(string_view path) {
2618
std::string result;
2719

2820
if (!path.empty()) {
2921
std::vector<std::string> path_segments;
30-
network_boost::split(path_segments, path,
31-
[](char ch) { return ch == '/'; });
22+
split(path_segments, path, '/');
3223

3324
bool last_segment_is_slash = path_segments.back().empty();
3425
std::vector<std::string> normalized_segments;
@@ -61,12 +52,13 @@ std::string normalize_path_segments(string_view path) {
6152
return result;
6253
}
6354

64-
std::string normalize_path(string_view path, uri_comparison_level level) {
55+
std::string network_detail::normalize_path(string_view path,
56+
uri_comparison_level level) {
6557
auto result = path.to_string();
6658

6759
if (uri_comparison_level::syntax_based == level) {
6860
// case normalization
69-
detail::for_each(result, percent_encoded_to_upper<std::string>());
61+
for_each(result, percent_encoded_to_upper<std::string>());
7062

7163
// % encoding normalization
7264
result.erase(detail::decode_encoded_unreserved_chars(std::begin(result),
@@ -79,5 +71,3 @@ std::string normalize_path(string_view path, uri_comparison_level level) {
7971

8072
return result;
8173
}
82-
} // namespace detail
83-
} // namespace network

src/detail/uri_resolve.cpp

+35-38
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@
55
// http://www.boost.org/LICENSE_1_0.txt)
66

77
#include "uri_resolve.hpp"
8-
#include <algorithm>
8+
#include "algorithm_find.hpp"
99

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 {
2214

23-
namespace network {
24-
namespace detail {
2515
// remove_dot_segments
2616
inline void remove_last_segment(std::string &path) {
2717
while (!path.empty()) {
@@ -33,57 +23,64 @@ inline void remove_last_segment(std::string &path) {
3323
}
3424
}
3525

26+
inline bool starts_with(std::string const &str, const char *range) {
27+
return str.find(range) == 0;
28+
}
29+
3630
// implementation of http://tools.ietf.org/html/rfc3986#section-5.2.4
3731
static std::string remove_dot_segments(std::string input) {
3832
std::string result;
3933

4034
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() = '/';
4742
} 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);
5147
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() = '/';
5451
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 == '.'; })) {
5753
input.clear();
5854
} else {
5955
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);
6359
}
6460
}
6561
return result;
6662
}
6763

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());
7068
}
7169

7270
// 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) {
7472
std::string result;
7573

7674
if (!base.has_path() || base.path().empty()) {
7775
result = "/";
7876
} else {
7977
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);
8281
}
8382
if (reference.has_path()) {
8483
result.append(reference.path().to_string());
8584
}
8685
return remove_dot_segments(string_view(result));
8786
}
88-
} // namespace detail
89-
} // namespace network

0 commit comments

Comments
 (0)