10
10
# include < boost/network/uri/detail/uri_parts.hpp>
11
11
# include < boost/operators.hpp>
12
12
# include < boost/utility/swap.hpp>
13
+ # include < boost/range/iterator_range.hpp>
13
14
# include < boost/lexical_cast.hpp>
14
15
# include < boost/optional.hpp>
15
16
# include < algorithm>
@@ -21,7 +22,7 @@ namespace uri {
21
22
namespace detail {
22
23
bool parse (std::string::const_iterator first,
23
24
std::string::const_iterator last,
24
- uri_parts<std::string::const_iterator> &parts);
25
+ uri_parts &parts);
25
26
} // namespace detail
26
27
27
28
@@ -32,9 +33,7 @@ class uri
32
33
33
34
typedef std::string string_type;
34
35
typedef string_type::iterator iterator;
35
- typedef boost::iterator_range<iterator> range_type;
36
36
typedef string_type::const_iterator const_iterator;
37
- typedef boost::iterator_range<const_iterator> const_range_type;
38
37
39
38
uri ()
40
39
: is_valid_(false ) {
@@ -45,7 +44,7 @@ class uri
45
44
class FwdIter
46
45
>
47
46
uri (const FwdIter &first, const FwdIter &last)
48
- : uri_(first, last), uri_parts_(first, first), is_valid_(false ) {
47
+ : uri_(first, last), is_valid_(false ) {
49
48
parse ();
50
49
}
51
50
@@ -97,67 +96,32 @@ class uri
97
96
return uri_.end ();
98
97
}
99
98
100
- const_range_type scheme_range () const {
101
- return uri_parts_.scheme ;
102
- }
103
-
104
- const_range_type user_info_range () const {
105
- return uri_parts_.hier_part .user_info ;
106
- }
107
-
108
- const_range_type host_range () const {
109
- return uri_parts_.hier_part .host ;
110
- }
111
-
112
- const_range_type port_range () const {
113
- return uri_parts_.hier_part .port ;
114
- }
115
-
116
- const_range_type path_range () const {
117
- return uri_parts_.hier_part .path ;
118
- }
119
-
120
- const_range_type query_range () const {
121
- return uri_parts_.query ;
122
- }
123
-
124
- const_range_type fragment_range () const {
125
- return uri_parts_.fragment ;
126
- }
127
-
128
99
string_type scheme () const {
129
- const_range_type range = scheme_range ();
130
- return string_type (boost::begin (range), boost::end (range));
100
+ return uri_parts_.scheme ;
131
101
}
132
102
133
103
string_type user_info () const {
134
- const_range_type range = user_info_range ();
135
- return string_type (boost::begin (range), boost::end (range));
104
+ return uri_parts_.hier_part .user_info ;
136
105
}
137
106
138
107
string_type host () const {
139
- const_range_type range = host_range ();
140
- return string_type (boost::begin (range), boost::end (range));
108
+ return uri_parts_.hier_part .host ;
141
109
}
142
110
143
111
string_type port () const {
144
- const_range_type range = port_range ();
145
- return string_type (boost::begin (range), boost::end (range));
112
+ return uri_parts_.hier_part .port ;
146
113
}
147
114
148
115
string_type path () const {
149
- const_range_type range = path_range ();
150
- return string_type (boost::begin (range), boost::end (range));
116
+ return uri_parts_.hier_part .path ;
151
117
}
152
118
153
119
string_type query () const {
154
- const_range_type range = query_range ();
155
- return string_type (boost::begin (range), boost::end (range));
120
+ return uri_parts_.query ;
156
121
}
157
122
158
123
string_type fragment () const {
159
- const_range_type range = fragment_range ();
160
- return string_type (boost::begin (range), boost::end (range));
124
+ return uri_parts_.fragment ;
161
125
}
162
126
163
127
string_type string () const {
@@ -186,13 +150,14 @@ class uri
186
150
void parse ();
187
151
188
152
string_type uri_;
189
- detail::uri_parts<std::string::const_iterator> uri_parts_;
153
+ detail::uri_parts uri_parts_;
190
154
bool is_valid_;
191
155
192
156
};
193
157
194
158
inline
195
159
void uri::parse () {
160
+ uri_parts_.clear ();
196
161
const_iterator first (boost::begin (uri_)), last (boost::end (uri_));
197
162
is_valid_ = detail::parse (first, last, uri_parts_);
198
163
}
@@ -242,14 +207,25 @@ std::string fragment(const uri &uri_) {
242
207
243
208
inline
244
209
std::string authority (const uri &uri_) {
245
- uri::const_range_type user_info (uri_.user_info_range ());
246
- uri::const_range_type port (uri_.port_range ());
247
- return std::string (user_info.begin (), port.end ());
248
- }
249
-
250
- inline
251
- std::string netloc (const uri &uri_) {
252
- return authority (uri_);
210
+ std::string user_info (uri_.user_info ());
211
+ std::string host (uri_.host ());
212
+ std::string port (uri_.port ());
213
+ std::string authority;
214
+ if (!boost::empty (user_info))
215
+ {
216
+ std::copy (boost::begin (user_info), boost::end (user_info), std::back_inserter (authority));
217
+ authority.push_back (' @' );
218
+ }
219
+ if (!boost::empty (host))
220
+ {
221
+ std::copy (boost::begin (host), boost::end (host), std::back_inserter (authority));
222
+ }
223
+ if (!boost::empty (port))
224
+ {
225
+ authority.push_back (' :' );
226
+ std::copy (boost::begin (port), boost::end (port), std::back_inserter (authority));
227
+ }
228
+ return authority;
253
229
}
254
230
255
231
inline
0 commit comments