Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite1f9211

Browse files
committed
[URI] Added some convenient builder functions from URI parts and a filesystem path.
[URI] Added an alternative builder syntax.
1 parentd3d3bff commite1f9211

File tree

14 files changed

+548
-140
lines changed

14 files changed

+548
-140
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
structkey_value_sequence
2626
: spirit::qi::grammar<uri::const_iterator, Map()>
2727
{
28+
typedeftypename Map::key_type key_type;
29+
typedeftypename 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,typenamestd::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-
conststd::string range = uri_.query();
53+
consturi::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::stringusername(const uri &uri_) {
56-
conststd::string user_info = uri_.user_info();
60+
uri::string_typeusername(const uri &uri_) {
61+
consturi::string_type user_info = uri_.user_info();
5762
uri::const_iteratorit(boost::begin(user_info)),end(boost::end(user_info));
5863
for (; it != end; ++it) {
5964
if (*it ==':') {
6065
break;
6166
}
6267
}
63-
returnstd::string(boost::begin(user_info), it);
68+
returnuri::string_type(boost::begin(user_info), it);
6469
}
6570

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

7984
inline
80-
std::stringdecoded_path(const uri &uri_) {
81-
conststd::string path = uri_.path();
82-
std::string decoded_path;
85+
uri::string_typedecoded_path(const uri &uri_) {
86+
consturi::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::stringdecoded_query(const uri &uri_) {
89-
conststd::string query = uri_.query();
90-
std::string decoded_query;
93+
uri::string_typedecoded_query(const uri &uri_) {
94+
consturi::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::stringdecoded_fragment(const uri &uri_) {
97-
conststd::string fragment = uri_.fragment();
98-
std::string decoded_fragment;
101+
uri::string_typedecoded_fragment(const uri &uri_) {
102+
consturi::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+
namespaceboost {
15+
namespacenetwork {
16+
namespaceuri {
17+
classbuilder {
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 (non_hierarchical_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+
returnthis->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+
#defineBOOST_URI_DECL
16+
#else
17+
#defineBOOST_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/directives/scheme.hpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ inline
5454
uri &https(uri &uri_) {
5555
return uri_ <<scheme("https");
5656
}
57+
58+
inline
59+
uri &file(uri &uri_) {
60+
return uri_ <<scheme("file");
61+
}
5762
}// namespace schemes
5863
}// namespace uri
5964
}// namespace network

‎boost/network/uri/schemes.hpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@
1515
namespaceboost {
1616
namespacenetwork {
1717
namespaceuri {
18-
structhierarchical_schemes {
18+
classhierarchical_schemes {
19+
20+
public:
1921

2022
staticvoidregister_(const std::string &scheme);
2123
staticboolexists(const std::string &scheme);
2224

25+
private:
26+
2327
static boost::unordered_set<std::string> schemes_;
2428

2529
};
2630

27-
structnon_hierarchical_schemes {
31+
classnon_hierarchical_schemes {
32+
33+
public:
2834

2935
staticvoidregister_(const std::string &scheme);
3036
staticboolexists(const std::string &scheme);
3137

38+
private:
39+
3240
static boost::unordered_set<std::string> schemes_;
3341

3442
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp