Skip to content

Commit

Permalink
[URI] Added another accessor for the hierarchical part.
Browse files Browse the repository at this point in the history
  • Loading branch information
glynos committed Mar 13, 2012
1 parent c6ea5ff commit 3b9d40f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
25 changes: 8 additions & 17 deletions boost/network/uri/uri.hpp
Expand Up @@ -253,25 +253,16 @@ uri::string_type fragment(const uri &uri_) {
return uri_.fragment();
}

inline
uri::string_type hierarchical_part(const uri &uri_) {
return uri::string_type(boost::begin(uri_.user_info_range()),
boost::end(uri_.path_range()));
}

inline
uri::string_type authority(const uri &uri_) {
uri::string_type port(uri_.port());
uri::string_type authority;
if (uri_.user_info_range())
{
boost::copy(uri_.user_info_range(), std::back_inserter(authority));
authority.push_back('@');
}
if (uri_.host_range())
{
boost::copy(uri_.host(), std::back_inserter(authority));
}
if (uri_.port_range())
{
authority.push_back(':');
boost::copy(uri_.port_range(), std::back_inserter(authority));
}
return authority;
return uri::string_type(boost::begin(uri_.user_info_range()),
boost::end(uri_.port_range()));
}

inline
Expand Down
18 changes: 18 additions & 0 deletions libs/network/test/uri/url_test.cpp
Expand Up @@ -306,12 +306,30 @@ BOOST_AUTO_TEST_CASE(username_test) {
BOOST_CHECK_EQUAL(uri::password(instance), "password");
}

BOOST_AUTO_TEST_CASE(hierarchical_part_test) {
uri::uri instance("http://user:password@www.example.com:80/path?query#fragment");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::hierarchical_part(instance), "user:password@www.example.com:80/path");
}

BOOST_AUTO_TEST_CASE(partial_hierarchical_part_test) {
uri::uri instance("http://www.example.com?query#fragment");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::hierarchical_part(instance), "www.example.com");
}

BOOST_AUTO_TEST_CASE(authority_test) {
uri::uri instance("http://user:password@www.example.com:80/path?query#fragment");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::authority(instance), "user:password@www.example.com:80");
}

BOOST_AUTO_TEST_CASE(partial_authority_test) {
uri::uri instance("http://www.example.com/path?query#fragment");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::authority(instance), "www.example.com");
}

BOOST_AUTO_TEST_CASE(http_query_map_test) {
uri::uri instance("http://user:password@www.example.com:80/path?query=something#fragment");
BOOST_REQUIRE(uri::valid(instance));
Expand Down

0 comments on commit 3b9d40f

Please sign in to comment.