Skip to content

Commit 3b9d40f

Browse files
committed
[URI] Added another accessor for the hierarchical part.
1 parent c6ea5ff commit 3b9d40f

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

boost/network/uri/uri.hpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,25 +253,16 @@ uri::string_type fragment(const uri &uri_) {
253253
return uri_.fragment();
254254
}
255255

256+
inline
257+
uri::string_type hierarchical_part(const uri &uri_) {
258+
return uri::string_type(boost::begin(uri_.user_info_range()),
259+
boost::end(uri_.path_range()));
260+
}
261+
256262
inline
257263
uri::string_type authority(const uri &uri_) {
258-
uri::string_type port(uri_.port());
259-
uri::string_type authority;
260-
if (uri_.user_info_range())
261-
{
262-
boost::copy(uri_.user_info_range(), std::back_inserter(authority));
263-
authority.push_back('@');
264-
}
265-
if (uri_.host_range())
266-
{
267-
boost::copy(uri_.host(), std::back_inserter(authority));
268-
}
269-
if (uri_.port_range())
270-
{
271-
authority.push_back(':');
272-
boost::copy(uri_.port_range(), std::back_inserter(authority));
273-
}
274-
return authority;
264+
return uri::string_type(boost::begin(uri_.user_info_range()),
265+
boost::end(uri_.port_range()));
275266
}
276267

277268
inline

libs/network/test/uri/url_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,30 @@ BOOST_AUTO_TEST_CASE(username_test) {
306306
BOOST_CHECK_EQUAL(uri::password(instance), "password");
307307
}
308308

309+
BOOST_AUTO_TEST_CASE(hierarchical_part_test) {
310+
uri::uri instance("http://user:[email protected]:80/path?query#fragment");
311+
BOOST_REQUIRE(uri::valid(instance));
312+
BOOST_CHECK_EQUAL(uri::hierarchical_part(instance), "user:[email protected]:80/path");
313+
}
314+
315+
BOOST_AUTO_TEST_CASE(partial_hierarchical_part_test) {
316+
uri::uri instance("http://www.example.com?query#fragment");
317+
BOOST_REQUIRE(uri::valid(instance));
318+
BOOST_CHECK_EQUAL(uri::hierarchical_part(instance), "www.example.com");
319+
}
320+
309321
BOOST_AUTO_TEST_CASE(authority_test) {
310322
uri::uri instance("http://user:[email protected]:80/path?query#fragment");
311323
BOOST_REQUIRE(uri::valid(instance));
312324
BOOST_CHECK_EQUAL(uri::authority(instance), "user:[email protected]:80");
313325
}
314326

327+
BOOST_AUTO_TEST_CASE(partial_authority_test) {
328+
uri::uri instance("http://www.example.com/path?query#fragment");
329+
BOOST_REQUIRE(uri::valid(instance));
330+
BOOST_CHECK_EQUAL(uri::authority(instance), "www.example.com");
331+
}
332+
315333
BOOST_AUTO_TEST_CASE(http_query_map_test) {
316334
uri::uri instance("http://user:[email protected]:80/path?query=something#fragment");
317335
BOOST_REQUIRE(uri::valid(instance));

0 commit comments

Comments
 (0)