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

Commitb17a4f3

Browse files
committed
Added accessor to fill a map with the key-value pairs in the URI query; added accessors to get the username and password individually; added a class that will eventually become an e-mail address.
1 parent5bc6c29 commitb17a4f3

File tree

6 files changed

+288
-46
lines changed

6 files changed

+288
-46
lines changed

‎boost/network/uri/mailto/uri.hpp‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef __BOOST_NETWORK_URI_MAILTO_URI_INC__
2+
#define__BOOST_NETWORK_URI_MAILTO_URI_INC__
3+
4+
5+
#include<boost/network/uri/uri.hpp>
6+
7+
8+
namespaceboost {
9+
namespacenetwork {
10+
namespaceuri {
11+
namespacemailto {
12+
namespacedetails {
13+
template<
14+
classString
15+
>
16+
structuri_parts
17+
: boost::fusion::vector<
18+
iterator_range<String>// to
19+
// headers
20+
>
21+
{ };
22+
}// namespace details
23+
}// namespace mailto
24+
}// namespace uri
25+
}// namespace network
26+
}// namespace boost
27+
28+
29+
namespaceboost {
30+
namespacenetwork {
31+
namespaceuri {
32+
namespacemailto {
33+
34+
template<
35+
classTag
36+
>
37+
classbasic_uri
38+
: public boost::network::uri::basic_uri<Tag> {
39+
40+
typedef boost::network::uri::basic_uri<Tag> base_type;
41+
42+
public:
43+
44+
basic_uri() {
45+
46+
}
47+
48+
basic_uri(consttypename base_type::string_type &uri) : base_type(uri) {
49+
50+
}
51+
52+
basic_uri &operator = (consttypename base_type::string_type &uri) {
53+
basic_uri(uri).swap(*this);
54+
return *this;
55+
}
56+
57+
58+
59+
};
60+
}// namespace mailto
61+
62+
template<
63+
classTag
64+
>
65+
boolis_mailto(const mailto::basic_uri<Tag> &uri) {
66+
staticconstchar scheme_mailto[] = {'m','a','i','l','t','o'};
67+
returnboost::equal(uri.scheme_range(), scheme_mailto);
68+
}
69+
}// namespace uri
70+
}// namespace network
71+
}// namespace boost
72+
73+
74+
#endif// __BOOST_NETWORK_URI_MAILTO_URI_INC__

‎boost/network/uri/uri.hpp‎

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifdef BOOST_NETWORK_NO_LIB
1616
#include<boost/network/uri/detail/parse_uri.hpp>
1717
#endif// #ifdef BOOST_NETWORK_NO_LIB
18+
#include<boost/fusion/include/std_pair.hpp>
1819
#include<boost/algorithm/string.hpp>
1920
#include<boost/range/iterator_range.hpp>
2021
#include<boost/operators.hpp>
@@ -111,50 +112,26 @@ class basic_uri
111112

112113
const_range_typeuser_info_range()const {
113114
using boost::fusion::at_c;
114-
const boost::fusion::vector<
115-
detail::iterator_range<typename string<Tag>::type>
116-
, detail::iterator_range<typename string<Tag>::type>
117-
, detail::iterator_range<typename string<Tag>::type>
118-
, detail::iterator_range<typename string<Tag>::type> > &hier_part = at_c<1>(uri_parts_);
119-
120-
returnconst_range_type(at_c<0>(at_c<0>(hier_part)),
121-
at_c<1>(at_c<0>(hier_part)));
115+
returnconst_range_type(at_c<0>(at_c<0>(at_c<1>(uri_parts_))),
116+
at_c<1>(at_c<0>(at_c<1>(uri_parts_))));
122117
}
123118

124119
const_range_typehost_range()const {
125120
using boost::fusion::at_c;
126-
const boost::fusion::vector<
127-
detail::iterator_range<typename string<Tag>::type>
128-
, detail::iterator_range<typename string<Tag>::type>
129-
, detail::iterator_range<typename string<Tag>::type>
130-
, detail::iterator_range<typename string<Tag>::type> > &hier_part = at_c<1>(uri_parts_);
131-
132-
returnconst_range_type(at_c<0>(at_c<1>(hier_part)),
133-
at_c<1>(at_c<1>(hier_part)));
121+
returnconst_range_type(at_c<0>(at_c<1>(at_c<1>(uri_parts_))),
122+
at_c<1>(at_c<1>(at_c<1>(uri_parts_))));
134123
}
135124

136125
const_range_typeport_range()const {
137126
using boost::fusion::at_c;
138-
const boost::fusion::vector<
139-
detail::iterator_range<typename string<Tag>::type>
140-
, detail::iterator_range<typename string<Tag>::type>
141-
, detail::iterator_range<typename string<Tag>::type>
142-
, detail::iterator_range<typename string<Tag>::type> > &hier_part = at_c<1>(uri_parts_);
143-
144-
returnconst_range_type(at_c<0>(at_c<2>(hier_part)),
145-
at_c<1>(at_c<2>(hier_part)));
127+
returnconst_range_type(at_c<0>(at_c<2>(at_c<1>(uri_parts_))),
128+
at_c<1>(at_c<2>(at_c<1>(uri_parts_))));
146129
}
147130

148131
const_range_typepath_range()const {
149132
using boost::fusion::at_c;
150-
const boost::fusion::vector<
151-
detail::iterator_range<typename string<Tag>::type>
152-
, detail::iterator_range<typename string<Tag>::type>
153-
, detail::iterator_range<typename string<Tag>::type>
154-
, detail::iterator_range<typename string<Tag>::type> > &hier_part = at_c<1>(uri_parts_);
155-
156-
returnconst_range_type(at_c<0>(at_c<3>(hier_part)),
157-
at_c<1>(at_c<3>(hier_part)));
133+
returnconst_range_type(at_c<0>(at_c<3>(at_c<1>(uri_parts_))),
134+
at_c<1>(at_c<3>(at_c<1>(uri_parts_))));
158135
}
159136

160137
const_range_typequery_range()const {
@@ -208,6 +185,10 @@ class basic_uri
208185
return uri_;
209186
}
210187

188+
string_typeraw()const {
189+
returnto_string();
190+
}
191+
211192
boolis_valid()const {
212193
return is_valid_;
213194
}
@@ -222,10 +203,10 @@ class basic_uri
222203

223204
};
224205

225-
226206
template<
227207
classTag
228208
>
209+
inline
229210
void basic_uri<Tag>::parse() {
230211
const_iterator_typefirst(boost::begin(uri_)),last(boost::end(uri_));
231212
is_valid_ =detail::parse(first, last, uri_parts_);
@@ -301,7 +282,6 @@ struct port_wrapper {
301282
}
302283
};
303284

304-
305285
template<
306286
classTag
307287
>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#ifndef __BOOST_NETWORK_URI_URI_ACCESSORS_INC__
2+
#define__BOOST_NETWORK_URI_URI_ACCESSORS_INC__
3+
4+
5+
#include<boost/network/uri/uri.hpp>
6+
#include<boost/spirit/include/qi.hpp>
7+
8+
9+
namespaceboost {
10+
namespacenetwork {
11+
namespaceuri {
12+
namespacedetails {
13+
template<
14+
typename Uri,
15+
typename Map
16+
>
17+
structkey_value_sequence
18+
: spirit::qi::grammar<typename Uri::const_iterator_type, Map()>
19+
{
20+
typedeftypename Uri::const_iterator_type const_iterator_type;
21+
22+
key_value_sequence()
23+
: key_value_sequence::base_type(query)
24+
{
25+
query = pair >> *((spirit::qi::lit(';') |'&') >> pair);
26+
pair = key >> -('=' >> value);
27+
key =spirit::qi::char_("a-zA-Z_") >> *spirit::qi::char_("a-zA-Z_0-9%");
28+
value = +spirit::qi::char_("a-zA-Z_0-9%");
29+
}
30+
31+
spirit::qi::rule<const_iterator_type, Map()> query;
32+
spirit::qi::rule<const_iterator_type, std::pair<typename Uri::string_type,typename Uri::string_type>()> pair;
33+
spirit::qi::rule<const_iterator_type,typenameUri::string_type()> key, value;
34+
};
35+
}// namespace details
36+
37+
template<
38+
classTag,
39+
classMap
40+
>
41+
inline
42+
Map &query_map(const basic_uri<Tag> &uri, Map &map) {
43+
typename basic_uri<Tag>::const_range_type range = uri.query_range();
44+
details::key_value_sequence<basic_uri<Tag>, Map> parser;
45+
spirit::qi::parse(boost::begin(range),boost::end(range), parser, map);
46+
return map;
47+
}
48+
49+
template<
50+
classTag
51+
>
52+
typename basic_uri<Tag>::string_typeusername(const basic_uri<Tag> &uri) {
53+
typename basic_uri<Tag>::const_range_type user_info_range = uri.user_info_range();
54+
typename basic_uri<Tag>::const_iterator_typeit(boost::begin(user_info_range)),end(boost::end(user_info_range));
55+
for (; it != end; ++it) {
56+
if (*it ==':') {
57+
break;
58+
}
59+
}
60+
returntypename string<Tag>::type(boost::begin(user_info_range), it);
61+
}
62+
63+
template<
64+
classTag
65+
>
66+
typename basic_uri<Tag>::string_typepassword(const basic_uri<Tag> &uri) {
67+
typename basic_uri<Tag>::const_range_type user_info_range = uri.user_info_range();
68+
typename basic_uri<Tag>::const_iterator_typeit(boost::begin(user_info_range)),end(boost::end(user_info_range));
69+
for (; it != end; ++it) {
70+
if (*it ==':') {
71+
++it;
72+
break;
73+
}
74+
}
75+
returntypename string<Tag>::type(it,boost::end(user_info_range));
76+
}
77+
}// namespace uri
78+
}// namespace network
79+
}// namespace boost
80+
81+
82+
#endif// __BOOST_NETWORK_URI_URI_ACCESSORS_INC__

‎libs/network/test/uri/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (Boost_FOUND)
1616
TESTS
1717
url_test
1818
url_http_test
19+
url_mailto_test
1920
)
2021
foreach (test${TESTS})
2122
set_source_files_properties(${test}.cpp
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Glyn Matthews 2011.
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+
#defineBOOST_TEST_MODULE mailto URL Test
8+
#include<boost/config/warning_disable.hpp>
9+
#include<boost/test/unit_test.hpp>
10+
#include<boost/network/uri/mailto/uri.hpp>
11+
#include<boost/mpl/list.hpp>
12+
#include<boost/range/algorithm/equal.hpp>
13+
14+
usingnamespaceboost::network;
15+
16+
typedef boost::mpl::list<
17+
tags::default_string
18+
// , tags::default_wstring
19+
> tag_types;
20+
21+
22+
BOOST_AUTO_TEST_CASE_TEMPLATE(valid_mailto, T, tag_types)
23+
{
24+
typedef uri::mailto::basic_uri<T> uri_type;
25+
typedeftypename uri_type::string_type string_type;
26+
const std::stringurl("mailto:john.doe@example.com");
27+
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
28+
BOOST_REQUIRE(uri::is_mailto(instance));
29+
BOOST_REQUIRE(uri::is_valid(instance));
30+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp