12
12
namespace network {
13
13
uri_builder::uri_builder (const network::uri &base_uri) {
14
14
if (base_uri.has_scheme ()) {
15
- set_scheme ( base_uri.scheme ().to_string () );
15
+ scheme_ = base_uri.scheme ().to_string ();
16
16
}
17
17
18
18
if (base_uri.has_user_info ()) {
19
- set_user_info ( base_uri.user_info ().to_string () );
19
+ user_info_ = base_uri.user_info ().to_string ();
20
20
}
21
21
22
22
if (base_uri.has_host ()) {
23
- set_host ( base_uri.host ().to_string () );
23
+ host_ = base_uri.host ().to_string ();
24
24
}
25
25
26
26
if (base_uri.has_port ()) {
27
- set_port ( base_uri.port ().to_string () );
27
+ port_ = base_uri.port ().to_string ();
28
28
}
29
29
30
30
if (base_uri.has_path ()) {
31
- set_path ( base_uri.path ().to_string () );
31
+ path_ = base_uri.path ().to_string ();
32
32
}
33
33
34
34
if (base_uri.has_query ()) {
35
- append_query ( base_uri.query ().to_string () );
35
+ query_ = base_uri.query ().to_string ();
36
36
}
37
37
38
38
if (base_uri.has_fragment ()) {
39
- set_fragment ( base_uri.fragment ().to_string () );
39
+ fragment_ = base_uri.fragment ().to_string ();
40
40
}
41
41
}
42
42
43
43
uri_builder::~uri_builder () noexcept {}
44
44
45
45
network::uri uri_builder::uri () const { return network::uri (*this ); }
46
46
47
- void uri_builder::set_scheme (string_type scheme) {
47
+ void uri_builder::set_scheme (string_type && scheme) {
48
48
// validate scheme is valid and normalize
49
49
scheme_ = scheme;
50
50
detail::transform (*scheme_, std::begin (*scheme_),
51
51
[] (char ch) { return std::tolower (ch, std::locale ()); });
52
52
}
53
53
54
- void uri_builder::set_user_info (string_type user_info) {
54
+ void uri_builder::set_user_info (string_type && user_info) {
55
55
user_info_ = string_type ();
56
56
network::uri::encode_user_info (std::begin (user_info), std::end (user_info),
57
57
std::back_inserter (*user_info_));
@@ -62,15 +62,15 @@ uri_builder &uri_builder::clear_user_info() {
62
62
return *this ;
63
63
}
64
64
65
- void uri_builder::set_host (string_type host) {
65
+ void uri_builder::set_host (string_type && host) {
66
66
host_ = string_type ();
67
67
network::uri::encode_host (std::begin (host), std::end (host),
68
68
std::back_inserter (*host_));
69
69
detail::transform (*host_, std::begin (*host_),
70
70
[](char ch) { return std::tolower (ch, std::locale ()); });
71
71
}
72
72
73
- void uri_builder::set_port (string_type port) {
73
+ void uri_builder::set_port (string_type && port) {
74
74
port_ = string_type ();
75
75
network::uri::encode_port (std::begin (port), std::end (port),
76
76
std::back_inserter (*port_));
@@ -81,7 +81,7 @@ uri_builder &uri_builder::clear_port() {
81
81
return *this ;
82
82
}
83
83
84
- void uri_builder::set_authority (string_type authority) {
84
+ void uri_builder::set_authority (string_type && authority) {
85
85
optional<detail::uri_part> user_info, host, port;
86
86
uri::string_view view (authority);
87
87
uri::const_iterator it = std::begin (view), last = std::end (view);
@@ -100,7 +100,7 @@ void uri_builder::set_authority(string_type authority) {
100
100
}
101
101
}
102
102
103
- void uri_builder::set_path (string_type path) {
103
+ void uri_builder::set_path (string_type && path) {
104
104
path_ = string_type ();
105
105
network::uri::encode_path (std::begin (path), std::end (path),
106
106
std::back_inserter (*path_));
@@ -111,36 +111,35 @@ uri_builder &uri_builder::clear_path() {
111
111
return *this ;
112
112
}
113
113
114
- void uri_builder::append_query (string_type query ) {
114
+ void uri_builder::append_query_component (string_type &&name ) {
115
115
if (!query_) {
116
116
query_ = string_type ();
117
117
}
118
118
else {
119
119
query_->append (" &" );
120
120
}
121
- network::uri::encode_query ( std::begin (query), std::end (query),
122
- std::back_inserter (*query_));
121
+ network::uri::encode_query_component (
122
+ std::begin (name), std::end (name), std::back_inserter (*query_));
123
123
}
124
124
125
- void uri_builder::append_query_key_value_pair (string_type key, string_type value) {
125
+ void uri_builder::append_query_key_value_pair (string_type && key, string_type && value) {
126
126
if (!query_) {
127
127
query_ = string_type ();
128
128
} else {
129
129
query_->push_back (' &' );
130
130
}
131
- detail::encode_query_component (std::begin (key), std::end (key),
132
- std::back_inserter (*query_));
133
- query_->push_back (' =' );
134
- detail::encode_query_component (std::begin (value), std::end (value),
135
- std::back_inserter (*query_));
131
+ network::uri::encode_query_key_value_pair (
132
+ std::begin (key), std::end (key),
133
+ std::begin (value), std::end (value),
134
+ std::back_inserter (*query_));
136
135
}
137
136
138
137
uri_builder &uri_builder::clear_query () {
139
138
query_ = network::nullopt ;
140
139
return *this ;
141
140
}
142
141
143
- void uri_builder::set_fragment (string_type fragment) {
142
+ void uri_builder::set_fragment (string_type && fragment) {
144
143
fragment_ = string_type ();
145
144
network::uri::encode_fragment (std::begin (fragment), std::end (fragment),
146
145
std::back_inserter (*fragment_));
0 commit comments