Skip to content

Commit a1242bf

Browse files
committed
Added more URI builder tests.
1 parent c20d1d3 commit a1242bf

File tree

17 files changed

+571
-43
lines changed

17 files changed

+571
-43
lines changed
File renamed without changes.

boost/network/uri/directives.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
# include <boost/network/uri/directives/path.hpp>
1212
# include <boost/network/uri/directives/query.hpp>
1313
# include <boost/network/uri/directives/fragment.hpp>
14-
# include <boost/network/support/is_pod.hpp>
15-
# include <boost/utility/enable_if.hpp>
16-
# include <boost/mpl/if.hpp>
17-
# include <boost/mpl/or.hpp>
1814

1915

2016
namespace boost {

boost/network/uri/directives/authority.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,53 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_AUTHORITY_INC__
33

44

5+
# include <boost/network/support/is_pod.hpp>
6+
# include <boost/utility/enable_if.hpp>
7+
# include <boost/mpl/if.hpp>
8+
# include <boost/mpl/or.hpp>
9+
10+
511
namespace boost {
612
namespace network {
713
namespace uri {
14+
template <
15+
class ValueType
16+
>
17+
struct authority_directive {
18+
19+
explicit authority_directive(const ValueType &value)
20+
: value(value)
21+
{}
22+
23+
template <
24+
class Tag
25+
, template <class> class Uri
26+
>
27+
typename enable_if<is_pod<Tag>, void>::type
28+
operator () (Uri<Tag> &uri) const {
29+
uri.append(value);
30+
}
31+
32+
template <
33+
class Tag
34+
, template <class> class Uri
35+
>
36+
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
37+
operator () (Uri<Tag> &uri) const {
38+
uri.append(value);
39+
}
40+
41+
const ValueType &value;
42+
43+
};
844

45+
template <
46+
class T
47+
>
48+
inline
49+
authority_directive<T> authority(const T &value) {
50+
return authority_directive<T>(value);
51+
}
952
} // namespace uri
1053
} // namespace network
1154
} // namespace boost

boost/network/uri/directives/fragment.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,57 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_FRAGMENT_INC__
33

44

5+
# include <boost/network/support/is_pod.hpp>
6+
# include <boost/utility/enable_if.hpp>
7+
# include <boost/mpl/if.hpp>
8+
# include <boost/mpl/or.hpp>
9+
10+
511
namespace boost {
612
namespace network {
713
namespace uri {
14+
template <
15+
class ValueType
16+
>
17+
struct fragment_directive {
18+
19+
explicit fragment_directive(const ValueType &value)
20+
: value(value)
21+
{}
22+
23+
template <
24+
class Tag
25+
, template <class> class Uri
26+
>
27+
typename enable_if<is_pod<Tag>, void>::type
28+
operator () (Uri<Tag> &uri) const {
29+
static const char separator[] = {'#'};
30+
uri.append(boost::begin(separator), boost::end(separator));
31+
uri.append(value);
32+
}
33+
34+
template <
35+
class Tag
36+
, template <class> class Uri
37+
>
38+
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
39+
operator () (Uri<Tag> &uri) const {
40+
static const char separator[] = {'#'};
41+
uri.append(boost::begin(separator), boost::end(separator));
42+
uri.append(value);
43+
}
44+
45+
const ValueType &value;
46+
47+
};
848

49+
template <
50+
class T
51+
>
52+
inline
53+
fragment_directive<T> fragment(const T &value) {
54+
return fragment_directive<T>(value);
55+
}
956
} // namespace uri
1057
} // namespace network
1158
} // namespace boost

boost/network/uri/directives/host.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_HOST_INC__
33

44

5+
# include <boost/network/support/is_pod.hpp>
6+
# include <boost/utility/enable_if.hpp>
7+
# include <boost/mpl/if.hpp>
8+
# include <boost/mpl/or.hpp>
9+
10+
511
namespace boost {
612
namespace network {
713
namespace uri {

boost/network/uri/directives/path.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_PATH_INC__
33

44

5+
# include <boost/network/uri/encode.hpp>
6+
# include <boost/network/support/is_pod.hpp>
7+
# include <boost/utility/enable_if.hpp>
8+
# include <boost/mpl/if.hpp>
9+
# include <boost/mpl/or.hpp>
10+
11+
512
namespace boost {
613
namespace network {
714
namespace uri {
@@ -20,7 +27,9 @@ struct path_directive {
2027
>
2128
typename enable_if<is_pod<Tag>, void>::type
2229
operator () (Uri<Tag> &uri) const {
23-
uri.append(value);
30+
typename string<Tag>::type encoded_value;
31+
encode(boost::begin(value), boost::end(value), std::back_inserter(encoded_value));
32+
uri.append(encoded_value);
2433
}
2534

2635
template <
@@ -29,7 +38,9 @@ struct path_directive {
2938
>
3039
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
3140
operator () (Uri<Tag> &uri) const {
32-
uri.append(value);
41+
typename string<Tag>::type encoded_value;
42+
encode(boost::begin(value), boost::end(value), std::back_inserter(encoded_value));
43+
uri.append(encoded_value);
3344
}
3445

3546
const ValueType &value;

boost/network/uri/directives/port.hpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,88 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_PORT_INC__
33

44

5+
# include <boost/network/support/is_pod.hpp>
6+
# include <boost/utility/enable_if.hpp>
7+
# include <boost/mpl/if.hpp>
8+
# include <boost/mpl/or.hpp>
9+
# include <boost/type_traits/is_integral.hpp>
10+
# include <boost/cstdint.hpp>
11+
12+
513
namespace boost {
614
namespace network {
715
namespace uri {
16+
template <
17+
class ValueType
18+
>
19+
struct port_directive {
20+
21+
explicit port_directive(const ValueType &value)
22+
: value(value)
23+
{}
24+
25+
template <
26+
class Tag
27+
, template <class> class Uri
28+
>
29+
typename enable_if<is_pod<Tag>, void>::type
30+
operator () (Uri<Tag> &uri) const {
31+
static const char separator[] = {':'};
32+
uri.append(boost::begin(separator), boost::end(separator));
33+
uri.append(value);
34+
}
35+
36+
template <
37+
class Tag
38+
, template <class> class Uri
39+
>
40+
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
41+
operator () (Uri<Tag> &uri) const {
42+
static const char separator[] = {':'};
43+
uri.append(boost::begin(separator), boost::end(separator));
44+
uri.append(value);
45+
}
46+
47+
const ValueType &value;
48+
49+
};
50+
51+
52+
struct port_directive_us {
53+
54+
explicit port_directive_us(boost::uint16_t value)
55+
: value(value)
56+
{}
57+
58+
template <
59+
class Tag
60+
, template <class> class Uri
61+
>
62+
void operator () (Uri<Tag> &uri) const {
63+
static const char separator[] = {':'};
64+
uri.append(boost::begin(separator), boost::end(separator));
65+
typename string<Tag>::type port = boost::lexical_cast<typename string<Tag>::type>(value);
66+
uri.append(port);
67+
}
68+
69+
boost::uint16_t value;
70+
71+
};
72+
73+
74+
template <
75+
class T
76+
>
77+
inline
78+
port_directive<T> port(const T &value,
79+
typename boost::disable_if<typename boost::is_integral<T>::type>::type * = 0) {
80+
return port_directive<T>(value);
81+
}
882

83+
inline
84+
port_directive_us port(boost::uint16_t value) {
85+
return port_directive_us(value);
86+
}
987
} // namespace uri
1088
} // namespace network
1189
} // namespace boost

boost/network/uri/directives/query.hpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,127 @@
22
# define __BOOST_NETWORK_URI_DIRECTIVES_QUERY_INC__
33

44

5+
# include <boost/network/support/is_pod.hpp>
6+
# include <boost/utility/enable_if.hpp>
7+
# include <boost/mpl/if.hpp>
8+
# include <boost/mpl/or.hpp>
9+
10+
511
namespace boost {
612
namespace network {
713
namespace uri {
14+
template <
15+
class ValueType
16+
>
17+
struct query_directive {
18+
19+
explicit query_directive(const ValueType &value)
20+
: value(value)
21+
{}
22+
23+
template <
24+
class Tag
25+
, template <class> class Uri
26+
>
27+
typename enable_if<is_pod<Tag>, void>::type
28+
operator () (Uri<Tag> &uri) const {
29+
static const char separator[] = {'?'};
30+
uri.append(boost::begin(separator), boost::end(separator));
31+
uri.append(value);
32+
}
33+
34+
template <
35+
class Tag
36+
, template <class> class Uri
37+
>
38+
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
39+
operator () (Uri<Tag> &uri) const {
40+
static const char separator[] = {'?'};
41+
uri.append(boost::begin(separator), boost::end(separator));
42+
uri.append(value);
43+
}
44+
45+
const ValueType &value;
46+
47+
};
48+
49+
template <
50+
class T
51+
>
52+
inline
53+
query_directive<T> query(const T &value) {
54+
return query_directive<T>(value);
55+
}
56+
57+
template <
58+
class KeyType
59+
, class ValueType
60+
>
61+
struct query_key_value_directive {
62+
63+
query_key_value_directive(const KeyType &key, const ValueType &value)
64+
: key(key), value(value)
65+
{}
66+
67+
template <
68+
class Tag
69+
, template <class> class Uri
70+
>
71+
typename enable_if<is_pod<Tag>, void>::type
72+
operator () (Uri<Tag> &uri) const {
73+
static const char separator_1[] = {'?'};
74+
static const char separator_2[] = {'='};
75+
static const char separator_3[] = {';'};
76+
if (!uri.query_range())
77+
{
78+
uri.append(boost::begin(separator_1), boost::end(separator_1));
79+
}
80+
else
81+
{
82+
uri.append(boost::begin(separator_3), boost::end(separator_3));
83+
}
84+
uri.append(key);
85+
uri.append(boost::begin(separator_2), boost::end(separator_2));
86+
typename string<Tag>::type encoded_value;
87+
encode(boost::begin(value), boost::end(value), std::back_inserter(encoded_value));
88+
uri.append(encoded_value);
89+
}
90+
91+
template <
92+
class Tag
93+
, template <class> class Uri
94+
>
95+
typename enable_if<mpl::not_<is_pod<Tag> >, void>::type
96+
operator () (Uri<Tag> &uri) const {
97+
static const char separator_1[] = {'?'};
98+
static const char separator_2[] = {'='};
99+
static const char separator_3[] = {';'};
100+
if (!uri.query_range())
101+
{
102+
uri.append(boost::begin(separator_1), boost::end(separator_1));
103+
}
104+
else
105+
{
106+
uri.append(boost::begin(separator_3), boost::end(separator_3));
107+
}
108+
uri.append(key);
109+
uri.append(boost::begin(separator_2), boost::end(separator_2));
110+
uri.append(value);
111+
}
112+
113+
const KeyType &key;
114+
const ValueType &value;
115+
116+
};
8117

118+
template <
119+
class Key
120+
, class Value
121+
>
122+
inline
123+
query_key_value_directive<Key, Value> query(const Key &key, const Value &value) {
124+
return query_key_value_directive<Key, Value>(key, value);
125+
}
9126
} // namespace uri
10127
} // namespace network
11128
} // namespace boost

0 commit comments

Comments
 (0)