1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/url
//
#include <boost/url.hpp>
#include "test_suite.hpp"
#include <boost/core/ignore_unused.hpp>
#include <iostream>
#include <list>
#include <string>
namespace boost {
namespace urls {
struct doc_3_urls_test
{
static
void
doc_parsing()
{
{
//[code_containers_1_1
system::result< url_view > r = parse_uri( "https://www.example.com/path/to/file.txt" );
//]
ignore_unused(r);
}
{
//[code_containers_1_2
url_view u1 = parse_uri_reference( "wss://example.com/quote.cgi?symbol=BOOST¤cy=USD" ).value();
url_view u2( "wss://example.com/quote.cgi?symbol=BOOST¤cy=USD" );
//]
ignore_unused(u1, u2);
}
}
//[code_container_4_1
auto segs( core::string_view s ) -> std::list< std::string >
{
url_view u( s );
std::list< std::string > seq;
for( auto seg : u.encoded_segments() )
seq.push_back( seg.decode() );
return seq;
}
//]
//[code_container_5_1
auto parms( core::string_view s ) -> std::list< param >
{
url_view u( s );
std::list< param > seq;
for( auto qp : u.params() )
seq.push_back( qp );
return seq;
}
//]
void
path_segments()
{
auto check = [](
core::string_view path,
std::initializer_list<core::string_view> segs,
bool path_abs)
{
auto r1 = parse_path(path);
BOOST_TEST(r1.has_value());
auto ss = r1.value();
BOOST_TEST_EQ(segs.size(), ss.size());
BOOST_TEST_EQ(path_abs, r1->is_absolute());
auto it0 = segs.begin();
auto it1 = ss.begin();
while (it0 != segs.end())
{
BOOST_TEST_EQ(*it0, *it1);
++it0;
++it1;
}
};
check("", { }, false);
check("/", { }, true);
check("./", { "" }, false);
check("./usr", { "usr" }, false);
check("/index.htm", { "index.htm" }, true);
check("/images/cat-pic.gif", { "images", "cat-pic.gif" }, true);
check("images/cat-pic.gif", { "images", "cat-pic.gif" }, false);
check("/fast//query", { "fast", "", "query" }, true);
check("fast//", { "fast", "", "" }, false);
check("/./", { "" }, true);
check(".//", { "", "" }, false);
}
void
run()
{
// segs()
{
url_view u;
segs("http://example.com/path/to/file.txt");
}
path_segments();
}
};
TEST_SUITE(
doc_3_urls_test,
"boost.url.doc.3_urls");
} // urls
} // boost
|