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

Commita796329

Browse files
committed
[uri] Moved around some deckchairs. Now the main namespace is 'network'. URI headers moved to include/network/uri*
1 parentaca0667 commita796329

28 files changed

+2118
-320
lines changed

‎include/network/uri.hpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 __NETWORK_URI_INC__
8+
#define__NETWORK_URI_INC__
9+
10+
#include<network/uri/uri.hpp>
11+
#include<network/uri/uri_io.hpp>
12+
13+
#endif// __NETWORK_URI_INC__

‎include/network/uri/accessors.hpp‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) Glyn Matthews 2011, 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_URI_ACCESSORS_INC__
8+
#define__BOOST_NETWORK_URI_URI_ACCESSORS_INC__
9+
10+
11+
#include<network/uri/uri.hpp>
12+
#include<network/uri/encode.hpp>
13+
#include<network/uri/decode.hpp>
14+
#include<boost/spirit/include/qi.hpp>
15+
#include<boost/fusion/include/std_pair.hpp>
16+
17+
18+
namespacenetwork {
19+
namespacedetails {
20+
template<
21+
typename Map
22+
>
23+
structkey_value_sequence
24+
: boost::spirit::qi::grammar<uri::const_iterator, Map()>
25+
{
26+
typedeftypename Map::key_type key_type;
27+
typedeftypename Map::mapped_type mapped_type;
28+
typedef std::pair<key_type, mapped_type> pair_type;
29+
30+
key_value_sequence()
31+
: key_value_sequence::base_type(query)
32+
{
33+
query = pair >> *((boost::spirit::qi::lit(';') |'&') >> pair);
34+
pair = key >> -('=' >> value);
35+
key =boost::spirit::qi::char_("a-zA-Z_") >> *boost::spirit::qi::char_("a-zA-Z_0-9/%");
36+
value = +boost::spirit::qi::char_("a-zA-Z_0-9/%");
37+
}
38+
39+
boost::spirit::qi::rule<uri::const_iterator, Map()> query;
40+
boost::spirit::qi::rule<uri::const_iterator, pair_type()> pair;
41+
boost::spirit::qi::rule<uri::const_iterator, key_type()> key;
42+
boost::spirit::qi::rule<uri::const_iterator, mapped_type()> value;
43+
};
44+
}// namespace details
45+
46+
template<
47+
classMap
48+
>
49+
inline
50+
Map &query_map(const uri &uri_, Map &map) {
51+
const uri::string_type range = uri_.query();
52+
details::key_value_sequence<Map> parser;
53+
boost::spirit::qi::parse(boost::begin(range),boost::end(range), parser, map);
54+
return map;
55+
}
56+
57+
inline
58+
uri::string_typeusername(const uri &uri_) {
59+
const uri::string_type user_info = uri_.user_info();
60+
uri::const_iteratorit(boost::begin(user_info)),end(boost::end(user_info));
61+
for (; it != end; ++it) {
62+
if (*it ==':') {
63+
break;
64+
}
65+
}
66+
returnuri::string_type(boost::begin(user_info), it);
67+
}
68+
69+
inline
70+
uri::string_typepassword(const uri &uri_) {
71+
const uri::string_type user_info = uri_.user_info();
72+
uri::const_iteratorit(boost::begin(user_info)),end(boost::end(user_info));
73+
for (; it != end; ++it) {
74+
if (*it ==':') {
75+
++it;
76+
break;
77+
}
78+
}
79+
returnuri::string_type(it,boost::end(user_info));
80+
}
81+
82+
inline
83+
uri::string_typedecoded_path(const uri &uri_) {
84+
const uri::string_type path = uri_.path();
85+
uri::string_type decoded_path;
86+
decode(path,std::back_inserter(decoded_path));
87+
return decoded_path;
88+
}
89+
90+
inline
91+
uri::string_typedecoded_query(const uri &uri_) {
92+
const uri::string_type query = uri_.query();
93+
uri::string_type decoded_query;
94+
decode(query,std::back_inserter(decoded_query));
95+
return decoded_query;
96+
}
97+
98+
inline
99+
uri::string_typedecoded_fragment(const uri &uri_) {
100+
const uri::string_type fragment = uri_.fragment();
101+
uri::string_type decoded_fragment;
102+
decode(fragment,std::back_inserter(decoded_fragment));
103+
return decoded_fragment;
104+
}
105+
}// namespace network
106+
107+
108+
#endif// __BOOST_NETWORK_URI_URI_ACCESSORS_INC__

‎include/network/uri/builder.hpp‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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/asio/ip/address.hpp>
12+
13+
14+
namespacenetwork {
15+
classbuilder {
16+
17+
typedef uri::string_type string_type;
18+
19+
public:
20+
21+
builder(uri &uri_)
22+
: uri_(uri_) {
23+
24+
}
25+
26+
builder &scheme(const string_type &scheme) {
27+
uri_.uri_.append(scheme);
28+
if (opaque_schemes::exists(scheme)) {
29+
uri_.uri_.append(":");
30+
}
31+
else {
32+
uri_.uri_.append("://");
33+
}
34+
uri_.parse();
35+
return *this;
36+
}
37+
38+
builder &user_info(const string_type &user_info) {
39+
uri_.uri_.append(user_info);
40+
uri_.uri_.append("@");
41+
uri_.parse();
42+
return *this;
43+
}
44+
45+
builder &host(const string_type &host) {
46+
uri_.uri_.append(host);
47+
uri_.parse();
48+
return *this;
49+
}
50+
51+
builder &host(const boost::asio::ip::address &host) {
52+
uri_.uri_.append(host.to_string());
53+
uri_.parse();
54+
return *this;
55+
}
56+
57+
builder &host(const boost::asio::ip::address_v4 &host) {
58+
uri_.uri_.append(host.to_string());
59+
uri_.parse();
60+
return *this;
61+
}
62+
63+
builder &host(const boost::asio::ip::address_v6 &host) {
64+
uri_.uri_.append("[");
65+
uri_.uri_.append(host.to_string());
66+
uri_.uri_.append("]");
67+
uri_.parse();
68+
return *this;
69+
}
70+
71+
builder &port(const string_type &port) {
72+
uri_.uri_.append(":");
73+
uri_.uri_.append(port);
74+
uri_.parse();
75+
return *this;
76+
}
77+
78+
builder &port(uint16_t port) {
79+
returnthis->port(boost::lexical_cast<string_type>(port));
80+
}
81+
82+
builder &path(const string_type &path) {
83+
uri_.uri_.append(path);
84+
uri_.parse();
85+
return *this;
86+
}
87+
88+
builder &encoded_path(const string_type &path) {
89+
string_type encoded_path;
90+
encode(path,std::back_inserter(encoded_path));
91+
returnthis->path(encoded_path);
92+
}
93+
94+
builder &query(const string_type &query) {
95+
uri_.uri_.append("?");
96+
uri_.uri_.append(query);
97+
uri_.parse();
98+
return *this;
99+
}
100+
101+
builder &query(const string_type &key,const string_type &value) {
102+
if (!uri_.query_range())
103+
{
104+
uri_.uri_.append("?");
105+
}
106+
else
107+
{
108+
uri_.uri_.append("&");
109+
}
110+
uri_.uri_.append(key);
111+
uri_.uri_.append("=");
112+
uri_.uri_.append(value);
113+
uri_.parse();
114+
return *this;
115+
}
116+
117+
builder &fragment(const string_type &fragment) {
118+
uri_.uri_.append("#");
119+
uri_.uri_.append(fragment);
120+
uri_.parse();
121+
return *this;
122+
}
123+
124+
private:
125+
126+
uri &uri_;
127+
128+
};
129+
}// namespace network
130+
131+
132+
#endif// __BOOST_NETWORK_URI_BUILDER_INC__

‎include/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__

‎include/network/uri/decode.hpp‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) Glyn Matthews 2011, 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_DECODE_INC__
8+
#define__BOOST_NETWORK_URI_DECODE_INC__
9+
10+
11+
#include<boost/iterator/iterator_traits.hpp>
12+
#include<boost/range/begin.hpp>
13+
#include<boost/range/end.hpp>
14+
#include<cassert>
15+
16+
17+
namespacenetwork {
18+
namespacedetail {
19+
template<
20+
typename CharT
21+
>
22+
CharTletter_to_hex(CharT in)
23+
{
24+
switch (in)
25+
{
26+
case'0':
27+
case'1':
28+
case'2':
29+
case'3':
30+
case'4':
31+
case'5':
32+
case'6':
33+
case'7':
34+
case'8':
35+
case'9':
36+
return in -'0';
37+
case'a':
38+
case'b':
39+
case'c':
40+
case'd':
41+
case'e':
42+
case'f':
43+
return in +10 -'a';
44+
case'A':
45+
case'B':
46+
case'C':
47+
case'D':
48+
case'E':
49+
case'F':
50+
return in +10 -'A';
51+
}
52+
returnCharT();
53+
}
54+
}// namespace detail
55+
56+
template<
57+
classInputIterator,
58+
classOutputIterator
59+
>
60+
OutputIteratordecode(const InputIterator &in_begin,
61+
const InputIterator &in_end,
62+
const OutputIterator &out_begin) {
63+
typedeftypename boost::iterator_value<InputIterator>::type value_type;
64+
65+
InputIterator it = in_begin;
66+
OutputIterator out = out_begin;
67+
while (it != in_end) {
68+
if (*it =='%')
69+
{
70+
++it;
71+
value_type v0 =detail::letter_to_hex(*it);
72+
++it;
73+
value_type v1 =detail::letter_to_hex(*it);
74+
++it;
75+
*out++ =0x10 * v0 + v1;
76+
}
77+
else
78+
{
79+
*out++ = *it++;
80+
}
81+
}
82+
return out;
83+
}
84+
85+
template<
86+
classSinglePassRange,
87+
classOutputIterator
88+
>
89+
inline
90+
OutputIteratordecode(const SinglePassRange &range,
91+
const OutputIterator &out) {
92+
returndecode(boost::begin(range),boost::end(range), out);
93+
}
94+
95+
inline
96+
std::stringdecoded(const std::string &input) {
97+
std::string decoded;
98+
decode(input,std::back_inserter(decoded));
99+
return decoded;
100+
}
101+
}// namespace network
102+
103+
104+
#endif// __BOOST_NETWORK_URI_DECODE_INC__

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp