Skip to content

Commit 1fe0b02

Browse files
committed
Merge branch '0.10-devel'
2 parents 0e12b94 + 4f1c182 commit 1fe0b02

19 files changed

+941
-164
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Testing
88
*.gch
99
libs/mime/test/mime-roundtrip
1010
*.a
11+
_build

boost/network/uri/accessors.hpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ template <
2525
struct key_value_sequence
2626
: spirit::qi::grammar<uri::const_iterator, Map()>
2727
{
28+
typedef typename Map::key_type key_type;
29+
typedef typename Map::mapped_type mapped_type;
30+
typedef std::pair<key_type, mapped_type> pair_type;
31+
2832
key_value_sequence()
2933
: key_value_sequence::base_type(query)
3034
{
@@ -35,8 +39,9 @@ struct key_value_sequence
3539
}
3640

3741
spirit::qi::rule<uri::const_iterator, Map()> query;
38-
spirit::qi::rule<uri::const_iterator, std::pair<std::string, std::string>()> pair;
39-
spirit::qi::rule<uri::const_iterator, typename std::string()> key, value;
42+
spirit::qi::rule<uri::const_iterator, pair_type()> pair;
43+
spirit::qi::rule<uri::const_iterator, key_type()> key;
44+
spirit::qi::rule<uri::const_iterator, mapped_type()> value;
4045
};
4146
} // namespace details
4247

@@ -45,57 +50,57 @@ template <
4550
>
4651
inline
4752
Map &query_map(const uri &uri_, Map &map) {
48-
const std::string range = uri_.query();
53+
const uri::string_type range = uri_.query();
4954
details::key_value_sequence<Map> parser;
5055
spirit::qi::parse(boost::begin(range), boost::end(range), parser, map);
5156
return map;
5257
}
5358

5459
inline
55-
std::string username(const uri &uri_) {
56-
const std::string user_info = uri_.user_info();
60+
uri::string_type username(const uri &uri_) {
61+
const uri::string_type user_info = uri_.user_info();
5762
uri::const_iterator it(boost::begin(user_info)), end(boost::end(user_info));
5863
for (; it != end; ++it) {
5964
if (*it == ':') {
6065
break;
6166
}
6267
}
63-
return std::string(boost::begin(user_info), it);
68+
return uri::string_type(boost::begin(user_info), it);
6469
}
6570

6671
inline
67-
std::string password(const uri &uri_) {
68-
const std::string user_info = uri_.user_info();
72+
uri::string_type password(const uri &uri_) {
73+
const uri::string_type user_info = uri_.user_info();
6974
uri::const_iterator it(boost::begin(user_info)), end(boost::end(user_info));
7075
for (; it != end; ++it) {
7176
if (*it == ':') {
7277
++it;
7378
break;
7479
}
7580
}
76-
return std::string(it, boost::end(user_info));
81+
return uri::string_type(it, boost::end(user_info));
7782
}
7883

7984
inline
80-
std::string decoded_path(const uri &uri_) {
81-
const std::string path = uri_.path();
82-
std::string decoded_path;
85+
uri::string_type decoded_path(const uri &uri_) {
86+
const uri::string_type path = uri_.path();
87+
uri::string_type decoded_path;
8388
decode(path, std::back_inserter(decoded_path));
8489
return decoded_path;
8590
}
8691

8792
inline
88-
std::string decoded_query(const uri &uri_) {
89-
const std::string query = uri_.query();
90-
std::string decoded_query;
93+
uri::string_type decoded_query(const uri &uri_) {
94+
const uri::string_type query = uri_.query();
95+
uri::string_type decoded_query;
9196
decode(query, std::back_inserter(decoded_query));
9297
return decoded_query;
9398
}
9499

95100
inline
96-
std::string decoded_fragment(const uri &uri_) {
97-
const std::string fragment = uri_.fragment();
98-
std::string decoded_fragment;
101+
uri::string_type decoded_fragment(const uri &uri_) {
102+
const uri::string_type fragment = uri_.fragment();
103+
uri::string_type decoded_fragment;
99104
decode(fragment, std::back_inserter(decoded_fragment));
100105
return decoded_fragment;
101106
}

boost/network/uri/builder.hpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) Glyn Matthews 2012.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
7+
#ifndef __BOOST_NETWORK_URI_BUILDER_INC__
8+
# define __BOOST_NETWORK_URI_BUILDER_INC__
9+
10+
11+
# include <boost/network/uri/uri.hpp>
12+
13+
14+
namespace boost {
15+
namespace network {
16+
namespace uri {
17+
class builder {
18+
19+
typedef uri::string_type string_type;
20+
21+
public:
22+
23+
builder(uri &uri_)
24+
: uri_(uri_) {
25+
26+
}
27+
28+
builder &scheme(const string_type &scheme) {
29+
uri_.uri_.append(scheme);
30+
if (opaque_schemes::exists(scheme)) {
31+
uri_.uri_.append(":");
32+
}
33+
else {
34+
uri_.uri_.append("://");
35+
}
36+
uri_.parse();
37+
return *this;
38+
}
39+
40+
builder &user_info(const string_type &user_info) {
41+
uri_.uri_.append(user_info);
42+
uri_.uri_.append("@");
43+
uri_.parse();
44+
return *this;
45+
}
46+
47+
builder &host(const string_type &host) {
48+
uri_.uri_.append(host);
49+
uri_.parse();
50+
return *this;
51+
}
52+
53+
builder &port(const string_type &port) {
54+
uri_.uri_.append(":");
55+
uri_.uri_.append(port);
56+
uri_.parse();
57+
return *this;
58+
}
59+
60+
builder &port(uint16_t port) {
61+
return this->port(boost::lexical_cast<string_type>(port));
62+
}
63+
64+
builder &path(const string_type &path) {
65+
uri_.uri_.append(path);
66+
uri_.parse();
67+
return *this;
68+
}
69+
70+
builder &encoded_path(const string_type &path) {
71+
string_type encoded_path;
72+
encode(path, std::back_inserter(encoded_path));
73+
uri_.uri_.append(encoded_path);
74+
uri_.parse();
75+
return *this;
76+
}
77+
78+
builder &query(const string_type &query) {
79+
uri_.uri_.append("?");
80+
uri_.uri_.append(query);
81+
uri_.parse();
82+
return *this;
83+
}
84+
85+
builder &query(const string_type &key, const string_type &value) {
86+
if (!uri_.query_range())
87+
{
88+
uri_.uri_.append("?");
89+
}
90+
else
91+
{
92+
uri_.uri_.append("&");
93+
}
94+
uri_.uri_.append(key);
95+
uri_.uri_.append("=");
96+
uri_.uri_.append(value);
97+
uri_.parse();
98+
return *this;
99+
}
100+
101+
builder &fragment(const string_type &fragment) {
102+
uri_.uri_.append("#");
103+
uri_.uri_.append(fragment);
104+
uri_.parse();
105+
return *this;
106+
}
107+
108+
private:
109+
110+
uri &uri_;
111+
112+
};
113+
} // namespace uri
114+
} // namespace network
115+
} // namespace boost
116+
117+
118+
#endif // __BOOST_NETWORK_URI_BUILDER_INC__

boost/network/uri/config.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Glyn Matthews 2012.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
7+
#ifndef __BOOST_NETWORK_URI_CONFIG_INC__
8+
# define __BOOST_NETWORK_URI_CONFIG_INC__
9+
10+
11+
# include <boost/config.hpp>
12+
# include <boost/detail/workaround.hpp>
13+
14+
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_URI_DYN_LINK)
15+
# define BOOST_URI_DECL
16+
# else
17+
# define BOOST_URI_DECL
18+
# endif // defined(BOOST_ALL_DYN_LINK) || defined(BOOST_URI_DYN_LINK)
19+
20+
21+
#endif // __BOOST_NETWORK_URI_CONFIG_INC__

boost/network/uri/detail/uri_parts.hpp

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,43 @@ struct hierarchical_part {
2323
optional<iterator_range<FwdIter> > host;
2424
optional<iterator_range<FwdIter> > port;
2525
optional<iterator_range<FwdIter> > path;
26+
27+
FwdIter begin() const {
28+
return boost::begin(user_info);
29+
}
30+
31+
FwdIter end() const {
32+
return boost::end(path);
33+
}
34+
35+
void update() {
36+
if (!user_info) {
37+
if (host) {
38+
user_info = iterator_range<FwdIter>(boost::begin(host.get()),
39+
boost::begin(host.get()));
40+
}
41+
else if (path) {
42+
user_info = iterator_range<FwdIter>(boost::begin(path.get()),
43+
boost::begin(path.get()));
44+
}
45+
}
46+
47+
if (!host) {
48+
host = iterator_range<FwdIter>(boost::begin(path.get()),
49+
boost::begin(path.get()));
50+
}
51+
52+
if (!port) {
53+
port = iterator_range<FwdIter>(boost::end(host.get()),
54+
boost::end(host.get()));
55+
}
56+
57+
if (!path) {
58+
path = iterator_range<FwdIter>(boost::end(port.get()),
59+
boost::end(port.get()));
60+
}
61+
}
62+
2663
};
2764

2865
template <
@@ -34,14 +71,27 @@ struct uri_parts {
3471
optional<iterator_range<FwdIter> > query;
3572
optional<iterator_range<FwdIter> > fragment;
3673

37-
void clear() {
38-
scheme = iterator_range<FwdIter>();
39-
hier_part.user_info = optional<iterator_range<FwdIter> >();
40-
hier_part.host = optional<iterator_range<FwdIter> >();
41-
hier_part.port = optional<iterator_range<FwdIter> >();
42-
hier_part.path = optional<iterator_range<FwdIter> >();
43-
query = optional<iterator_range<FwdIter> >();
44-
fragment = optional<iterator_range<FwdIter> >();
74+
FwdIter begin() const {
75+
return boost::begin(scheme);
76+
}
77+
78+
FwdIter end() const {
79+
return boost::end(fragment);
80+
}
81+
82+
void update() {
83+
84+
hier_part.update();
85+
86+
if (!query) {
87+
query = iterator_range<FwdIter>(boost::end(hier_part.path.get()),
88+
boost::end(hier_part.path.get()));
89+
}
90+
91+
if (!fragment) {
92+
fragment = iterator_range<FwdIter>(boost::end(query.get()),
93+
boost::end(query.get()));
94+
}
4595
}
4696
};
4797
} // namespace detail

boost/network/uri/directives.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@
99

1010

1111
# include <boost/network/uri/uri.hpp>
12-
# include <boost/network/uri/directives/scheme.hpp>
13-
# include <boost/network/uri/directives/user_info.hpp>
14-
# include <boost/network/uri/directives/host.hpp>
15-
# include <boost/network/uri/directives/port.hpp>
16-
# include <boost/network/uri/directives/authority.hpp>
17-
# include <boost/network/uri/directives/path.hpp>
18-
# include <boost/network/uri/directives/query.hpp>
19-
# include <boost/network/uri/directives/fragment.hpp>
2012

2113

2214
namespace boost {
@@ -43,4 +35,14 @@ uri &operator << (uri &uri_, const Directive &directive) {
4335
} // namespace boost
4436

4537

38+
# include <boost/network/uri/directives/scheme.hpp>
39+
# include <boost/network/uri/directives/user_info.hpp>
40+
# include <boost/network/uri/directives/host.hpp>
41+
# include <boost/network/uri/directives/port.hpp>
42+
# include <boost/network/uri/directives/authority.hpp>
43+
# include <boost/network/uri/directives/path.hpp>
44+
# include <boost/network/uri/directives/query.hpp>
45+
# include <boost/network/uri/directives/fragment.hpp>
46+
47+
4648
#endif // __BOOST_NETWORK_URI_DIRECTIVES_INC__

boost/network/uri/directives/scheme.hpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# include <boost/range/begin.hpp>
1212
# include <boost/range/end.hpp>
13+
# include <boost/network/uri/schemes.hpp>
1314

1415

1516
namespace boost {
@@ -26,7 +27,12 @@ struct scheme_directive {
2627
>
2728
void operator () (Uri &uri) const {
2829
uri.append(scheme);
29-
uri.append("://");
30+
if (opaque_schemes::exists(scheme)) {
31+
uri.append(":");
32+
}
33+
else {
34+
uri.append("://");
35+
}
3036
}
3137

3238
std::string scheme;
@@ -37,6 +43,23 @@ inline
3743
scheme_directive scheme(const std::string &scheme) {
3844
return scheme_directive(scheme);
3945
}
46+
47+
namespace schemes {
48+
inline
49+
uri &http(uri &uri_) {
50+
return uri_ << scheme("http");
51+
}
52+
53+
inline
54+
uri &https(uri &uri_) {
55+
return uri_ << scheme("https");
56+
}
57+
58+
inline
59+
uri &file(uri &uri_) {
60+
return uri_ << scheme("file");
61+
}
62+
} // namespace schemes
4063
} // namespace uri
4164
} // namespace network
4265
} // namespace boost

0 commit comments

Comments
 (0)