Skip to content

Commit f67705f

Browse files
committed
URI no longer uses ranges internally, but strings because of inconsistencies in the parser that I couldn't solve.
1 parent 6183a0c commit f67705f

File tree

7 files changed

+121
-161
lines changed

7 files changed

+121
-161
lines changed

boost/network/protocol/http/impl/request.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace http {
9696
if (!port)
9797
{
9898
typedef constants<Tag> consts;
99-
return boost::iequals(uri_.scheme_range(),
99+
return boost::iequals(uri_.scheme(),
100100
string_type(consts::https()))? 443 : 80;
101101
}
102102
return *port;

boost/network/uri/accessors.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,53 +45,53 @@ template <
4545
>
4646
inline
4747
Map &query_map(const uri &uri_, Map &map) {
48-
uri::const_range_type range = uri_.query_range();
48+
std::string range = uri_.query();
4949
details::key_value_sequence<Map> parser;
5050
spirit::qi::parse(boost::begin(range), boost::end(range), parser, map);
5151
return map;
5252
}
5353

5454
std::string username(const uri &uri_) {
55-
uri::const_range_type user_info_range = uri_.user_info_range();
56-
uri::const_iterator it(boost::begin(user_info_range)), end(boost::end(user_info_range));
55+
std::string user_info = uri_.user_info();
56+
uri::const_iterator it(boost::begin(user_info)), end(boost::end(user_info));
5757
for (; it != end; ++it) {
5858
if (*it == ':') {
5959
break;
6060
}
6161
}
62-
return std::string(boost::begin(user_info_range), it);
62+
return std::string(boost::begin(user_info), it);
6363
}
6464

6565
std::string password(const uri &uri_) {
66-
uri::const_range_type user_info_range = uri_.user_info_range();
67-
uri::const_iterator it(boost::begin(user_info_range)), end(boost::end(user_info_range));
66+
std::string user_info = uri_.user_info();
67+
uri::const_iterator it(boost::begin(user_info)), end(boost::end(user_info));
6868
for (; it != end; ++it) {
6969
if (*it == ':') {
7070
++it;
7171
break;
7272
}
7373
}
74-
return std::string(it, boost::end(user_info_range));
74+
return std::string(it, boost::end(user_info));
7575
}
7676

7777
std::string decoded_path(const uri &uri_) {
78-
uri::const_range_type path_range = uri_.path_range();
78+
std::string path = uri_.path();
7979
std::string decoded_path;
80-
decode(path_range, std::back_inserter(decoded_path));
80+
decode(path, std::back_inserter(decoded_path));
8181
return decoded_path;
8282
}
8383

8484
std::string decoded_query(const uri &uri_) {
85-
uri::const_range_type query_range = uri_.query_range();
85+
std::string query = uri_.query();
8686
std::string decoded_query;
87-
decode(query_range, std::back_inserter(decoded_query));
87+
decode(query, std::back_inserter(decoded_query));
8888
return decoded_query;
8989
}
9090

9191
std::string decoded_fragment(const uri &uri_) {
92-
uri::const_range_type fragment_range = uri_.fragment_range();
92+
std::string fragment = uri_.fragment();
9393
std::string decoded_fragment;
94-
decode(fragment_range, std::back_inserter(decoded_fragment));
94+
decode(fragment, std::back_inserter(decoded_fragment));
9595
return decoded_fragment;
9696
}
9797
} // namespace uri

boost/network/uri/detail/uri_parts.hpp

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,36 @@
77
# define BOOST_NETWORK_URL_DETAIL_URL_PARTS_HPP_
88

99

10-
# include <boost/range/iterator_range.hpp>
10+
# include <string>
1111

1212

1313
namespace boost {
1414
namespace network {
1515
namespace uri {
1616
namespace detail {
17-
template <
18-
class FwdIter
19-
>
2017
struct hierarchical_part {
21-
iterator_range<FwdIter> user_info, host, port, path;
22-
23-
hierarchical_part()
24-
{}
25-
26-
hierarchical_part(FwdIter begin, FwdIter end)
27-
: user_info(begin, end)
28-
, host(begin, end)
29-
, port(begin, end)
30-
, path(begin, end)
31-
{ }
18+
std::string user_info, host, port, path;
19+
20+
void clear() {
21+
user_info.clear();
22+
host.clear();
23+
port.clear();
24+
path.clear();
25+
}
3226
};
3327

34-
template <
35-
class FwdIter
36-
>
3728
struct uri_parts {
38-
iterator_range<FwdIter> scheme;
39-
hierarchical_part<FwdIter> hier_part;
40-
iterator_range<FwdIter> query;
41-
iterator_range<FwdIter> fragment;
42-
43-
uri_parts()
44-
{}
45-
46-
uri_parts(FwdIter begin, FwdIter end)
47-
: scheme(begin, end)
48-
, hier_part(begin, end)
49-
, query(begin, end)
50-
, fragment(begin, end)
51-
{ }
29+
std::string scheme;
30+
hierarchical_part hier_part;
31+
std::string query;
32+
std::string fragment;
33+
34+
void clear() {
35+
scheme.clear();
36+
hier_part.clear();
37+
query.clear();
38+
fragment.clear();
39+
}
5240
};
5341
} // namespace detail
5442
} // namespace uri

boost/network/uri/directives/query.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct query_key_query_directive {
4444
>
4545
void operator () (Uri &uri) const {
4646
std::string encoded_key, encoded_query;
47-
if (!uri.query_range())
47+
if (boost::empty(uri.query()))
4848
{
4949
uri.append("?");
5050
}

boost/network/uri/uri.hpp

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# include <boost/network/uri/detail/uri_parts.hpp>
1111
# include <boost/operators.hpp>
1212
# include <boost/utility/swap.hpp>
13+
# include <boost/range/iterator_range.hpp>
1314
# include <boost/lexical_cast.hpp>
1415
# include <boost/optional.hpp>
1516
# include <algorithm>
@@ -21,7 +22,7 @@ namespace uri {
2122
namespace detail {
2223
bool parse(std::string::const_iterator first,
2324
std::string::const_iterator last,
24-
uri_parts<std::string::const_iterator> &parts);
25+
uri_parts &parts);
2526
} // namespace detail
2627

2728

@@ -32,9 +33,7 @@ class uri
3233

3334
typedef std::string string_type;
3435
typedef string_type::iterator iterator;
35-
typedef boost::iterator_range<iterator> range_type;
3636
typedef string_type::const_iterator const_iterator;
37-
typedef boost::iterator_range<const_iterator> const_range_type;
3837

3938
uri()
4039
: is_valid_(false) {
@@ -45,7 +44,7 @@ class uri
4544
class FwdIter
4645
>
4746
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) {
4948
parse();
5049
}
5150

@@ -97,67 +96,32 @@ class uri
9796
return uri_.end();
9897
}
9998

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-
12899
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;
131101
}
132102

133103
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;
136105
}
137106

138107
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;
141109
}
142110

143111
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;
146113
}
147114

148115
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;
151117
}
152118

153119
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;
156121
}
157122

158123
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;
161125
}
162126

163127
string_type string() const {
@@ -186,13 +150,14 @@ class uri
186150
void parse();
187151

188152
string_type uri_;
189-
detail::uri_parts<std::string::const_iterator> uri_parts_;
153+
detail::uri_parts uri_parts_;
190154
bool is_valid_;
191155

192156
};
193157

194158
inline
195159
void uri::parse() {
160+
uri_parts_.clear();
196161
const_iterator first(boost::begin(uri_)), last(boost::end(uri_));
197162
is_valid_ = detail::parse(first, last, uri_parts_);
198163
}
@@ -242,14 +207,25 @@ std::string fragment(const uri &uri_) {
242207

243208
inline
244209
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;
253229
}
254230

255231
inline

0 commit comments

Comments
 (0)