libs/url/doc/modules/ROOT/examples/unit/snippets.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/url | ||
| 8 | // | ||
| 9 | |||
| 10 | #include "test_suite.hpp" | ||
| 11 | |||
| 12 | #include <boost/container/string.hpp> | ||
| 13 | #include <boost/filesystem/path.hpp> | ||
| 14 | #include <boost/core/ignore_unused.hpp> | ||
| 15 | #include <boost/core/detail/string_view.hpp> | ||
| 16 | #include <boost/url/string_view.hpp> | ||
| 17 | #include <boost/url/grammar/string_token.hpp> | ||
| 18 | |||
| 19 | // tag::snippet_headers_1[] | ||
| 20 | #include <boost/url.hpp> | ||
| 21 | // end::snippet_headers_1[] | ||
| 22 | |||
| 23 | #include <algorithm> | ||
| 24 | #include <iostream> | ||
| 25 | #include <sstream> | ||
| 26 | #include <vector> | ||
| 27 | #include <cctype> | ||
| 28 | #include <tuple> | ||
| 29 | #include <initializer_list> | ||
| 30 | #include <string> | ||
| 31 | #include <cstddef> | ||
| 32 | #include <type_traits> | ||
| 33 | #include <iterator> | ||
| 34 | #include <utility> | ||
| 35 | |||
| 36 | // tag::snippet_headers_3[] | ||
| 37 | #include <boost/url.hpp> | ||
| 38 | using namespace boost::urls; | ||
| 39 | // end::snippet_headers_3[] | ||
| 40 | |||
| 41 | #ifdef assert | ||
| 42 | #undef assert | ||
| 43 | #endif | ||
| 44 | #define assert BOOST_TEST | ||
| 45 | |||
| 46 | namespace { | ||
| 47 | |||
| 48 | namespace detail { | ||
| 49 | |||
| 50 | template<class It1, class It2, class Pred1, class Pred2> | ||
| 51 | bool | ||
| 52 | 18 | equal_range_impl( | |
| 53 | It1 first1, | ||
| 54 | It1 last1, | ||
| 55 | It2 first2, | ||
| 56 | It2 last2, | ||
| 57 | Pred1 const& pred1, | ||
| 58 | Pred2 const& pred2) | ||
| 59 | { | ||
| 60 |
35/42bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_base::iterator, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param const&)#1}, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_base::iterator, boost::urls::params_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 2 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_pct_view const&)#1}, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_pct_view const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 2 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, using_url_views()::{lambda(boost::urls::param_pct_view const&)#1}, using_url_views()::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, using_url_views()::{lambda(boost::urls::param_pct_view const&)#1} const&, using_url_views()::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 time.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_base::iterator, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1}, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1}>(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator, char const* const*, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1} const&):
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 2 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(boost::urls::pct_string_view const&)#1}, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(boost::urls::pct_string_view const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1} const&):
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19 times.
✓ Branch 7 taken 9 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#1}, using_url_views()::{lambda(char const*)#1}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#1} const&, using_url_views()::{lambda(char const*)#1} const&):
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 1 time.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#2}, using_url_views()::{lambda(char const*)#2}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#2} const&, using_url_views()::{lambda(char const*)#2} const&):
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 1 time.
|
62 | for (; first1 != last1 && first2 != last2; ++first1, ++first2) |
| 61 | { | ||
| 62 |
26/33bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_base::iterator, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param const&)#1}, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_base::iterator, boost::urls::params_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_pct_view const&)#1}, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_pct_view const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 1 taken 7 times.
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 7 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, using_url_views()::{lambda(boost::urls::param_pct_view const&)#1}, using_url_views()::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, using_url_views()::{lambda(boost::urls::param_pct_view const&)#1} const&, using_url_views()::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_base::iterator, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1}, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1}>(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator, char const* const*, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1} const&):
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(boost::urls::pct_string_view const&)#1}, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(boost::urls::pct_string_view const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1} const&):
✓ Branch 1 taken 19 times.
✓ Branch 5 taken 19 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 19 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#1}, using_url_views()::{lambda(char const*)#1}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#1} const&, using_url_views()::{lambda(char const*)#1} const&):
✓ Branch 1 taken 3 times.
✓ Branch 5 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#2}, using_url_views()::{lambda(char const*)#2}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#2} const&, using_url_views()::{lambda(char const*)#2} const&):
✓ Branch 1 taken 3 times.
✓ Branch 5 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
|
44 | if (pred1(*first1) != pred2(*first2)) |
| 63 | ✗ | return false; | |
| 64 | } | ||
| 65 | |||
| 66 |
14/28bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_base::iterator, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param const&)#1}, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_base::iterator, boost::urls::params_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_pct_view const&)#1}, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_pct_view const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>)::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, using_url_views()::{lambda(boost::urls::param_pct_view const&)#1}, using_url_views()::{lambda(boost::urls::param_view const&)#1}>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, using_url_views()::{lambda(boost::urls::param_pct_view const&)#1} const&, using_url_views()::{lambda(boost::urls::param_view const&)#1} const&):
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_base::iterator, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1}, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1}>(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator, char const* const*, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1} const&):
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(boost::urls::pct_string_view const&)#1}, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(boost::urls::pct_string_view const&)#1} const&, (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>)::{lambda(char const*)#1} const&):
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#1}, using_url_views()::{lambda(char const*)#1}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#1} const&, using_url_views()::{lambda(char const*)#1} const&):
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
bool (anonymous namespace)::detail::equal_range_impl<boost::urls::segments_encoded_base::iterator, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#2}, using_url_views()::{lambda(char const*)#2}>(boost::urls::segments_encoded_base::iterator, boost::urls::segments_encoded_base::iterator, char const* const*, char const* const*, using_url_views()::{lambda(boost::urls::pct_string_view const&)#2} const&, using_url_views()::{lambda(char const*)#2} const&):
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
18 | return first1 == last1 && first2 == last2; |
| 67 | } | ||
| 68 | |||
| 69 | } // detail | ||
| 70 | |||
| 71 | template<class R1, class R2, class Pred1, class Pred2> | ||
| 72 | bool | ||
| 73 | equal_range(R1&& r1, R2&& r2, Pred1 pred1, Pred2 pred2) | ||
| 74 | { | ||
| 75 | using std::begin; | ||
| 76 | using std::end; | ||
| 77 | |||
| 78 | return detail::equal_range_impl( | ||
| 79 | begin(r1), | ||
| 80 | end(r1), | ||
| 81 | begin(r2), | ||
| 82 | end(r2), | ||
| 83 | pred1, | ||
| 84 | pred2); | ||
| 85 | } | ||
| 86 | |||
| 87 | template<class R1, class T, class Pred1, class Pred2> | ||
| 88 | bool | ||
| 89 | 18 | equal_range( | |
| 90 | R1&& r1, | ||
| 91 | std::initializer_list<T> r2, | ||
| 92 | Pred1 pred1, | ||
| 93 | Pred2 pred2) | ||
| 94 | { | ||
| 95 | using std::begin; | ||
| 96 | using std::end; | ||
| 97 | |||
| 98 | 36 | return detail::equal_range_impl( | |
| 99 | begin(r1), | ||
| 100 | end(r1), | ||
| 101 | r2.begin(), | ||
| 102 | r2.end(), | ||
| 103 | pred1, | ||
| 104 | 18 | pred2); | |
| 105 | } | ||
| 106 | |||
| 107 | template<class Range> | ||
| 108 | bool | ||
| 109 | 11 | equal_range( | |
| 110 | Range const& rng, | ||
| 111 | std::initializer_list<const char*> expected) | ||
| 112 | { | ||
| 113 | typedef typename std::decay< | ||
| 114 | decltype(*std::declval<Range const&>().begin())>::type value_type; | ||
| 115 | |||
| 116 | auto project_range = [](value_type const& value) | ||
| 117 | { | ||
| 118 | return std::string(value.begin(), value.end()); | ||
| 119 | }; | ||
| 120 | |||
| 121 | auto project_expected = [](const char* value) | ||
| 122 | { | ||
| 123 | return std::string(value); | ||
| 124 | }; | ||
| 125 | |||
| 126 |
2/2bool (anonymous namespace)::equal_range<boost::urls::segments_encoded_view>(boost::urls::segments_encoded_view const&, std::initializer_list<char const*>):
✓ Branch 1 taken 9 times.
bool (anonymous namespace)::equal_range<boost::urls::segments_view>(boost::urls::segments_view const&, std::initializer_list<char const*>):
✓ Branch 1 taken 2 times.
|
11 | return equal_range( |
| 127 | rng, | ||
| 128 | expected, | ||
| 129 | project_range, | ||
| 130 | 22 | project_expected); | |
| 131 | } | ||
| 132 | |||
| 133 | template<class Range> | ||
| 134 | bool | ||
| 135 | 4 | equal_range( | |
| 136 | Range const& rng, | ||
| 137 | std::initializer_list<param_view> expected) | ||
| 138 | { | ||
| 139 | typedef typename std::decay< | ||
| 140 | decltype(*std::declval<Range const&>().begin())>::type param_type; | ||
| 141 | typedef std::tuple<std::string, bool, std::string> param_tuple; | ||
| 142 | |||
| 143 | auto project_range = [](param_type const& param) | ||
| 144 | { | ||
| 145 | param_tuple result( | ||
| 146 | std::string(param.key.begin(), param.key.end()), | ||
| 147 | param.has_value, | ||
| 148 | std::string()); | ||
| 149 | if (param.has_value) | ||
| 150 | { | ||
| 151 | std::get<2>(result) = | ||
| 152 | std::string(param.value.begin(), param.value.end()); | ||
| 153 | } | ||
| 154 | return result; | ||
| 155 | }; | ||
| 156 | |||
| 157 | auto project_expected = [](param_view const& param) | ||
| 158 | { | ||
| 159 | param_tuple result( | ||
| 160 | std::string(param.key.begin(), param.key.end()), | ||
| 161 | param.has_value, | ||
| 162 | std::string()); | ||
| 163 | if (param.has_value) | ||
| 164 | { | ||
| 165 | std::get<2>(result) = | ||
| 166 | std::string(param.value.begin(), param.value.end()); | ||
| 167 | } | ||
| 168 | return result; | ||
| 169 | }; | ||
| 170 | |||
| 171 |
2/2bool (anonymous namespace)::equal_range<boost::urls::params_encoded_view>(boost::urls::params_encoded_view const&, std::initializer_list<boost::urls::param_view>):
✓ Branch 1 taken 2 times.
bool (anonymous namespace)::equal_range<boost::urls::params_view>(boost::urls::params_view const&, std::initializer_list<boost::urls::param_view>):
✓ Branch 1 taken 2 times.
|
4 | return equal_range( |
| 172 | rng, | ||
| 173 | expected, | ||
| 174 | project_range, | ||
| 175 | 8 | project_expected); | |
| 176 | } | ||
| 177 | |||
| 178 | } // namespace | ||
| 179 | |||
| 180 | |||
| 181 | void | ||
| 182 | 1 | using_url_views() | |
| 183 | { | ||
| 184 | { | ||
| 185 | // tag::snippet_accessing_1[] | ||
| 186 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); |
| 187 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "https"); |
| 188 |
1/1✓ Branch 5 taken 1 time.
|
1 | assert(u.authority().buffer() == "user:pass@example.com:443"); |
| 189 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.userinfo() == "user:pass"); |
| 190 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.user() == "user"); |
| 191 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.password() == "pass"); |
| 192 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "example.com"); |
| 193 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.port() == "443"); |
| 194 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/path/to/my-file.txt"); |
| 195 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.query() == "id=42&name=John Doe+Jingleheimer-Schmidt"); |
| 196 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.fragment() == "page anchor"); |
| 197 | // end::snippet_accessing_1[] | ||
| 198 | } | ||
| 199 | |||
| 200 | // tag::code_urls_parsing_1[] | ||
| 201 | 1 | boost::core::string_view s = "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor"; | |
| 202 | // end::code_urls_parsing_1[] | ||
| 203 | |||
| 204 | { | ||
| 205 | // tag::code_urls_parsing_2[] | ||
| 206 |
1/1✓ Branch 1 taken 1 time.
|
1 | boost::system::result<url_view> r = parse_uri( s ); |
| 207 | // end::code_urls_parsing_2[] | ||
| 208 | // tag::snippet_parsing_3[] | ||
| 209 |
1/1✓ Branch 2 taken 1 time.
|
1 | url_view u = r.value(); |
| 210 | // end::snippet_parsing_3[] | ||
| 211 | boost::ignore_unused(u); | ||
| 212 | } | ||
| 213 | |||
| 214 | { | ||
| 215 |
1/1✓ Branch 1 taken 1 time.
|
1 | boost::system::result<url_view> r = parse_uri( s ); |
| 216 | // tag::snippet_parsing_4[] | ||
| 217 | 1 | url_view u = *r; | |
| 218 | // end::snippet_parsing_4[] | ||
| 219 | boost::ignore_unused(u); | ||
| 220 | } | ||
| 221 | |||
| 222 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( s ); |
| 223 | // tag::snippet_accessing_1b[] | ||
| 224 |
3/3✓ Branch 4 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 1 time.
|
4 | for (auto seg: u.segments()) |
| 225 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << seg << "\n"; |
| 226 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << "\n"; |
| 227 | |||
| 228 |
3/3✓ Branch 4 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1 time.
|
3 | for (auto param: u.params()) |
| 229 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | std::cout << param.key << ": " << param.value << "\n"; |
| 230 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << "\n"; |
| 231 | // end::snippet_accessing_1b[] | ||
| 232 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(equal_range(u.segments(), {"path", "to", "my-file.txt"})); |
| 233 | 1 | auto params = u.params(); | |
| 234 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 235 | params, | ||
| 236 | { | ||
| 237 | param_view{"id", "42", true}, | ||
| 238 | param_view{"name", "John Doe Jingleheimer-Schmidt", true} | ||
| 239 | })); | ||
| 240 | |||
| 241 | { | ||
| 242 | // tag::snippet_token_1[] | ||
| 243 |
1/1✓ Branch 2 taken 1 time.
|
1 | std::string h = u.host(); |
| 244 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(h == "example.com"); |
| 245 | // end::snippet_token_1[] | ||
| 246 | boost::ignore_unused(h); | ||
| 247 | 1 | } | |
| 248 | |||
| 249 | { | ||
| 250 | // tag::snippet_token_2[] | ||
| 251 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string h = "host: "; |
| 252 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.host(string_token::append_to(h)); |
| 253 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(h == "host: example.com"); |
| 254 | // end::snippet_token_2[] | ||
| 255 | boost::ignore_unused(h); | ||
| 256 | 1 | } | |
| 257 | |||
| 258 | { | ||
| 259 | // tag::snippet_accessing_2a[] | ||
| 260 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u1 = parse_uri( "http://www.example.com" ).value(); |
| 261 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u1.fragment().empty()); |
| 262 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u1.has_fragment()); |
| 263 | // end::snippet_accessing_2a[] | ||
| 264 | boost::ignore_unused(u1); | ||
| 265 | } | ||
| 266 | |||
| 267 | { | ||
| 268 | // tag::snippet_accessing_2b[] | ||
| 269 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u2 = parse_uri( "http://www.example.com/#" ).value(); |
| 270 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u2.fragment().empty()); |
| 271 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u2.has_fragment()); |
| 272 | // end::snippet_accessing_2b[] | ||
| 273 | } | ||
| 274 | |||
| 275 | { | ||
| 276 | // tag::snippet_accessing_3a[] | ||
| 277 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u1 = parse_uri( "http://www.example.com" ).value(); |
| 278 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | std::cout << "has fragment 1 : " << u1.has_fragment() << "\n"; |
| 279 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | std::cout << "fragment 1 : " << u1.fragment() << "\n\n"; |
| 280 | // end::snippet_accessing_3a[] | ||
| 281 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u1.has_fragment()); |
| 282 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u1.fragment().empty()); |
| 283 | |||
| 284 | // tag::snippet_accessing_3b[] | ||
| 285 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u2 = parse_uri( "http://www.example.com/#" ).value(); |
| 286 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | std::cout << "has fragment 2 : " << u2.has_fragment() << "\n"; |
| 287 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | std::cout << "fragment 2 : " << u2.fragment() << "\n\n"; |
| 288 | // end::snippet_accessing_3b[] | ||
| 289 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u2.has_fragment()); |
| 290 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u2.fragment().empty()); |
| 291 | } | ||
| 292 | |||
| 293 | { | ||
| 294 | // tag::snippet_accessing_4[] | ||
| 295 | std::cout << | ||
| 296 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | "url : " << u << "\n" |
| 297 | "scheme : " << u.scheme() << "\n" | ||
| 298 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "authority : " << u.encoded_authority() << "\n" |
| 299 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "userinfo : " << u.encoded_userinfo() << "\n" |
| 300 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "user : " << u.encoded_user() << "\n" |
| 301 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "password : " << u.encoded_password() << "\n" |
| 302 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "host : " << u.encoded_host() << "\n" |
| 303 | "port : " << u.port() << "\n" | ||
| 304 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "path : " << u.encoded_path() << "\n" |
| 305 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "query : " << u.encoded_query() << "\n" |
| 306 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | "fragment : " << u.encoded_fragment() << "\n"; |
| 307 | // end::snippet_accessing_4[] | ||
| 308 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "https"); |
| 309 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_authority() == "user:pass@example.com:443"); |
| 310 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_userinfo() == "user:pass"); |
| 311 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_user() == "user"); |
| 312 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_password() == "pass"); |
| 313 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_host() == "example.com"); |
| 314 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.port() == "443"); |
| 315 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_path() == "/path/to/my%2dfile.txt"); |
| 316 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_query() == "id=42&name=John%20Doe+Jingleheimer%2DSchmidt"); |
| 317 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_fragment() == "page%20anchor"); |
| 318 | } | ||
| 319 | |||
| 320 | { | ||
| 321 | // tag::snippet_decoding_1[] | ||
| 322 |
1/1✓ Branch 2 taken 1 time.
|
1 | decode_view dv("id=42&name=John%20Doe%20Jingleheimer%2DSchmidt"); |
| 323 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << dv << "\n"; |
| 324 | // end::snippet_decoding_1[] | ||
| 325 |
2/3✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(dv == "id=42&name=John Doe Jingleheimer-Schmidt"); |
| 326 | } | ||
| 327 | { | ||
| 328 |
1/1✓ Branch 1 taken 1 time.
|
1 | url u1 = u; |
| 329 |
1/1✓ Branch 1 taken 1 time.
|
1 | url u2 = u; |
| 330 | // tag::snippet_decoding_2[] | ||
| 331 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | u1.set_host(u2.host()); |
| 332 | // end::snippet_decoding_2[] | ||
| 333 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << u1 << "\n"; |
| 334 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u1.buffer() == u.buffer()); |
| 335 | 1 | } | |
| 336 | { | ||
| 337 | // tag::snippet_decoding_3[] | ||
| 338 | 1 | boost::filesystem::path p; | |
| 339 |
3/3✓ Branch 4 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 1 time.
|
4 | for (auto seg: u.segments()) |
| 340 | 6 | p.append(seg.begin(), seg.end()); | |
| 341 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | std::cout << "path: " << p << "\n"; |
| 342 | // end::snippet_decoding_3[] | ||
| 343 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(p.generic_string() == "path/to/my-file.txt"); |
| 344 | 1 | } | |
| 345 | // transparent std::equal_to<> required | ||
| 346 | #if BOOST_CXX_VERSION >= 201402L && !defined(BOOST_CLANG) | ||
| 347 | { | ||
| 348 | auto handle_route = []( | ||
| 349 | std::vector<std::string> const&, | ||
| 350 | url_view) | ||
| 351 | {}; | ||
| 352 | |||
| 353 | // tag::snippet_decoding_4a[] | ||
| 354 | auto match = []( | ||
| 355 | std::vector<std::string> const& route, | ||
| 356 | url_view u) | ||
| 357 | { | ||
| 358 | auto segs = u.segments(); | ||
| 359 | if (route.size() != segs.size()) | ||
| 360 | return false; | ||
| 361 | return std::equal( | ||
| 362 | route.begin(), | ||
| 363 | route.end(), | ||
| 364 | segs.begin()); | ||
| 365 | }; | ||
| 366 | // end::snippet_decoding_4a[] | ||
| 367 | // tag::snippet_decoding_4b[] | ||
| 368 | std::vector<std::string> route = | ||
| 369 | {"community", "reviews.html"}; | ||
| 370 | if (match(route, u)) | ||
| 371 | { | ||
| 372 | handle_route(route, u); | ||
| 373 | } | ||
| 374 | // end::snippet_decoding_4b[] | ||
| 375 | } | ||
| 376 | #endif | ||
| 377 | { | ||
| 378 | // tag::snippet_compound_elements_0[] | ||
| 379 | 1 | segments_encoded_view segs_encoded = u.encoded_segments(); | |
| 380 | |||
| 381 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for( auto v : segs_encoded ) |
| 382 | { | ||
| 383 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << v << "\n"; |
| 384 | } | ||
| 385 | // end::snippet_compound_elements_0[] | ||
| 386 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 387 | segs_encoded, | ||
| 388 | {"path", "to", "my%2dfile.txt"})); | ||
| 389 | } | ||
| 390 | |||
| 391 | { | ||
| 392 | // tag::snippet_compound_elements_0b[] | ||
| 393 | 1 | segments_encoded_view segs_encoded = u.encoded_segments(); | |
| 394 | |||
| 395 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for( pct_string_view v : segs_encoded ) |
| 396 | { | ||
| 397 | 3 | decode_view dv = *v; | |
| 398 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << dv << "\n"; |
| 399 | } | ||
| 400 | // end::snippet_compound_elements_0b[] | ||
| 401 | 3 | auto decode_segment = [](pct_string_view const& value) | |
| 402 | { | ||
| 403 | 3 | decode_view dv = *value; | |
| 404 |
1/1✓ Branch 3 taken 3 times.
|
6 | return std::string(dv.begin(), dv.end()); |
| 405 | }; | ||
| 406 | 3 | auto literal = [](const char* value) | |
| 407 | { | ||
| 408 |
1/1✓ Branch 1 taken 3 times.
|
6 | return std::string(value); |
| 409 | }; | ||
| 410 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 411 | segs_encoded, | ||
| 412 | {"path", "to", "my-file.txt"}, | ||
| 413 | decode_segment, | ||
| 414 | literal)); | ||
| 415 | } | ||
| 416 | |||
| 417 | { | ||
| 418 | // tag::snippet_compound_elements_1[] | ||
| 419 | 1 | segments_encoded_view segs_encoded = u.encoded_segments(); | |
| 420 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for( auto v : segs_encoded ) |
| 421 | { | ||
| 422 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << v << "\n"; |
| 423 | } | ||
| 424 | // end::snippet_compound_elements_1[] | ||
| 425 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 426 | segs_encoded, | ||
| 427 | {"path", "to", "my%2dfile.txt"})); | ||
| 428 | } | ||
| 429 | |||
| 430 | { | ||
| 431 | // tag::snippet_encoded_compound_elements_1[] | ||
| 432 | 1 | segments_encoded_view segs_encoded = u.encoded_segments(); | |
| 433 | |||
| 434 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for( pct_string_view v : segs_encoded ) |
| 435 | { | ||
| 436 | 3 | decode_view dv = *v; | |
| 437 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << dv << "\n"; |
| 438 | } | ||
| 439 | // end::snippet_encoded_compound_elements_1[] | ||
| 440 | 3 | auto decode_segment = [](pct_string_view const& value) | |
| 441 | { | ||
| 442 | 3 | decode_view dv = *value; | |
| 443 |
1/1✓ Branch 3 taken 3 times.
|
6 | return std::string(dv.begin(), dv.end()); |
| 444 | }; | ||
| 445 | 3 | auto literal = [](const char* value) | |
| 446 | { | ||
| 447 |
1/1✓ Branch 1 taken 3 times.
|
6 | return std::string(value); |
| 448 | }; | ||
| 449 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 450 | segs_encoded, | ||
| 451 | {"path", "to", "my-file.txt"}, | ||
| 452 | decode_segment, | ||
| 453 | literal)); | ||
| 454 | } | ||
| 455 | |||
| 456 | { | ||
| 457 | // tag::snippet_encoded_compound_elements_2[] | ||
| 458 | 1 | params_encoded_view params_ref_view = u.encoded_params(); | |
| 459 | |||
| 460 |
2/2✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 time.
|
3 | for( auto v : params_ref_view ) |
| 461 | { | ||
| 462 | 2 | decode_view dk(v.key); | |
| 463 | 2 | decode_view dv(v.value); | |
| 464 | |||
| 465 | std::cout << | ||
| 466 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | "key = " << dk << |
| 467 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | ", value = " << dv << "\n"; |
| 468 | } | ||
| 469 | // end::snippet_encoded_compound_elements_2[] | ||
| 470 | 2 | auto decode_param = [](param_pct_view const& param) | |
| 471 | { | ||
| 472 | 2 | decode_view dk(param.key); | |
| 473 | std::tuple<std::string, bool, std::string> result( | ||
| 474 |
1/1✓ Branch 3 taken 2 times.
|
4 | std::string(dk.begin(), dk.end()), |
| 475 | 2 | param.has_value, | |
| 476 | 6 | std::string()); | |
| 477 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (param.has_value) |
| 478 | { | ||
| 479 | 2 | decode_view dv(param.value); | |
| 480 | 2 | std::get<2>(result) = | |
| 481 |
1/1✓ Branch 3 taken 2 times.
|
6 | std::string(dv.begin(), dv.end()); |
| 482 | } | ||
| 483 | 4 | return result; | |
| 484 | ✗ | }; | |
| 485 | 2 | auto expect_param_tuple = [](param_view const& param) | |
| 486 | { | ||
| 487 | std::tuple<std::string, bool, std::string> result( | ||
| 488 |
1/1✓ Branch 3 taken 2 times.
|
4 | std::string(param.key.begin(), param.key.end()), |
| 489 | 2 | param.has_value, | |
| 490 | 6 | std::string()); | |
| 491 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (param.has_value) |
| 492 | { | ||
| 493 | 2 | std::get<2>(result) = | |
| 494 |
1/1✓ Branch 3 taken 2 times.
|
6 | std::string(param.value.begin(), param.value.end()); |
| 495 | } | ||
| 496 | 2 | return result; | |
| 497 | ✗ | }; | |
| 498 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 499 | params_ref_view, | ||
| 500 | { | ||
| 501 | param_view{"id", "42", true}, | ||
| 502 | param_view{"name", "John Doe+Jingleheimer-Schmidt", true} | ||
| 503 | }, | ||
| 504 | decode_param, | ||
| 505 | expect_param_tuple)); | ||
| 506 | } | ||
| 507 | 1 | } | |
| 508 | |||
| 509 | void | ||
| 510 | 1 | using_urls() | |
| 511 | { | ||
| 512 | 1 | boost::core::string_view s = "https://user:pass@www.example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe#page%20anchor"; | |
| 513 | |||
| 514 | // tag::snippet_quicklook_modifying_1[] | ||
| 515 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | url u = parse_uri( s ).value(); |
| 516 | // end::snippet_quicklook_modifying_1[] | ||
| 517 | |||
| 518 | // tag::snippet_quicklook_modifying_1b[] | ||
| 519 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | static_url<1024> su = parse_uri( s ).value(); |
| 520 | // end::snippet_quicklook_modifying_1b[] | ||
| 521 | (void)su; | ||
| 522 | |||
| 523 | // tag::snippet_quicklook_modifying_2[] | ||
| 524 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.set_scheme( "https" ); |
| 525 | // end::snippet_quicklook_modifying_2[] | ||
| 526 | |||
| 527 | // tag::snippet_quicklook_modifying_3[] | ||
| 528 |
1/1✓ Branch 1 taken 1 time.
|
1 | u.set_scheme_id( scheme::https ); // equivalent to u.set_scheme( "https" ); |
| 529 | // end::snippet_quicklook_modifying_3[] | ||
| 530 | |||
| 531 | // tag::snippet_quicklook_modifying_4[] | ||
| 532 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | u.set_host_ipv4( ipv4_address( "192.168.0.1" ) ) |
| 533 |
1/1✓ Branch 1 taken 1 time.
|
1 | .set_port_number( 8080 ) |
| 534 | 1 | .remove_userinfo(); | |
| 535 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << u << "\n"; |
| 536 | // end::snippet_quicklook_modifying_4[] | ||
| 537 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.buffer() == "https://192.168.0.1:8080/path/to/my%2dfile.txt?id=42&name=John%20Doe#page%20anchor"); |
| 538 | |||
| 539 | // tag::snippet_quicklook_modifying_5[] | ||
| 540 | 1 | params_ref p = u.params(); | |
| 541 |
1/1✓ Branch 6 taken 1 time.
|
1 | p.replace(p.find("name"), {"name", "John Doe"}); |
| 542 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << u << "\n"; |
| 543 | // end::snippet_quicklook_modifying_5[] | ||
| 544 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.buffer() == "https://192.168.0.1:8080/path/to/my%2dfile.txt?id=42&name=John+Doe#page%20anchor"); |
| 545 | 1 | } | |
| 546 | |||
| 547 | void | ||
| 548 | 1 | parsing_urls() | |
| 549 | { | ||
| 550 | { | ||
| 551 | ✗ | auto handle_error = [](boost::system::error_code e) | |
| 552 | { | ||
| 553 | boost::ignore_unused(e); | ||
| 554 | ✗ | }; | |
| 555 | // tag::snippet_parsing_url_1[] | ||
| 556 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | boost::system::result< url > ru = parse_uri_reference( "https://www.example.com/path/to/file.txt" ); |
| 557 |
1/2✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
|
1 | if ( ru ) |
| 558 | { | ||
| 559 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = *ru; |
| 560 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(u.encoded_path() == "/path/to/file.txt"); |
| 561 | 1 | } | |
| 562 | else | ||
| 563 | { | ||
| 564 | ✗ | boost::system::error_code e = ru.error(); | |
| 565 | ✗ | handle_error(e); | |
| 566 | } | ||
| 567 | // end::snippet_parsing_url_1[] | ||
| 568 | 1 | } | |
| 569 | |||
| 570 | { | ||
| 571 | ✗ | auto handle_error = [](boost::system::system_error& e) | |
| 572 | { | ||
| 573 | boost::ignore_unused(e); | ||
| 574 | ✗ | }; | |
| 575 | // tag::snippet_parsing_url_1b[] | ||
| 576 | try | ||
| 577 | { | ||
| 578 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri_reference( "https://www.example.com/path/to/file.txt" ).value(); |
| 579 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(u.encoded_path() == "/path/to/file.txt"); |
| 580 | 1 | } | |
| 581 | ✗ | catch (boost::system::system_error &e) | |
| 582 | { | ||
| 583 | ✗ | handle_error(e); | |
| 584 | ✗ | } | |
| 585 | // end::snippet_parsing_url_1b[] | ||
| 586 | } | ||
| 587 | |||
| 588 | { | ||
| 589 | // tag::snippet_parsing_url_1b2[] | ||
| 590 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | boost::system::result< url > ru = parse_uri_reference( "https://www.example.com/path/to/file.txt" ); |
| 591 |
1/2✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
|
1 | if ( ru.has_value() ) |
| 592 | { | ||
| 593 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = *ru; |
| 594 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(u.encoded_path() == "/path/to/file.txt"); |
| 595 | 1 | } | |
| 596 | // end::snippet_parsing_url_1b2[] | ||
| 597 | boost::ignore_unused(ru); | ||
| 598 | 1 | } | |
| 599 | |||
| 600 | { | ||
| 601 | // tag::snippet_parsing_url_1bb[] | ||
| 602 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri_reference( "https://www.example.com/path/to/file.txt" ).value(); |
| 603 | |||
| 604 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(u.encoded_path() == "/path/to/file.txt"); |
| 605 | // end::snippet_parsing_url_1bb[] | ||
| 606 | boost::ignore_unused(u); | ||
| 607 | 1 | } | |
| 608 | |||
| 609 | { | ||
| 610 | // tag::snippet_parsing_url_1bc[] | ||
| 611 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | boost::system::result< url > rv = parse_uri_reference( "https://www.example.com/path/to/file.txt" ); |
| 612 | |||
| 613 | static_assert( std::is_convertible< boost::system::result< url_view >, boost::system::result< url > >::value, "" ); | ||
| 614 | // end::snippet_parsing_url_1bc[] | ||
| 615 | boost::ignore_unused(rv); | ||
| 616 | 1 | } | |
| 617 | |||
| 618 | { | ||
| 619 | // tag::snippet_parsing_url_1bd[] | ||
| 620 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | boost::system::result< static_url<1024> > rv = parse_uri_reference( "https://www.example.com/path/to/file.txt" ); |
| 621 | |||
| 622 | static_assert( std::is_convertible< boost::system::result< static_url<1024> >, boost::system::result< url > >::value, "" ); | ||
| 623 | // end::snippet_parsing_url_1bd[] | ||
| 624 | boost::ignore_unused(rv); | ||
| 625 | 1 | } | |
| 626 | |||
| 627 | { | ||
| 628 | // tag::snippet_parsing_url_1c[] | ||
| 629 |
1/1✓ Branch 2 taken 1 time.
|
1 | boost::system::result< url_view > r0 = parse_relative_ref( "/path/to/file.txt" ); |
| 630 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert( r0.has_value() ); |
| 631 | // end::snippet_parsing_url_1c[] | ||
| 632 | // tag::snippet_parsing_url_1d[] | ||
| 633 |
1/1✓ Branch 2 taken 1 time.
|
1 | boost::system::result< url_view > r1 = parse_uri( "https://www.example.com" ); |
| 634 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert( r1.has_value() ); |
| 635 | 1 | url dest; | |
| 636 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | resolve(r1.value(), r0.value(), dest); |
| 637 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(dest.buffer() == "https://www.example.com/path/to/file.txt"); |
| 638 | // end::snippet_parsing_url_1d[] | ||
| 639 | boost::ignore_unused(dest); | ||
| 640 | 1 | } | |
| 641 | |||
| 642 | // tag::snippet_parsing_url_2[] | ||
| 643 | // This will hold our copy | ||
| 644 | 1 | std::shared_ptr<url_view const> sp; | |
| 645 | { | ||
| 646 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string s = "/path/to/file.txt"; |
| 647 | |||
| 648 | // result::value() will throw an exception if an error occurs | ||
| 649 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u = parse_relative_ref( s ).value(); |
| 650 | |||
| 651 | // create a copy with ownership and string lifetime extension | ||
| 652 |
1/1✓ Branch 1 taken 1 time.
|
1 | sp = u.persist(); |
| 653 | |||
| 654 | // At this point the string goes out of scope | ||
| 655 | 1 | } | |
| 656 | |||
| 657 | // but `*sp` remains valid since it has its own copy | ||
| 658 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | std::cout << *sp << "\n"; |
| 659 | // end::snippet_parsing_url_2[] | ||
| 660 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(sp); |
| 661 |
1/1✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(sp->buffer() == "/path/to/file.txt"); |
| 662 | |||
| 663 | { | ||
| 664 | // tag::snippet_parsing_url_3[] | ||
| 665 | // This will hold our mutable copy | ||
| 666 | 1 | url v; | |
| 667 | { | ||
| 668 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string s = "/path/to/file.txt"; |
| 669 | |||
| 670 | // result::value() will throw an exception if an error occurs | ||
| 671 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | v = parse_relative_ref(s).value(); |
| 672 | |||
| 673 | // At this point the string goes out of scope | ||
| 674 | 1 | } | |
| 675 | |||
| 676 | // but `v` remains valid since it has its own copy | ||
| 677 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << v << "\n"; |
| 678 | |||
| 679 | // and it's mutable | ||
| 680 |
1/1✓ Branch 2 taken 1 time.
|
1 | v.set_fragment("anchor"); |
| 681 | |||
| 682 | // path/to/file.txt#anchor | ||
| 683 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << v << "\n"; |
| 684 | // end::snippet_parsing_url_3[] | ||
| 685 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(v.buffer() == "/path/to/file.txt#anchor"); |
| 686 | 1 | } | |
| 687 | 1 | } | |
| 688 | |||
| 689 | void | ||
| 690 | 1 | parsing_components() | |
| 691 | { | ||
| 692 | { | ||
| 693 | // tag::snippet_components_2a[] | ||
| 694 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.ietf.org/rfc/rfc2396.txt" ); |
| 695 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "https"); |
| 696 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "www.ietf.org"); |
| 697 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/rfc/rfc2396.txt"); |
| 698 | // end::snippet_components_2a[] | ||
| 699 | } | ||
| 700 | { | ||
| 701 | // tag::snippet_components_2b[] | ||
| 702 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "ftp://ftp.is.co.za/rfc/rfc1808.txt" ); |
| 703 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "ftp"); |
| 704 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "ftp.is.co.za"); |
| 705 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/rfc/rfc1808.txt"); |
| 706 | // end::snippet_components_2b[] | ||
| 707 | } | ||
| 708 | { | ||
| 709 | // tag::snippet_components_2c[] | ||
| 710 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "mailto:John.Doe@example.com" ); |
| 711 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "mailto"); |
| 712 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "John.Doe@example.com"); |
| 713 | // end::snippet_components_2c[] | ||
| 714 | } | ||
| 715 | { | ||
| 716 | // tag::snippet_components_2d[] | ||
| 717 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "urn:isbn:096139210x" ); |
| 718 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "urn"); |
| 719 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "isbn:096139210x"); |
| 720 | // end::snippet_components_2d[] | ||
| 721 | } | ||
| 722 | { | ||
| 723 | // tag::snippet_components_2e[] | ||
| 724 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36" ); |
| 725 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "magnet"); |
| 726 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == ""); |
| 727 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.query() == "xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36"); |
| 728 | // end::snippet_components_2e[] | ||
| 729 | } | ||
| 730 | 1 | } | |
| 731 | |||
| 732 | void | ||
| 733 | 1 | formatting_components() | |
| 734 | { | ||
| 735 | // I have spent a lot of time on this and have no | ||
| 736 | // idea how to fix this bug in GCC 4.8 and GCC 5.0 | ||
| 737 | // without help from the pros. | ||
| 738 | #if !BOOST_WORKAROUND( BOOST_GCC_VERSION, < 60000 ) | ||
| 739 | { | ||
| 740 | // tag::snippet_format_1[] | ||
| 741 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{}://{}:{}/rfc/{}", "https", "www.ietf.org", 80, "rfc2396.txt"); |
| 742 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.ietf.org:80/rfc/rfc2396.txt"); |
| 743 | // end::snippet_format_1[] | ||
| 744 | 1 | } | |
| 745 | |||
| 746 | { | ||
| 747 | // tag::snippet_format_2[] | ||
| 748 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("https://{}/{}", "www.boost.org", "Hello world!"); |
| 749 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.boost.org/Hello%20world!"); |
| 750 | // end::snippet_format_2[] | ||
| 751 | 1 | } | |
| 752 | |||
| 753 | { | ||
| 754 | // tag::snippet_format_3a[] | ||
| 755 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{}:{}", "mailto", "someone@example.com"); |
| 756 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "mailto:someone@example.com"); |
| 757 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "mailto"); |
| 758 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "someone@example.com"); |
| 759 | // end::snippet_format_3a[] | ||
| 760 | 1 | } | |
| 761 | { | ||
| 762 | // tag::snippet_format_3b[] | ||
| 763 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{}{}", "mailto:", "someone@example.com"); |
| 764 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "mailto%3Asomeone@example.com"); |
| 765 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u.has_scheme()); |
| 766 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "mailto:someone@example.com"); |
| 767 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(u.encoded_path() == "mailto%3Asomeone@example.com"); |
| 768 | // end::snippet_format_3b[] | ||
| 769 | 1 | } | |
| 770 | |||
| 771 | { | ||
| 772 | // tag::snippet_format_4[] | ||
| 773 | 1 | static_url<50> u; | |
| 774 |
1/1✓ Branch 2 taken 1 time.
|
1 | format_to(u, "{}://{}:{}/rfc/{}", "https", "www.ietf.org", 80, "rfc2396.txt"); |
| 775 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.ietf.org:80/rfc/rfc2396.txt"); |
| 776 | // end::snippet_format_4[] | ||
| 777 | 1 | } | |
| 778 | |||
| 779 | { | ||
| 780 | // tag::snippet_format_5a[] | ||
| 781 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{0}://{2}:{1}/{3}{4}{3}", "https", 80, "www.ietf.org", "abra", "cad"); |
| 782 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.ietf.org:80/abracadabra"); |
| 783 | // end::snippet_format_5a[] | ||
| 784 | 1 | } | |
| 785 | { | ||
| 786 | // tag::snippet_format_5b[] | ||
| 787 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url u = format("https://example.com/~{username}", arg("username", "mark")); |
| 788 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://example.com/~mark"); |
| 789 | // end::snippet_format_5b[] | ||
| 790 | 1 | } | |
| 791 | |||
| 792 | { | ||
| 793 | // tag::snippet_format_5c[] | ||
| 794 | 1 | boost::core::string_view fmt = "{scheme}://{host}:{port}/{dir}/{file}"; | |
| 795 |
6/6✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 18 taken 1 time.
✓ Branch 21 taken 1 time.
|
1 | url u = format(fmt, {{"scheme", "https"}, {"port", 80}, {"host", "example.com"}, {"dir", "path/to"}, {"file", "file.txt"}}); |
| 796 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://example.com:80/path/to/file.txt"); |
| 797 | // end::snippet_format_5c[] | ||
| 798 | 1 | } | |
| 799 | #endif | ||
| 800 | 1 | } | |
| 801 | |||
| 802 | void | ||
| 803 | 1 | parsing_scheme() | |
| 804 | { | ||
| 805 | { | ||
| 806 | // tag::snippet_parsing_scheme_1[] | ||
| 807 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("mailto:name@email.com" ); |
| 808 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert( u.has_scheme() ); |
| 809 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert( u.scheme() == "mailto" ); |
| 810 | // end::snippet_parsing_scheme_1[] | ||
| 811 | boost::ignore_unused(u); | ||
| 812 | } | ||
| 813 | { | ||
| 814 | // tag::snippet_parsing_scheme_3[] | ||
| 815 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("file://host/path/to/file" ); |
| 816 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert( u.scheme_id() == scheme::file ); |
| 817 | // end::snippet_parsing_scheme_3[] | ||
| 818 | boost::ignore_unused(u); | ||
| 819 | } | ||
| 820 | 1 | } | |
| 821 | |||
| 822 | void | ||
| 823 | 1 | parsing_authority() | |
| 824 | { | ||
| 825 | { | ||
| 826 | // tag::snippet_parsing_authority_1[] | ||
| 827 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https:///path/to_resource" ); |
| 828 |
1/1✓ Branch 5 taken 1 time.
|
1 | assert( u.authority().buffer() == ""); |
| 829 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert( u.has_authority() ); |
| 830 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.path() == "/path/to_resource" ); |
| 831 | // end::snippet_parsing_authority_1[] | ||
| 832 | } | ||
| 833 | { | ||
| 834 | // tag::snippet_parsing_authority_2[] | ||
| 835 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org" ); |
| 836 | std::cout << "scheme: " << u.scheme() << "\n" | ||
| 837 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "has authority: " << u.has_authority() << "\n" |
| 838 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.authority() << "\n" |
| 839 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "path: " << u.path() << "\n"; |
| 840 | // end::snippet_parsing_authority_2[] | ||
| 841 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "https"); |
| 842 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_authority()); |
| 843 |
1/1✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.authority().buffer() == "www.boost.org"); |
| 844 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.path().empty()); |
| 845 | } | ||
| 846 | { | ||
| 847 | // tag::snippet_parsing_authority_3a[] | ||
| 848 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.boost.org/users/download/" ); |
| 849 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u.has_authority()); |
| 850 | 1 | authority_view a = u.authority(); | |
| 851 | // end::snippet_parsing_authority_3a[] | ||
| 852 | // tag::snippet_parsing_authority_3b[] | ||
| 853 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(a.host() == "www.boost.org"); |
| 854 | // end::snippet_parsing_authority_3b[] | ||
| 855 | 1 | } | |
| 856 | { | ||
| 857 | // tag::snippet_parsing_authority_4[] | ||
| 858 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.boost.org/" ); |
| 859 | std::cout << "scheme: " << u.scheme() << "\n" | ||
| 860 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "has authority: " << u.has_authority() << "\n" |
| 861 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.authority() << "\n" |
| 862 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "path: " << u.path() << "\n"; |
| 863 | // end::snippet_parsing_authority_4[] | ||
| 864 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "https"); |
| 865 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_authority()); |
| 866 |
1/1✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.authority().buffer() == "www.boost.org"); |
| 867 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.path() == "/"); |
| 868 | } | ||
| 869 | { | ||
| 870 | // tag::snippet_parsing_authority_5[] | ||
| 871 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "mailto:John.Doe@example.com" ); |
| 872 | std::cout << "scheme: " << u.scheme() << "\n" | ||
| 873 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "has authority: " << u.has_authority() << "\n" |
| 874 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.authority() << "\n" |
| 875 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "path: " << u.path() << "\n"; |
| 876 | // end::snippet_parsing_authority_5[] | ||
| 877 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "mailto"); |
| 878 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 879 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.authority().buffer().empty()); |
| 880 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.path() == "John.Doe@example.com"); |
| 881 | } | ||
| 882 | { | ||
| 883 | // tag::snippet_parsing_authority_6[] | ||
| 884 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "mailto://John.Doe@example.com" ); |
| 885 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 886 | "scheme: " << u.scheme() << "\n" | ||
| 887 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "has authority: " << u.has_authority() << "\n" |
| 888 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.authority() << "\n" |
| 889 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "path: " << u.path() << "\n"; |
| 890 | // end::snippet_parsing_authority_6[] | ||
| 891 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "mailto"); |
| 892 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_authority()); |
| 893 |
1/1✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.authority().buffer() == "John.Doe@example.com"); |
| 894 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.path().empty()); |
| 895 | } | ||
| 896 | { | ||
| 897 | // tag::snippet_parsing_authority_7[] | ||
| 898 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://john.doe@www.example.com:123/forum/questions/" ); |
| 899 | std::cout << "scheme: " << u.scheme() << "\n" | ||
| 900 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "has authority: " << u.has_authority() << "\n" |
| 901 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.authority() << "\n" |
| 902 |
1/1✓ Branch 1 taken 1 time.
|
2 | "host: " << u.host() << "\n" |
| 903 |
1/1✓ Branch 1 taken 1 time.
|
2 | "userinfo: " << u.userinfo() << "\n" |
| 904 | "port: " << u.port() << "\n" | ||
| 905 |
10/10✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
✓ Branch 15 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 26 taken 1 time.
✓ Branch 29 taken 1 time.
✓ Branch 32 taken 1 time.
|
3 | "path: " << u.path() << "\n"; |
| 906 | // end::snippet_parsing_authority_7[] | ||
| 907 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "https"); |
| 908 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_authority()); |
| 909 |
1/1✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.authority().buffer() == "john.doe@www.example.com:123"); |
| 910 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.host() == "www.example.com"); |
| 911 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.userinfo() == "john.doe"); |
| 912 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.port() == "123"); |
| 913 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.path() == "/forum/questions/"); |
| 914 | } | ||
| 915 | { | ||
| 916 | // tag::snippet_parsing_authority_8[] | ||
| 917 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://john.doe@www.example.com:123/forum/questions/" ); |
| 918 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "www.example.com"); |
| 919 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.port() == "123"); |
| 920 | // end::snippet_parsing_authority_8[] | ||
| 921 | } | ||
| 922 | { | ||
| 923 | // tag::snippet_parsing_authority_9[] | ||
| 924 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://john.doe@192.168.2.1:123/forum/questions/" ); |
| 925 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "192.168.2.1"); |
| 926 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.port() == "123"); |
| 927 | // end::snippet_parsing_authority_9[] | ||
| 928 | } | ||
| 929 | { | ||
| 930 | // tag::snippet_parsing_authority_9b[] | ||
| 931 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.example.com" ); |
| 932 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "www.example.com"); |
| 933 |
3/4✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 time.
|
1 | assert(u.host() == u.encoded_host()); |
| 934 | // end::snippet_parsing_authority_9b[] | ||
| 935 | } | ||
| 936 | { | ||
| 937 | struct resolve_f { | ||
| 938 | boost::core::string_view | ||
| 939 | 1 | operator()(boost::core::string_view h) | |
| 940 | { | ||
| 941 | 1 | return h; | |
| 942 | } | ||
| 943 | } resolve; | ||
| 944 | struct write_request_f { | ||
| 945 | 1 | void operator()(boost::core::string_view) {} | |
| 946 | ✗ | void operator()(ipv4_address) {} | |
| 947 | ✗ | void operator()(ipv6_address) {} | |
| 948 | } write_request; | ||
| 949 | |||
| 950 | // tag::snippet_parsing_authority_10[] | ||
| 951 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.boost.org/users/download/" ); |
| 952 |
1/4✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | switch (u.host_type()) |
| 953 | { | ||
| 954 | 1 | case host_type::name: | |
| 955 |
1/1✓ Branch 2 taken 1 time.
|
1 | write_request(resolve(u.host())); |
| 956 | 1 | break; | |
| 957 | ✗ | case host_type::ipv4: | |
| 958 | ✗ | write_request(u.host_ipv4_address()); | |
| 959 | ✗ | break; | |
| 960 | ✗ | case host_type::ipv6: | |
| 961 | ✗ | write_request(u.host_ipv6_address()); | |
| 962 | ✗ | break; | |
| 963 | ✗ | default: | |
| 964 | ✗ | break; | |
| 965 | } | ||
| 966 | // end::snippet_parsing_authority_10[] | ||
| 967 | } | ||
| 968 | { | ||
| 969 | // tag::snippet_parsing_authority_10a[] | ||
| 970 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https:///path/to_resource" ); |
| 971 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert( u.has_authority() ); |
| 972 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert( u.authority().buffer().empty() ); |
| 973 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.path() == "/path/to_resource" ); |
| 974 | // end::snippet_parsing_authority_10a[] | ||
| 975 | } | ||
| 976 | { | ||
| 977 | // tag::snippet_parsing_authority_10b[] | ||
| 978 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.boost.org" ); |
| 979 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.host() == "www.boost.org" ); |
| 980 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.path().empty() ); |
| 981 | // end::snippet_parsing_authority_10b[] | ||
| 982 | } | ||
| 983 | { | ||
| 984 | // tag::snippet_parsing_authority_10c[] | ||
| 985 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.boost.org/users/download/" ); |
| 986 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.host() == "www.boost.org" ); |
| 987 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.path() == "/users/download/" ); |
| 988 | // end::snippet_parsing_authority_10c[] | ||
| 989 | } | ||
| 990 | { | ||
| 991 | // tag::snippet_parsing_authority_10d[] | ||
| 992 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.boost.org/" ); |
| 993 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.host() == "www.boost.org" ); |
| 994 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.path() == "/" ); |
| 995 | // end::snippet_parsing_authority_10d[] | ||
| 996 | } | ||
| 997 | { | ||
| 998 | // tag::snippet_parsing_authority_10e[] | ||
| 999 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "mailto:John.Doe@example.com" ); |
| 1000 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert( !u.has_authority() ); |
| 1001 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.path() == "John.Doe@example.com" ); |
| 1002 | // end::snippet_parsing_authority_10e[] | ||
| 1003 | } | ||
| 1004 | { | ||
| 1005 | // tag::snippet_parsing_authority_10f[] | ||
| 1006 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "mailto://John.Doe@example.com" ); |
| 1007 |
1/1✓ Branch 5 taken 1 time.
|
1 | assert( u.authority().buffer() == "John.Doe@example.com" ); |
| 1008 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.path().empty() ); |
| 1009 | // end::snippet_parsing_authority_10f[] | ||
| 1010 | } | ||
| 1011 | { | ||
| 1012 | // tag::snippet_parsing_authority_11a[] | ||
| 1013 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://john.doe@www.example.com:123/forum/questions/" ); |
| 1014 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.userinfo() == "john.doe"); |
| 1015 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.port() == "123"); |
| 1016 | // end::snippet_parsing_authority_11a[] | ||
| 1017 | } | ||
| 1018 | { | ||
| 1019 | // tag::snippet_parsing_authority_11b[] | ||
| 1020 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://john:doe@www.somehost.com/forum/questions/" ); |
| 1021 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.userinfo() == "john:doe"); |
| 1022 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.user() == "john"); |
| 1023 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.password() == "doe"); |
| 1024 | // end::snippet_parsing_authority_11b[] | ||
| 1025 | } | ||
| 1026 | { | ||
| 1027 | // tag::snippet_parsing_authority_12[] | ||
| 1028 |
1/1✓ Branch 4 taken 1 time.
|
1 | authority_view a = parse_authority( "www.example.com:80" ).value(); |
| 1029 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!a.has_userinfo()); |
| 1030 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(a.host() == "www.example.com"); |
| 1031 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(a.port() == "80"); |
| 1032 | // end::snippet_parsing_authority_12[] | ||
| 1033 | 1 | } | |
| 1034 | { | ||
| 1035 | // tag::snippet_parsing_authority_13[] | ||
| 1036 |
1/1✓ Branch 4 taken 1 time.
|
1 | authority_view a = parse_authority( "user:pass@www.example.com:443" ).value(); |
| 1037 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(a.userinfo() == "user:pass"); |
| 1038 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(a.user() == "user"); |
| 1039 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(a.password() == "pass"); |
| 1040 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(a.host() == "www.example.com"); |
| 1041 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(a.port() == "443"); |
| 1042 | // end::snippet_parsing_authority_13[] | ||
| 1043 | 1 | } | |
| 1044 | 1 | } | |
| 1045 | |||
| 1046 | void | ||
| 1047 | 1 | parsing_path() | |
| 1048 | { | ||
| 1049 | { | ||
| 1050 | // tag::snippet_parsing_path_0[] | ||
| 1051 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("http://www.example.com/path/to/file.txt"); |
| 1052 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/path/to/file.txt"); |
| 1053 | 1 | segments_view segs = u.segments(); | |
| 1054 | 1 | auto it = segs.begin(); | |
| 1055 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( *it++ == "path" ); |
| 1056 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( *it++ == "to" ); |
| 1057 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert( *it == "file.txt" ); |
| 1058 | // end::snippet_parsing_path_0[] | ||
| 1059 | boost::ignore_unused(it); | ||
| 1060 | } | ||
| 1061 | { | ||
| 1062 | // tag::snippet_parsing_path_1[] | ||
| 1063 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org/doc/the%20libs/"); |
| 1064 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/doc/the libs/"); |
| 1065 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(u.encoded_path() == "/doc/the%20libs/"); |
| 1066 | // end::snippet_parsing_path_1[] | ||
| 1067 | |||
| 1068 | // tag::snippet_parsing_path_1_b[] | ||
| 1069 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | std::cout << u.encoded_segments().size() << " segments\n"; |
| 1070 |
2/2✓ Branch 6 taken 3 times.
✓ Branch 7 taken 1 time.
|
4 | for (auto seg: u.encoded_segments()) |
| 1071 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | std::cout << "segment: " << seg << "\n"; |
| 1072 | // end::snippet_parsing_path_1_b[] | ||
| 1073 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 1074 | u.encoded_segments(), | ||
| 1075 | {"doc", "the%20libs", ""})); | ||
| 1076 | } | ||
| 1077 | { | ||
| 1078 | // tag::snippet_parsing_path_2[] | ||
| 1079 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org/doc/libs"); |
| 1080 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | std::cout << u.segments().size() << " segments\n"; |
| 1081 |
3/3✓ Branch 4 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1 time.
|
3 | for (auto seg: u.segments()) |
| 1082 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | std::cout << "segment: " << seg << "\n"; |
| 1083 | // end::snippet_parsing_path_2[] | ||
| 1084 | 1 | auto segs = u.segments(); | |
| 1085 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range(segs, {"doc", "libs"})); |
| 1086 | } | ||
| 1087 | { | ||
| 1088 | // tag::snippet_parsing_path_3[] | ||
| 1089 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org"); |
| 1090 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path().empty()); |
| 1091 |
1/1✓ Branch 3 taken 1 time.
|
1 | assert(u.encoded_path().empty()); |
| 1092 | // end::snippet_parsing_path_3[] | ||
| 1093 | } | ||
| 1094 | { | ||
| 1095 | // tag::snippet_parsing_path_3a[] | ||
| 1096 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | assert( url_view("urn:isbn:096139210x").path() == "isbn:096139210x" ); |
| 1097 | // end::snippet_parsing_path_3a[] | ||
| 1098 | } | ||
| 1099 | { | ||
| 1100 | // tag::snippet_parsing_path_4[] | ||
| 1101 | /* | ||
| 1102 | url_view u("https://www.boost.org//doc///libs"); | ||
| 1103 | std::cout << u << "\n" | ||
| 1104 | "path: " << u.encoded_path() << "\n" | ||
| 1105 | "encoded segments: " << u.encoded_segments() << "\n" | ||
| 1106 | "segments: " << u.segments() << "\n"; | ||
| 1107 | std::cout << u.encoded_segments().size() << " segments\n"; | ||
| 1108 | for (auto seg: u.encoded_segments()) | ||
| 1109 | std::cout << "segment: " << seg << "\n"; | ||
| 1110 | */ | ||
| 1111 | // end::snippet_parsing_path_4[] | ||
| 1112 | } | ||
| 1113 | |||
| 1114 | { | ||
| 1115 | { | ||
| 1116 | // tag::snippet_parsing_path_5_a[] | ||
| 1117 | 1 | boost::core::string_view s = "https://www.boost.org"; | |
| 1118 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u(s); |
| 1119 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1120 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | << "path: " << u.encoded_host() << "\n" |
| 1121 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | << "path: " << u.encoded_path() << "\n" |
| 1122 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | << "segments: " << u.encoded_segments().size() << "\n"; |
| 1123 | // end::snippet_parsing_path_5_a[] | ||
| 1124 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_host() == "www.boost.org"); |
| 1125 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST(u.encoded_path().empty()); |
| 1126 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 1127 | u.encoded_segments(), | ||
| 1128 | std::initializer_list<const char*>{})); | ||
| 1129 | } | ||
| 1130 | { | ||
| 1131 | // tag::snippet_parsing_path_5_b[] | ||
| 1132 | 1 | boost::core::string_view s = "https://www.boost.org/"; | |
| 1133 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u(s); |
| 1134 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1135 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | << "host: " << u.encoded_host() << "\n" |
| 1136 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | << "path: " << u.encoded_path() << "\n" |
| 1137 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | << "segments: " << u.encoded_segments().size() << "\n"; |
| 1138 | // end::snippet_parsing_path_5_b[] | ||
| 1139 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_host() == "www.boost.org"); |
| 1140 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_path() == "/"); |
| 1141 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 1142 | u.encoded_segments(), | ||
| 1143 | std::initializer_list<const char*>{})); | ||
| 1144 | } | ||
| 1145 | { | ||
| 1146 | // tag::snippet_parsing_path_5_c[] | ||
| 1147 | 1 | boost::core::string_view s = "https://www.boost.org//"; | |
| 1148 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u(s); |
| 1149 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1150 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | << "host: " << u.encoded_host() << "\n" |
| 1151 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | << "path: " << u.encoded_path() << "\n" |
| 1152 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | << "segments: " << u.encoded_segments().size() << "\n"; |
| 1153 | // end::snippet_parsing_path_5_c[] | ||
| 1154 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_host() == "www.boost.org"); |
| 1155 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_path() == "//"); |
| 1156 | 1 | auto segs = u.encoded_segments(); | |
| 1157 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range(segs, {"", ""})); |
| 1158 | } | ||
| 1159 | } | ||
| 1160 | |||
| 1161 | { | ||
| 1162 | // tag::snippet_parsing_path_6[] | ||
| 1163 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org//doc/libs/"); |
| 1164 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1165 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.encoded_authority() << "\n" |
| 1166 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | "path: " << u.encoded_path() << "\n"; |
| 1167 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | std::cout << u.encoded_segments().size() << " segments\n"; |
| 1168 |
2/2✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1 time.
|
5 | for (auto seg: u.encoded_segments()) |
| 1169 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | std::cout << "segment: " << seg << "\n"; |
| 1170 | // end::snippet_parsing_path_6[] | ||
| 1171 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_authority() == "www.boost.org"); |
| 1172 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_path() == "//doc/libs/"); |
| 1173 | 1 | auto segs = u.encoded_segments(); | |
| 1174 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range(segs, {"", "doc", "libs", ""})); |
| 1175 | } | ||
| 1176 | |||
| 1177 | { | ||
| 1178 | // tag::snippet_parsing_path_7[] | ||
| 1179 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://doc/libs/"); |
| 1180 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1181 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.encoded_authority() << "\n" |
| 1182 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | "path: " << u.encoded_path() << "\n"; |
| 1183 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | std::cout << u.encoded_segments().size() << " segments\n"; |
| 1184 |
2/2✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 time.
|
3 | for (auto seg: u.encoded_segments()) |
| 1185 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | std::cout << "segment: " << seg << "\n"; |
| 1186 | // end::snippet_parsing_path_7[] | ||
| 1187 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_authority() == "doc"); |
| 1188 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_path() == "/libs/"); |
| 1189 | 1 | auto segs = u.encoded_segments(); | |
| 1190 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range(segs, {"libs", ""})); |
| 1191 | } | ||
| 1192 | |||
| 1193 | { | ||
| 1194 | // tag::snippet_parsing_path_8[] | ||
| 1195 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org/doc@folder/libs:boost"); |
| 1196 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1197 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "authority: " << u.encoded_authority() << "\n" |
| 1198 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | "path: " << u.encoded_path() << "\n"; |
| 1199 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | std::cout << u.encoded_segments().size() << " segments\n"; |
| 1200 |
2/2✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 time.
|
3 | for (auto seg: u.encoded_segments()) |
| 1201 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | std::cout << "segment: " << seg << "\n"; |
| 1202 | // end::snippet_parsing_path_8[] | ||
| 1203 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_authority() == "www.boost.org"); |
| 1204 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_path() == "/doc@folder/libs:boost"); |
| 1205 | 1 | auto segs = u.encoded_segments(); | |
| 1206 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(equal_range(segs, {"doc@folder", "libs:boost"})); |
| 1207 | } | ||
| 1208 | |||
| 1209 | { | ||
| 1210 | // tag::snippet_parsing_path_9[] | ||
| 1211 | /* | ||
| 1212 | segments_view segs = parse_path("/doc/libs").value(); | ||
| 1213 | assert( segs.size() == 2 ); | ||
| 1214 | */ | ||
| 1215 | // end::snippet_parsing_path_9[] | ||
| 1216 | //boost::ignore_unused(segs); | ||
| 1217 | } | ||
| 1218 | |||
| 1219 | { | ||
| 1220 | // tag::snippet_parsing_path_use_case_1[] | ||
| 1221 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org/doc/libs/"); |
| 1222 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "www.boost.org"); |
| 1223 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/doc/libs/"); |
| 1224 | // end::snippet_parsing_path_use_case_1[] | ||
| 1225 | boost::ignore_unused(u); | ||
| 1226 | } | ||
| 1227 | { | ||
| 1228 | // tag::snippet_parsing_path_use_case_2[] | ||
| 1229 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( parse_uri("https://www.boost.org").has_value() ); |
| 1230 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( parse_uri("https://www.boost.org/").has_value() ); |
| 1231 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( parse_uri("https://www.boost.org//").has_value() ); |
| 1232 | // end::snippet_parsing_path_use_case_2[] | ||
| 1233 | } | ||
| 1234 | { | ||
| 1235 | // tag::snippet_parsing_path_use_case_3[] | ||
| 1236 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | assert( url_view("https://www.boost.org").path().empty() ); |
| 1237 | // end::snippet_parsing_path_use_case_3[] | ||
| 1238 | } | ||
| 1239 | { | ||
| 1240 | // tag::snippet_parsing_path_use_case_4[] | ||
| 1241 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org/doc@folder/libs:boost"); |
| 1242 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/doc@folder/libs:boost"); |
| 1243 | // end::snippet_parsing_path_use_case_4[] | ||
| 1244 | boost::ignore_unused(u); | ||
| 1245 | } | ||
| 1246 | { | ||
| 1247 | // tag::snippet_parsing_path_use_case_5[] | ||
| 1248 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org/doc/libs/"); |
| 1249 | 1 | segments_view segs = u.segments(); | |
| 1250 | 1 | auto it = segs.begin(); | |
| 1251 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == "doc"); |
| 1252 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == "libs"); |
| 1253 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(*it == ""); |
| 1254 | // end::snippet_parsing_path_use_case_5[] | ||
| 1255 | boost::ignore_unused(it); | ||
| 1256 | } | ||
| 1257 | { | ||
| 1258 | // tag::snippet_parsing_path_use_case_6[] | ||
| 1259 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org//doc///libs"); |
| 1260 | 1 | segments_view segs = u.segments(); | |
| 1261 | 1 | auto it = segs.begin(); | |
| 1262 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == ""); |
| 1263 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == "doc"); |
| 1264 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == ""); |
| 1265 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == ""); |
| 1266 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(*it == "libs"); |
| 1267 | // end::snippet_parsing_path_use_case_6[] | ||
| 1268 | boost::ignore_unused(it); | ||
| 1269 | } | ||
| 1270 | { | ||
| 1271 | // tag::snippet_parsing_path_use_case_7[] | ||
| 1272 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org//doc/libs/"); |
| 1273 | 1 | segments_view segs = u.segments(); | |
| 1274 | 1 | auto it = segs.begin(); | |
| 1275 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == ""); |
| 1276 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == "doc"); |
| 1277 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == "libs"); |
| 1278 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(*it == ""); |
| 1279 | // end::snippet_parsing_path_use_case_7[] | ||
| 1280 | boost::ignore_unused(it); | ||
| 1281 | } | ||
| 1282 | { | ||
| 1283 | // tag::snippet_parsing_path_use_case_8[] | ||
| 1284 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://doc/libs/"); |
| 1285 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "doc"); |
| 1286 | 1 | segments_view segs = u.segments(); | |
| 1287 | 1 | auto it = segs.begin(); | |
| 1288 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(*it++ == "libs"); |
| 1289 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(*it == ""); |
| 1290 | // end::snippet_parsing_path_use_case_8[] | ||
| 1291 | boost::ignore_unused(it); | ||
| 1292 | } | ||
| 1293 | 1 | } | |
| 1294 | |||
| 1295 | void | ||
| 1296 | 1 | parsing_query() | |
| 1297 | { | ||
| 1298 | { | ||
| 1299 | // tag::snippet_parsing_query_0[] | ||
| 1300 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?id=409&name=Joe&individual"); |
| 1301 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert( u.query() == "id=409&name=Joe&individual" ); |
| 1302 | // end::snippet_parsing_query_0[] | ||
| 1303 | } | ||
| 1304 | { | ||
| 1305 | // tag::snippet_parsing_query_1[] | ||
| 1306 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?id=409&name=Joe&individual"); |
| 1307 | 1 | params_view ps = u.params(); | |
| 1308 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(ps.size() == 3); |
| 1309 | // end::snippet_parsing_query_1[] | ||
| 1310 | // tag::snippet_parsing_query_1a[] | ||
| 1311 | 1 | auto it = ps.begin(); | |
| 1312 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == "id"); |
| 1313 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).value == "409"); |
| 1314 | 1 | ++it; | |
| 1315 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == "name"); |
| 1316 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).value == "Joe"); |
| 1317 | 1 | ++it; | |
| 1318 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == "individual"); |
| 1319 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | assert(!(*it).has_value); |
| 1320 | // end::snippet_parsing_query_1a[] | ||
| 1321 | boost::ignore_unused(it); | ||
| 1322 | } | ||
| 1323 | { | ||
| 1324 | // tag::snippet_parsing_query_2[] | ||
| 1325 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?key-1=value-1&key-2=&key-3&&=value-2"); |
| 1326 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1327 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "has query: " << u.has_query() << "\n" |
| 1328 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "encoded query: " << u.encoded_query() << "\n" |
| 1329 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "query: " << u.query() << "\n"; |
| 1330 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | std::cout << u.encoded_params().size() << " parameters\n"; |
| 1331 |
2/2✓ Branch 6 taken 5 times.
✓ Branch 7 taken 1 time.
|
6 | for (auto p: u.encoded_params()) |
| 1332 | { | ||
| 1333 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | if (p.has_value) |
| 1334 | { | ||
| 1335 | std::cout << | ||
| 1336 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | "parameter: <" << p.key << |
| 1337 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | ", " << p.value << ">\n"; |
| 1338 | } else { | ||
| 1339 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | std::cout << "parameter: " << p.key << "\n"; |
| 1340 | } | ||
| 1341 | } | ||
| 1342 | // end::snippet_parsing_query_2[] | ||
| 1343 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_query()); |
| 1344 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_query() == "key-1=value-1&key-2=&key-3&&=value-2"); |
| 1345 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.query() == "key-1=value-1&key-2=&key-3&&=value-2"); |
| 1346 |
2/2✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 1347 | u.encoded_params(), | ||
| 1348 | { | ||
| 1349 | param_view{"key-1", "value-1", true}, | ||
| 1350 | param_view{"key-2", "", true}, | ||
| 1351 | param_view{"key-3", boost::core::string_view(), false}, | ||
| 1352 | param_view{"", boost::core::string_view(), false}, | ||
| 1353 | param_view{"", "value-2", true} | ||
| 1354 | })); | ||
| 1355 | } | ||
| 1356 | { | ||
| 1357 | // tag::snippet_parsing_query_3[] | ||
| 1358 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?email=joe@email.com&code=a:2@/!"); |
| 1359 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1360 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "has query: " << u.has_query() << "\n" |
| 1361 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "encoded query: " << u.encoded_query() << "\n" |
| 1362 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "query: " << u.query() << "\n"; |
| 1363 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | std::cout << u.encoded_params().size() << " parameters\n"; |
| 1364 |
2/2✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 time.
|
3 | for (auto p: u.encoded_params()) |
| 1365 | { | ||
| 1366 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (p.has_value) |
| 1367 | { | ||
| 1368 | std::cout << | ||
| 1369 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | "parameter: <" << p.key << |
| 1370 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | ", " << p.value << ">\n"; |
| 1371 | } else { | ||
| 1372 | ✗ | std::cout << "parameter: " << p.key << "\n"; | |
| 1373 | } | ||
| 1374 | } | ||
| 1375 | // end::snippet_parsing_query_3[] | ||
| 1376 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_query()); |
| 1377 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_query() == "email=joe@email.com&code=a:2@/!"); |
| 1378 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.query() == "email=joe@email.com&code=a:2@/!"); |
| 1379 |
2/2✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 1380 | u.encoded_params(), | ||
| 1381 | { | ||
| 1382 | param_view{"email", "joe@email.com", true}, | ||
| 1383 | param_view{"code", "a:2@/!", true} | ||
| 1384 | })); | ||
| 1385 | } | ||
| 1386 | { | ||
| 1387 | // tag::snippet_parsing_query_4[] | ||
| 1388 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?name=joe"); |
| 1389 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1390 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "query: " << u.query() << "\n"; |
| 1391 | // end::snippet_parsing_query_4[] | ||
| 1392 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.query() == "name=joe"); |
| 1393 | } | ||
| 1394 | { | ||
| 1395 | // tag::snippet_parsing_query_5[] | ||
| 1396 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(url_view("https://www.example.com/get-customer.php?").has_query()); |
| 1397 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(!url_view("https://www.example.com/get-customer.php").has_query()); |
| 1398 | // end::snippet_parsing_query_5[] | ||
| 1399 | } | ||
| 1400 | { | ||
| 1401 | // tag::snippet_parsing_query_6[] | ||
| 1402 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?name=John%20Doe"); |
| 1403 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1404 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "has query: " << u.has_query() << "\n" |
| 1405 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "encoded query: " << u.encoded_query() << "\n" |
| 1406 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "query: " << u.query() << "\n"; |
| 1407 | // end::snippet_parsing_query_6[] | ||
| 1408 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_query()); |
| 1409 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_query() == "name=John%20Doe"); |
| 1410 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.query() == "name=John Doe"); |
| 1411 | } | ||
| 1412 | { | ||
| 1413 | // tag::snippet_parsing_query_7[] | ||
| 1414 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?name=John%26Doe"); |
| 1415 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.query() == "name=John&Doe"); |
| 1416 | // end::snippet_parsing_query_7[] | ||
| 1417 | } | ||
| 1418 | { | ||
| 1419 | // tag::snippet_parsing_query_8[] | ||
| 1420 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?key-1=value-1&key-2=&key-3&&=value-4"); |
| 1421 | 1 | params_view ps = u.params(); | |
| 1422 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(ps.size() == 5); |
| 1423 | // end::snippet_parsing_query_8[] | ||
| 1424 | // tag::snippet_parsing_query_8a[] | ||
| 1425 | 1 | auto it = ps.begin(); | |
| 1426 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == "key-1"); |
| 1427 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).value == "value-1"); |
| 1428 | // end::snippet_parsing_query_8a[] | ||
| 1429 | // tag::snippet_parsing_query_8b[] | ||
| 1430 | 1 | ++it; | |
| 1431 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == "key-2"); |
| 1432 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).value == ""); |
| 1433 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | assert((*it).has_value); |
| 1434 | // end::snippet_parsing_query_8b[] | ||
| 1435 | // tag::snippet_parsing_query_8c[] | ||
| 1436 | 1 | ++it; | |
| 1437 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == "key-3"); |
| 1438 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | assert(!(*it).has_value); |
| 1439 | // end::snippet_parsing_query_8c[] | ||
| 1440 | // tag::snippet_parsing_query_8d[] | ||
| 1441 | 1 | ++it; | |
| 1442 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == ""); |
| 1443 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | assert(!(*it).has_value); |
| 1444 | // end::snippet_parsing_query_8d[] | ||
| 1445 | // tag::snippet_parsing_query_8e[] | ||
| 1446 | 1 | ++it; | |
| 1447 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).key == ""); |
| 1448 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert((*it).value == "value-4"); |
| 1449 | // end::snippet_parsing_query_8e[] | ||
| 1450 | } | ||
| 1451 | { | ||
| 1452 | // tag::snippet_parsing_query_9[] | ||
| 1453 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/get-customer.php?email=joe@email.com&code=a:2@/!"); |
| 1454 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u.has_query()); |
| 1455 | // end::snippet_parsing_query_9[] | ||
| 1456 | } | ||
| 1457 | 1 | } | |
| 1458 | |||
| 1459 | void | ||
| 1460 | 1 | parsing_fragment() | |
| 1461 | { | ||
| 1462 | { | ||
| 1463 | // tag::snippet_parsing_fragment_1[] | ||
| 1464 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/index.html#section%202"); |
| 1465 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1466 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "has fragment: " << u.has_fragment() << "\n" |
| 1467 |
1/1✓ Branch 1 taken 1 time.
|
2 | "fragment: " << u.fragment() << "\n" |
| 1468 |
5/5✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
✓ Branch 15 taken 1 time.
|
2 | "encoded fragment: " << u.encoded_fragment() << "\n"; |
| 1469 | // end::snippet_parsing_fragment_1[] | ||
| 1470 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_fragment()); |
| 1471 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.fragment() == "section 2"); |
| 1472 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | BOOST_TEST(u.encoded_fragment() == "section%202"); |
| 1473 | } | ||
| 1474 | { | ||
| 1475 | // tag::snippet_parsing_fragment_2_a[] | ||
| 1476 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/index.html#"); |
| 1477 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1478 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "has fragment: " << u.has_fragment() << "\n" |
| 1479 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "fragment: " << u.fragment() << "\n"; |
| 1480 | // end::snippet_parsing_fragment_2_a[] | ||
| 1481 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_fragment()); |
| 1482 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.fragment().empty()); |
| 1483 | } | ||
| 1484 | { | ||
| 1485 | // tag::snippet_parsing_fragment_2_b[] | ||
| 1486 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/index.html"); |
| 1487 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1488 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "has fragment: " << u.has_fragment() << "\n" |
| 1489 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "fragment: " << u.fragment() << "\n"; |
| 1490 | // end::snippet_parsing_fragment_2_b[] | ||
| 1491 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_fragment()); |
| 1492 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.fragment().empty()); |
| 1493 | } | ||
| 1494 | { | ||
| 1495 | // tag::snippet_parsing_fragment_3[] | ||
| 1496 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/index.html#code%20:a@b?c/d"); |
| 1497 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u << "\n" |
| 1498 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "has fragment: " << u.has_fragment() << "\n" |
| 1499 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
|
1 | "fragment: " << u.fragment() << "\n"; |
| 1500 | // end::snippet_parsing_fragment_3[] | ||
| 1501 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_fragment()); |
| 1502 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | BOOST_TEST(u.fragment() == "code :a@b?c/d"); |
| 1503 | } | ||
| 1504 | { | ||
| 1505 | // tag::snippet_parsing_fragment_4[] | ||
| 1506 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/index.html#section2"); |
| 1507 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.fragment() == "section2"); |
| 1508 | // end::snippet_parsing_fragment_4[] | ||
| 1509 | } | ||
| 1510 | { | ||
| 1511 | // tag::snippet_parsing_fragment_5[] | ||
| 1512 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(url_view("https://www.example.com/index.html#").has_fragment()); |
| 1513 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert(!url_view("https://www.example.com/index.html").has_fragment()); |
| 1514 | // end::snippet_parsing_fragment_5[] | ||
| 1515 | } | ||
| 1516 | { | ||
| 1517 | // tag::snippet_parsing_fragment_6[] | ||
| 1518 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com/index.html#code%20:a@b?c/d"); |
| 1519 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.fragment() == "code :a@b?c/d"); |
| 1520 | // end::snippet_parsing_fragment_6[] | ||
| 1521 | } | ||
| 1522 | 1 | } | |
| 1523 | |||
| 1524 | void | ||
| 1525 | 1 | using_modifying() | |
| 1526 | { | ||
| 1527 | { | ||
| 1528 | // tag::snippet_modifying_1[] | ||
| 1529 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.example.com"); |
| 1530 |
1/1✓ Branch 1 taken 1 time.
|
1 | url v(u); |
| 1531 | // end::snippet_modifying_1[] | ||
| 1532 | |||
| 1533 | // tag::snippet_modifying_2[] | ||
| 1534 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(v.scheme() == "https"); |
| 1535 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(v.has_authority()); |
| 1536 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(v.encoded_authority() == "www.example.com"); |
| 1537 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(v.encoded_path() == ""); |
| 1538 | // end::snippet_modifying_2[] | ||
| 1539 | |||
| 1540 | // tag::snippet_modifying_3[] | ||
| 1541 |
1/1✓ Branch 2 taken 1 time.
|
1 | v.set_host("my website.com"); |
| 1542 |
1/1✓ Branch 2 taken 1 time.
|
1 | v.set_path("my file.txt"); |
| 1543 |
1/1✓ Branch 2 taken 1 time.
|
1 | v.set_query("id=42&name=John Doe"); |
| 1544 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(v.buffer() == "https://my%20website.com/my%20file.txt?id=42&name=John%20Doe"); |
| 1545 | // end::snippet_modifying_3[] | ||
| 1546 | |||
| 1547 | // tag::snippet_modifying_4[] | ||
| 1548 |
1/1✓ Branch 2 taken 1 time.
|
1 | v.set_scheme("http"); |
| 1549 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(v.buffer() == "http://my%20website.com/my%20file.txt?id=42&name=John%20Doe"); |
| 1550 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | v.set_encoded_host("www.my%20example.com"); |
| 1551 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(v.buffer() == "http://www.my%20example.com/my%20file.txt?id=42&name=John%20Doe"); |
| 1552 | // end::snippet_modifying_4[] | ||
| 1553 | |||
| 1554 | |||
| 1555 | 1 | } | |
| 1556 | 1 | } | |
| 1557 | |||
| 1558 | void | ||
| 1559 | 1 | grammar_parse() | |
| 1560 | { | ||
| 1561 | { | ||
| 1562 | // tag::snippet_parse_1[] | ||
| 1563 | // VFALCO we should not show this example | ||
| 1564 | /* | ||
| 1565 | boost::core::string_view s = "http:after_scheme"; | ||
| 1566 | const char* it = s.begin(); | ||
| 1567 | auto rv = grammar::parse(it, s.end(), scheme_rule() ); | ||
| 1568 | if( ! rv ) | ||
| 1569 | { | ||
| 1570 | std::cout << "scheme: " << rv->scheme << '\n'; | ||
| 1571 | std::cout << "suffix: " << it << '\n'; | ||
| 1572 | } | ||
| 1573 | */ | ||
| 1574 | // end::snippet_parse_1[] | ||
| 1575 | } | ||
| 1576 | |||
| 1577 | { | ||
| 1578 | // tag::snippet_parse_2[] | ||
| 1579 | // VFALCO This needs refactoring | ||
| 1580 | /* | ||
| 1581 | boost::core::string_view s = "?key=value#anchor"; | ||
| 1582 | const char* it = s.begin(); | ||
| 1583 | boost::system::error_code ec; | ||
| 1584 | if (grammar::parse(it, s.end(), ec, r1)) | ||
| 1585 | { | ||
| 1586 | auto r2 = grammar::parse( it, s.end(), fragment_part_rule ); | ||
| 1587 | if( r2 ) | ||
| 1588 | { | ||
| 1589 | std::cout << "query: " << r1.query_part << '\n'; | ||
| 1590 | std::cout << "fragment: " << std::get<1>(*r2.value()).encoded() << '\n'; | ||
| 1591 | } | ||
| 1592 | } | ||
| 1593 | */ | ||
| 1594 | // end::snippet_parse_2[] | ||
| 1595 | } | ||
| 1596 | |||
| 1597 | { | ||
| 1598 | // tag::snippet_parse_3[] | ||
| 1599 | // VFALCO This needs refactoring | ||
| 1600 | /* | ||
| 1601 | boost::core::string_view s = "?key=value#anchor"; | ||
| 1602 | query_part_rule r1; | ||
| 1603 | const char* it = s.begin(); | ||
| 1604 | boost::system::error_code ec; | ||
| 1605 | auto r2 = grammar::parse( it, s.end(), ec, fragment_part_rule ); | ||
| 1606 | if( ! ec.failed() ) | ||
| 1607 | { | ||
| 1608 | std::cout << "query: " << r1.query_part << '\n'; | ||
| 1609 | std::cout << "fragment: " << r2.fragment.encoded() << '\n'; | ||
| 1610 | } | ||
| 1611 | */ | ||
| 1612 | // end::snippet_parse_3[] | ||
| 1613 | } | ||
| 1614 | |||
| 1615 | { | ||
| 1616 | // tag::snippet_parse_4[] | ||
| 1617 | /* VFALCO This will be removed | ||
| 1618 | boost::core::string_view s = "http://www.boost.org"; | ||
| 1619 | uri_rule r; | ||
| 1620 | boost::system::error_code ec; | ||
| 1621 | if (grammar::parse_string(s, ec, r)) | ||
| 1622 | { | ||
| 1623 | std::cout << "scheme: " << r.scheme_part.scheme << '\n'; | ||
| 1624 | std::cout << "host: " << r.hier_part.authority.host.host_part << '\n'; | ||
| 1625 | } | ||
| 1626 | */ | ||
| 1627 | // end::snippet_parse_4[] | ||
| 1628 | } | ||
| 1629 | 1 | } | |
| 1630 | |||
| 1631 | // tag::snippet_customization_1[] | ||
| 1632 | /* VFALCO This needs rewriting | ||
| 1633 | struct lowercase_rule | ||
| 1634 | { | ||
| 1635 | boost::core::string_view str; | ||
| 1636 | |||
| 1637 | friend | ||
| 1638 | void | ||
| 1639 | tag_invoke( | ||
| 1640 | grammar::parse_tag const&, | ||
| 1641 | char const*& it, | ||
| 1642 | char const* const end, | ||
| 1643 | boost::system::error_code& ec, | ||
| 1644 | lowercase_rule& t) noexcept | ||
| 1645 | { | ||
| 1646 | ec = {}; | ||
| 1647 | char const* begin = it; | ||
| 1648 | while (it != end && std::islower(*it)) | ||
| 1649 | { | ||
| 1650 | ++it; | ||
| 1651 | } | ||
| 1652 | t.str = boost::core::string_view(begin, it); | ||
| 1653 | } | ||
| 1654 | }; | ||
| 1655 | */ | ||
| 1656 | // end::snippet_customization_1[] | ||
| 1657 | |||
| 1658 | void | ||
| 1659 | 1 | grammar_customization() | |
| 1660 | { | ||
| 1661 | { | ||
| 1662 | // tag::snippet_customization_2[] | ||
| 1663 | // VFALCO THIS NEEDS TO BE PORTED | ||
| 1664 | /* | ||
| 1665 | boost::core::string_view s = "http:somelowercase"; | ||
| 1666 | scheme_rule r1; | ||
| 1667 | lowercase_rule r2; | ||
| 1668 | boost::system::error_code ec; | ||
| 1669 | if (grammar::parse_string(s, ec, r1, ':', r2)) | ||
| 1670 | { | ||
| 1671 | std::cout << "scheme: " << r1.scheme << '\n'; | ||
| 1672 | std::cout << "lower: " << r2.str << '\n'; | ||
| 1673 | } | ||
| 1674 | */ | ||
| 1675 | // end::snippet_customization_2[] | ||
| 1676 | } | ||
| 1677 | 1 | } | |
| 1678 | |||
| 1679 | // tag::code_charset_1[] | ||
| 1680 | struct CharSet | ||
| 1681 | { | ||
| 1682 | bool operator()( char c ) const noexcept; | ||
| 1683 | |||
| 1684 | // These are both optional. If either or both are left | ||
| 1685 | // unspecified, a default implementation will be used. | ||
| 1686 | // | ||
| 1687 | char const* find_if( char const* first, char const* last ) const noexcept; | ||
| 1688 | char const* find_if_not( char const* first, char const* last ) const noexcept; | ||
| 1689 | }; | ||
| 1690 | // end::code_charset_1[] | ||
| 1691 | |||
| 1692 | void | ||
| 1693 | 1 | modifying_path() | |
| 1694 | { | ||
| 1695 | { | ||
| 1696 | // tag::snippet_modifying_path_1[] | ||
| 1697 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org"); |
| 1698 | |||
| 1699 | // end::snippet_modifying_path_1[] | ||
| 1700 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.is_path_absolute()); |
| 1701 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 0u); |
| 1702 | } | ||
| 1703 | { | ||
| 1704 | // tag::snippet_modifying_path_2[] | ||
| 1705 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://www.boost.org/"); |
| 1706 | // end::snippet_modifying_path_2[] | ||
| 1707 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.is_path_absolute()); |
| 1708 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 0u); |
| 1709 | } | ||
| 1710 | { | ||
| 1711 | // tag::snippet_modifying_path_1_2[] | ||
| 1712 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert( !url_view("https://www.boost.org").is_path_absolute() ); |
| 1713 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | assert( url_view("https://www.boost.org/").is_path_absolute() ); |
| 1714 | // end::snippet_modifying_path_1_2[] | ||
| 1715 | } | ||
| 1716 | |||
| 1717 | { | ||
| 1718 | // tag::snippet_modifying_path_3[] | ||
| 1719 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u("https://www.boost.org/./a/../b"); |
| 1720 |
1/1✓ Branch 1 taken 1 time.
|
1 | u.normalize(); |
| 1721 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.boost.org/b"); |
| 1722 | // end::snippet_modifying_path_3[] | ||
| 1723 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.is_path_absolute()); |
| 1724 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_EQ(u.buffer(), "https://www.boost.org/b"); |
| 1725 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 1u); |
| 1726 | 1 | } | |
| 1727 | { | ||
| 1728 | // tag::snippet_modifying_path_4[] | ||
| 1729 | // scheme and a relative path | ||
| 1730 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https:path/to/file.txt"); |
| 1731 | // end::snippet_modifying_path_4[] | ||
| 1732 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_EQ(u.scheme(), "https"); |
| 1733 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 1734 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.is_path_absolute()); |
| 1735 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 3u); |
| 1736 | } | ||
| 1737 | |||
| 1738 | { | ||
| 1739 | // tag::snippet_modifying_path_5[] | ||
| 1740 | // scheme and an absolute path | ||
| 1741 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https:/path/to/file.txt"); |
| 1742 | // end::snippet_modifying_path_5[] | ||
| 1743 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_EQ(u.scheme(), "https"); |
| 1744 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 1745 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.is_path_absolute()); |
| 1746 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 3u); |
| 1747 | } | ||
| 1748 | |||
| 1749 | { | ||
| 1750 | // tag::snippet_modifying_path_6[] | ||
| 1751 | // "//path" will be considered the authority component | ||
| 1752 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("https://path/to/file.txt"); |
| 1753 | // end::snippet_modifying_path_6[] | ||
| 1754 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_EQ(u.scheme(), "https"); |
| 1755 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_authority()); |
| 1756 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.is_path_absolute()); |
| 1757 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 2u); |
| 1758 | } | ||
| 1759 | |||
| 1760 | { | ||
| 1761 | // tag::snippet_modifying_path_4_5_6[] | ||
| 1762 | // scheme and a relative path | ||
| 1763 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u1("https:path/to/file.txt"); |
| 1764 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u1.has_authority()); |
| 1765 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u1.is_path_absolute()); |
| 1766 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u1.path() == "path/to/file.txt"); |
| 1767 | |||
| 1768 | // scheme and an absolute path | ||
| 1769 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u2("https:/path/to/file.txt"); |
| 1770 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u2.has_authority()); |
| 1771 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u2.is_path_absolute()); |
| 1772 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u2.path() == "/path/to/file.txt"); |
| 1773 | |||
| 1774 | // "//path" will be considered the authority component | ||
| 1775 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u3("https://path/to/file.txt"); |
| 1776 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u3.has_authority()); |
| 1777 |
1/1✓ Branch 5 taken 1 time.
|
1 | assert(u3.authority().buffer() == "path"); |
| 1778 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u3.is_path_absolute()); |
| 1779 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u3.path() == "/to/file.txt"); |
| 1780 | // end::snippet_modifying_path_4_5_6[] | ||
| 1781 | } | ||
| 1782 | |||
| 1783 | { | ||
| 1784 | // tag::snippet_modifying_path_7[] | ||
| 1785 | // only a relative path | ||
| 1786 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u = parse_uri_reference("path-to/file.txt").value(); |
| 1787 | // end::snippet_modifying_path_7[] | ||
| 1788 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_scheme()); |
| 1789 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 1790 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.is_path_absolute()); |
| 1791 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 2u); |
| 1792 | } | ||
| 1793 | |||
| 1794 | { | ||
| 1795 | // tag::snippet_modifying_path_8[] | ||
| 1796 | // "path:" will be considered the scheme component | ||
| 1797 | // instead of a substring of the first segment | ||
| 1798 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u = parse_uri_reference("path:to/file.txt").value(); |
| 1799 | // end::snippet_modifying_path_8[] | ||
| 1800 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.has_scheme()); |
| 1801 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 1802 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.is_path_absolute()); |
| 1803 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 2u); |
| 1804 | } | ||
| 1805 | |||
| 1806 | { | ||
| 1807 | // tag::snippet_modifying_path_7_8[] | ||
| 1808 | // only a relative path | ||
| 1809 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u1 = parse_uri_reference("path-to/file.txt").value(); |
| 1810 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u1.has_scheme()); |
| 1811 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u1.path() == "path-to/file.txt"); |
| 1812 | |||
| 1813 | // "path:" will be considered the scheme component | ||
| 1814 | // instead of a substring of the first segment | ||
| 1815 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u2 = parse_uri_reference("path:to/file.txt").value(); |
| 1816 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u2.has_scheme()); |
| 1817 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u2.path() == "to/file.txt"); |
| 1818 | // end::snippet_modifying_path_7_8[] | ||
| 1819 | } | ||
| 1820 | |||
| 1821 | { | ||
| 1822 | // tag::snippet_modifying_path_9[] | ||
| 1823 | // "path" should not become the authority component | ||
| 1824 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri("https:path/to/file.txt").value(); |
| 1825 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | u.set_encoded_path("//path/to/file.txt"); |
| 1826 | // end::snippet_modifying_path_9[] | ||
| 1827 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_EQ(u.scheme(), "https"); |
| 1828 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 1829 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(u.is_path_absolute()); |
| 1830 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 4u); |
| 1831 | 1 | } | |
| 1832 | |||
| 1833 | { | ||
| 1834 | // tag::snippet_modifying_path_10[] | ||
| 1835 | // "path:to" should not make the scheme become "path:" | ||
| 1836 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri_reference("path-to/file.txt").value(); |
| 1837 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | u.set_encoded_path("path:to/file.txt"); |
| 1838 | // end::snippet_modifying_path_10[] | ||
| 1839 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_scheme()); |
| 1840 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 1841 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.is_path_absolute()); |
| 1842 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 2u); |
| 1843 | 1 | } | |
| 1844 | { | ||
| 1845 | // tag::snippet_modifying_path_9_10[] | ||
| 1846 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u1("https:path/to/file.txt" ); |
| 1847 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | u1.set_encoded_path("//path/to/file.txt"); |
| 1848 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u1.buffer() == "https:/.//path/to/file.txt"); |
| 1849 | // end::snippet_modifying_path_9_10[] | ||
| 1850 | 1 | } | |
| 1851 | { | ||
| 1852 | // tag::snippet_modifying_path_11[] | ||
| 1853 | // should not insert as "pathto/file.txt" | ||
| 1854 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri_reference("to/file.txt").value(); |
| 1855 | 1 | segments_ref segs = u.segments(); | |
| 1856 |
1/1✓ Branch 3 taken 1 time.
|
1 | segs.insert(segs.begin(), "path"); |
| 1857 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "path/to/file.txt"); |
| 1858 | // end::snippet_modifying_path_11[] | ||
| 1859 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_scheme()); |
| 1860 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.has_authority()); |
| 1861 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST_NOT(u.is_path_absolute()); |
| 1862 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST_EQ(u.encoded_segments().size(), 3u); |
| 1863 | 1 | } | |
| 1864 | 1 | } | |
| 1865 | |||
| 1866 | void | ||
| 1867 | 1 | normalizing() | |
| 1868 | { | ||
| 1869 | { | ||
| 1870 | // tag::snippet_normalizing_1[] | ||
| 1871 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u1("https://www.boost.org/index.html"); |
| 1872 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u2("https://www.boost.org/doc/../index.html"); |
| 1873 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u1.buffer() != u2.buffer()); |
| 1874 | // end::snippet_normalizing_1[] | ||
| 1875 | } | ||
| 1876 | |||
| 1877 | { | ||
| 1878 | // tag::snippet_normalizing_2[] | ||
| 1879 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u1("https://www.boost.org/index.html"); |
| 1880 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u2("https://www.boost.org/doc/../index.html"); |
| 1881 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u1 == u2); |
| 1882 | // end::snippet_normalizing_2[] | ||
| 1883 | } | ||
| 1884 | |||
| 1885 | { | ||
| 1886 | // tag::snippet_normalizing_3[] | ||
| 1887 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u1("https://www.boost.org/index.html"); |
| 1888 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u2("https://www.boost.org/doc/../index.html"); |
| 1889 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u1.buffer() != u2.buffer()); |
| 1890 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u1 == u2); |
| 1891 |
1/1✓ Branch 1 taken 1 time.
|
1 | u2.normalize(); |
| 1892 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u1.buffer() == u2.buffer()); |
| 1893 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u1 == u2); |
| 1894 | // end::snippet_normalizing_3[] | ||
| 1895 | 1 | } | |
| 1896 | |||
| 1897 | { | ||
| 1898 | // tag::snippet_normalizing_4[] | ||
| 1899 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u("https://www.boost.org/doc/../%69%6e%64%65%78%20file.html"); |
| 1900 |
1/1✓ Branch 1 taken 1 time.
|
1 | u.normalize(); |
| 1901 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.boost.org/index%20file.html"); |
| 1902 | // end::snippet_normalizing_4[] | ||
| 1903 | 1 | } | |
| 1904 | |||
| 1905 | { | ||
| 1906 | // tag::snippet_normalizing_5[] | ||
| 1907 | auto normalize_http_url = | ||
| 1908 | 4 | [](url& u) | |
| 1909 | { | ||
| 1910 | 4 | u.normalize(); | |
| 1911 |
3/4✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
|
7 | if (u.port() == "80" || |
| 1912 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
7 | u.port().empty()) |
| 1913 | 4 | u.remove_port(); | |
| 1914 |
3/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3 times.
|
8 | if (u.has_authority() && |
| 1915 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 3 taken 3 times.
|
8 | u.encoded_path().empty()) |
| 1916 | 1 | u.set_path_absolute(true); | |
| 1917 | 4 | }; | |
| 1918 | |||
| 1919 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u1("https://www.boost.org"); |
| 1920 |
1/1✓ Branch 1 taken 1 time.
|
1 | normalize_http_url(u1); |
| 1921 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u2("https://www.boost.org/"); |
| 1922 |
1/1✓ Branch 1 taken 1 time.
|
1 | normalize_http_url(u2); |
| 1923 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u3("https://www.boost.org:/"); |
| 1924 |
1/1✓ Branch 1 taken 1 time.
|
1 | normalize_http_url(u3); |
| 1925 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u4("https://www.boost.org:80/"); |
| 1926 |
1/1✓ Branch 1 taken 1 time.
|
1 | normalize_http_url(u4); |
| 1927 | |||
| 1928 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u1.buffer() == "https://www.boost.org/"); |
| 1929 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u2.buffer() == "https://www.boost.org/"); |
| 1930 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u3.buffer() == "https://www.boost.org/"); |
| 1931 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u4.buffer() == "https://www.boost.org/"); |
| 1932 | // end::snippet_normalizing_5[] | ||
| 1933 | 1 | } | |
| 1934 | 1 | } | |
| 1935 | |||
| 1936 | void | ||
| 1937 | 1 | decode_with_token() | |
| 1938 | { | ||
| 1939 | { | ||
| 1940 | // tag::snippet_string_token_1[] | ||
| 1941 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("http://www.example.com/my%20file.txt"); |
| 1942 | 1 | pct_string_view sv = u.encoded_path(); | |
| 1943 |
2/3✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
|
1 | assert(sv == "/my%20file.txt"); |
| 1944 |
1/1✓ Branch 2 taken 1 time.
|
1 | std::string s = u.path(); |
| 1945 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "/my file.txt"); |
| 1946 | // end::snippet_string_token_1[] | ||
| 1947 | 1 | } | |
| 1948 | |||
| 1949 | { | ||
| 1950 | // tag::snippet_string_token_2[] | ||
| 1951 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("http://www.example.com/my%20file.txt"); |
| 1952 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string s = "existing string"; |
| 1953 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.path(string_token::assign_to(s)); |
| 1954 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "/my file.txt"); |
| 1955 | // end::snippet_string_token_2[] | ||
| 1956 | 1 | } | |
| 1957 | |||
| 1958 | { | ||
| 1959 | // tag::snippet_string_token_3[] | ||
| 1960 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("http://www.example.com/my%20file.txt"); |
| 1961 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string s = "existing string"; |
| 1962 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.path(string_token::append_to(s)); |
| 1963 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "existing string/my file.txt"); |
| 1964 | // end::snippet_string_token_3[] | ||
| 1965 | 1 | } | |
| 1966 | |||
| 1967 | { | ||
| 1968 | // tag::snippet_string_token_4[] | ||
| 1969 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u("http://www.example.com/my%20file.txt"); |
| 1970 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string s = "existing string"; |
| 1971 |
1/1✓ Branch 2 taken 1 time.
|
1 | boost::core::string_view sv = u.path(string_token::preserve_size(s)); |
| 1972 |
1/1✓ Branch 3 taken 1 time.
|
1 | assert(sv == "/my file.txt"); |
| 1973 | // end::snippet_string_token_4[] | ||
| 1974 | 1 | } | |
| 1975 | |||
| 1976 | { | ||
| 1977 | #if defined(__cpp_static_assert) && __cpp_static_assert >= 201411L | ||
| 1978 | // tag::snippet_string_token_5[] | ||
| 1979 | static_assert( | ||
| 1980 | string_token::is_token<string_token::return_string>::value); | ||
| 1981 | // end::snippet_string_token_5[] | ||
| 1982 | #endif | ||
| 1983 | } | ||
| 1984 | 1 | } | |
| 1985 | |||
| 1986 | |||
| 1987 | void | ||
| 1988 | 1 | encoding() | |
| 1989 | { | ||
| 1990 | { | ||
| 1991 | // tag::snippet_encoding_1[] | ||
| 1992 | 1 | std::string s = encode("hello world!", unreserved_chars); | |
| 1993 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "hello%20world%21"); |
| 1994 | // end::snippet_encoding_1[] | ||
| 1995 | 1 | } | |
| 1996 | |||
| 1997 | { | ||
| 1998 | // tag::snippet_encoding_2[] | ||
| 1999 | 1 | encoding_opts opt; | |
| 2000 | 1 | opt.space_as_plus = true; | |
| 2001 | 1 | std::string s = encode("msg=hello world", pchars, opt); | |
| 2002 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "msg=hello+world"); |
| 2003 | // end::snippet_encoding_2[] | ||
| 2004 | 1 | } | |
| 2005 | |||
| 2006 | { | ||
| 2007 | // tag::snippet_encoding_3[] | ||
| 2008 | 1 | std::string s; | |
| 2009 | 1 | encode("hello ", pchars, {}, string_token::assign_to(s)); | |
| 2010 | 1 | encode("world", pchars, {}, string_token::append_to(s)); | |
| 2011 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "hello%20world"); |
| 2012 | // end::snippet_encoding_3[] | ||
| 2013 | 1 | } | |
| 2014 | |||
| 2015 | { | ||
| 2016 | // tag::snippet_encoding_4[] | ||
| 2017 | 1 | boost::core::string_view e = "hello world"; | |
| 2018 | 1 | std::string s; | |
| 2019 |
1/1✓ Branch 3 taken 1 time.
|
1 | s.reserve(encoded_size(e, pchars)); |
| 2020 | 1 | encode(e, pchars, {}, string_token::assign_to(s)); | |
| 2021 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "hello%20world"); |
| 2022 | // end::snippet_encoding_4[] | ||
| 2023 | 1 | } | |
| 2024 | |||
| 2025 | { | ||
| 2026 | // tag::snippet_encoding_5[] | ||
| 2027 | 1 | boost::core::string_view e = "hello world"; | |
| 2028 | 1 | std::string s; | |
| 2029 |
1/1✓ Branch 3 taken 1 time.
|
1 | s.resize(encoded_size(e, pchars)); |
| 2030 |
1/1✓ Branch 3 taken 1 time.
|
1 | encode(&s[0], s.size(), e, pchars); |
| 2031 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(s == "hello%20world"); |
| 2032 | // end::snippet_encoding_5[] | ||
| 2033 | 1 | } | |
| 2034 | |||
| 2035 | { | ||
| 2036 | // tag::snippet_encoding_6[] | ||
| 2037 |
1/1✓ Branch 1 taken 1 time.
|
1 | pct_string_view sv = "hello%20world"; |
| 2038 |
2/3✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
|
1 | assert(sv == "hello%20world"); |
| 2039 | // end::snippet_encoding_6[] | ||
| 2040 | } | ||
| 2041 | |||
| 2042 | { | ||
| 2043 | // tag::snippet_encoding_7[] | ||
| 2044 | boost::system::result<pct_string_view> rs = | ||
| 2045 | 1 | make_pct_string_view("hello%20world"); | |
| 2046 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(rs.has_value()); |
| 2047 |
1/1✓ Branch 2 taken 1 time.
|
1 | pct_string_view sv = rs.value(); |
| 2048 |
2/3✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
|
1 | assert(sv == "hello%20world"); |
| 2049 | // end::snippet_encoding_7[] | ||
| 2050 | } | ||
| 2051 | |||
| 2052 | { | ||
| 2053 | // tag::snippet_encoding_8[] | ||
| 2054 |
1/1✓ Branch 1 taken 1 time.
|
1 | pct_string_view s = "path/to/file"; |
| 2055 | 1 | url u; | |
| 2056 |
1/1✓ Branch 1 taken 1 time.
|
1 | u.set_encoded_path(s); |
| 2057 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "path/to/file"); |
| 2058 | // end::snippet_encoding_8[] | ||
| 2059 | 1 | } | |
| 2060 | |||
| 2061 | { | ||
| 2062 | // tag::snippet_encoding_9[] | ||
| 2063 | 1 | url u; | |
| 2064 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | u.set_encoded_path("path/to/file"); |
| 2065 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "path/to/file"); |
| 2066 | // end::snippet_encoding_9[] | ||
| 2067 | 1 | } | |
| 2068 | |||
| 2069 | { | ||
| 2070 | // tag::snippet_encoding_10[] | ||
| 2071 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view uv("path/to/file"); |
| 2072 | 1 | url u; | |
| 2073 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.set_encoded_path(uv.encoded_path()); |
| 2074 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "path/to/file"); |
| 2075 | // end::snippet_encoding_10[] | ||
| 2076 | 1 | } | |
| 2077 | |||
| 2078 | { | ||
| 2079 | // tag::snippet_encoding_11[] | ||
| 2080 |
1/1✓ Branch 1 taken 1 time.
|
1 | pct_string_view es("hello%20world"); |
| 2081 |
2/3✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
|
1 | assert(es == "hello%20world"); |
| 2082 | |||
| 2083 |
1/1✓ Branch 2 taken 1 time.
|
1 | decode_view dv("hello%20world"); |
| 2084 |
2/3✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
|
1 | assert(dv == "hello world"); |
| 2085 | // end::snippet_encoding_11[] | ||
| 2086 | } | ||
| 2087 | |||
| 2088 | { | ||
| 2089 | // tag::snippet_encoding_12[] | ||
| 2090 | boost::system::result<pct_string_view> rs = | ||
| 2091 | 1 | make_pct_string_view("hello%20world"); | |
| 2092 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(rs.has_value()); |
| 2093 |
1/1✓ Branch 2 taken 1 time.
|
1 | pct_string_view s = rs.value(); |
| 2094 | 1 | decode_view dv = *s; | |
| 2095 |
2/3✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
|
1 | assert(dv == "hello world"); |
| 2096 | // end::snippet_encoding_12[] | ||
| 2097 | } | ||
| 2098 | |||
| 2099 | { | ||
| 2100 | // tag::snippet_encoding_13[] | ||
| 2101 | url_view u = | ||
| 2102 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | parse_relative_ref("user/john%20doe/profile%20photo.jpg").value(); |
| 2103 | std::vector<std::string> route = | ||
| 2104 |
1/1✓ Branch 1 taken 1 time.
|
2 | {"user", "john doe", "profile photo.jpg"}; |
| 2105 | 1 | auto segs = u.encoded_segments(); | |
| 2106 | 1 | auto it0 = segs.begin(); | |
| 2107 | 1 | auto end0 = segs.end(); | |
| 2108 | 1 | auto it1 = route.begin(); | |
| 2109 | 1 | auto end1 = route.end(); | |
| 2110 | 1 | while ( | |
| 2111 |
5/6✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
7 | it0 != end0 && |
| 2112 | 3 | it1 != end1) | |
| 2113 | { | ||
| 2114 | 3 | pct_string_view seg0 = *it0; | |
| 2115 | 3 | decode_view dseg0 = *seg0; | |
| 2116 | 3 | boost::core::string_view seg1 = *it1; | |
| 2117 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (dseg0 == seg1) |
| 2118 | { | ||
| 2119 | 3 | ++it0; | |
| 2120 | 3 | ++it1; | |
| 2121 | } | ||
| 2122 | else | ||
| 2123 | { | ||
| 2124 | ✗ | break; | |
| 2125 | } | ||
| 2126 | } | ||
| 2127 |
2/4✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
1 | bool route_match = it0 == end0 && it1 == end1; |
| 2128 |
1/1✓ Branch 1 taken 1 time.
|
1 | assert(route_match); |
| 2129 | // end::snippet_encoding_13[] | ||
| 2130 | 1 | } | |
| 2131 | |||
| 2132 | { | ||
| 2133 | // tag::snippet_encoding_14[] | ||
| 2134 |
1/1✓ Branch 1 taken 1 time.
|
1 | pct_string_view s = "user/john%20doe/profile%20photo.jpg"; |
| 2135 | 1 | std::string buf; | |
| 2136 |
1/1✓ Branch 2 taken 1 time.
|
1 | buf.resize(s.decoded_size()); |
| 2137 |
1/1✓ Branch 3 taken 1 time.
|
1 | s.decode({}, string_token::assign_to(buf)); |
| 2138 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(buf == "user/john doe/profile photo.jpg"); |
| 2139 | // end::snippet_encoding_14[] | ||
| 2140 | 1 | } | |
| 2141 | 1 | } | |
| 2142 | |||
| 2143 | void | ||
| 2144 | 1 | decoding_helpers() | |
| 2145 | { | ||
| 2146 | { | ||
| 2147 | // tag::snippet_decoding_helpers_1[] | ||
| 2148 | 1 | boost::core::string_view encoded = "name%3Dboost+url"; | |
| 2149 | 1 | encoding_opts opt; | |
| 2150 | 1 | opt.space_as_plus = true; | |
| 2151 | |||
| 2152 |
1/1✓ Branch 3 taken 1 time.
|
1 | auto const needed = decoded_size(encoded).value(); |
| 2153 | 1 | std::string buffer; | |
| 2154 |
1/1✓ Branch 1 taken 1 time.
|
1 | buffer.resize(needed); |
| 2155 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | auto const written = decode(&buffer[0], buffer.size(), encoded, opt).value(); |
| 2156 |
1/1✓ Branch 1 taken 1 time.
|
1 | buffer.resize(written); |
| 2157 | |||
| 2158 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(buffer == "name=boost url"); |
| 2159 | // end::snippet_decoding_helpers_1[] | ||
| 2160 | 1 | } | |
| 2161 | |||
| 2162 | { | ||
| 2163 | // tag::snippet_decoding_helpers_2[] | ||
| 2164 | 1 | encoding_opts opt; | |
| 2165 | 1 | opt.space_as_plus = true; | |
| 2166 | |||
| 2167 |
1/1✓ Branch 5 taken 1 time.
|
1 | auto plain = decode(boost::core::string_view("city%3DSan+Jose"), opt).value(); |
| 2168 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(plain == "city=San Jose"); |
| 2169 | |||
| 2170 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string scratch = "prefix:"; |
| 2171 |
1/1✓ Branch 6 taken 1 time.
|
1 | decode(boost::core::string_view("value%2F42"), {}, string_token::append_to(scratch)).value(); |
| 2172 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(scratch == "prefix:value/42"); |
| 2173 | // end::snippet_decoding_helpers_2[] | ||
| 2174 | 1 | } | |
| 2175 | 1 | } | |
| 2176 | |||
| 2177 | void | ||
| 2178 | 1 | readme_snippets() | |
| 2179 | { | ||
| 2180 | { | ||
| 2181 | // Parse a URL. This allocates no memory. The view | ||
| 2182 | // references the character buffer without taking ownership. | ||
| 2183 | // | ||
| 2184 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view uv( "https://www.example.com/path/to/file.txt?id=1001&name=John%20Doe&results=full" ); |
| 2185 | |||
| 2186 | // Print the query parameters with percent-decoding applied | ||
| 2187 | // | ||
| 2188 |
3/3✓ Branch 4 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 1 time.
|
4 | for( auto v : uv.params() ) |
| 2189 | { | ||
| 2190 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | std::cout << v.key << "=" << v.value << " "; |
| 2191 | 3 | } | |
| 2192 | |||
| 2193 |
2/2✓ Branch 11 taken 1 time.
✓ Branch 14 taken 1 time.
|
1 | BOOST_TEST(equal_range( |
| 2194 | uv.params(), | ||
| 2195 | { | ||
| 2196 | param_view{"id", "1001", true}, | ||
| 2197 | param_view{"name", "John Doe", true}, | ||
| 2198 | param_view{"results", "full", true} | ||
| 2199 | })); | ||
| 2200 | |||
| 2201 | // Prints: id=1001 name=John Doe results=full | ||
| 2202 | |||
| 2203 | // Create a modifiable copy of `uv`, with ownership of the buffer | ||
| 2204 | // | ||
| 2205 |
1/1✓ Branch 1 taken 1 time.
|
1 | url u = uv; |
| 2206 | |||
| 2207 | // Change some elements in the URL | ||
| 2208 | // | ||
| 2209 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.set_scheme( "http" ) |
| 2210 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | .set_encoded_host( "boost.org" ) |
| 2211 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | .set_encoded_path( "/index.htm" ) |
| 2212 | 1 | .remove_query() | |
| 2213 | 1 | .remove_fragment() | |
| 2214 |
1/1✓ Branch 4 taken 1 time.
|
1 | .params().append( {"key", "value"} ); |
| 2215 | |||
| 2216 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << u; |
| 2217 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.buffer() == "http://boost.org/index.htm?key=value"); |
| 2218 | 1 | } | |
| 2219 | |||
| 2220 | { | ||
| 2221 | boost::core::string_view s = | ||
| 2222 | 1 | "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor"; | |
| 2223 | { | ||
| 2224 |
1/1✓ Branch 1 taken 1 time.
|
1 | boost::system::result<url_view> r = parse_uri( s ); |
| 2225 |
1/1✓ Branch 2 taken 1 time.
|
1 | BOOST_TEST(r.has_value()); |
| 2226 | } | ||
| 2227 | |||
| 2228 | { | ||
| 2229 |
1/1✓ Branch 1 taken 1 time.
|
1 | boost::system::result<url_view> r = parse_uri( s ); |
| 2230 |
1/1✓ Branch 2 taken 1 time.
|
1 | url_view u = r.value(); |
| 2231 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST(!u.buffer().empty()); |
| 2232 | } | ||
| 2233 | |||
| 2234 | { | ||
| 2235 |
1/1✓ Branch 1 taken 1 time.
|
1 | boost::system::result<url_view> r = parse_uri( s ); |
| 2236 | 1 | url_view u = *r; | |
| 2237 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST(!u.buffer().empty()); |
| 2238 | } | ||
| 2239 | } | ||
| 2240 | |||
| 2241 | { | ||
| 2242 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); |
| 2243 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "https"); |
| 2244 |
1/1✓ Branch 5 taken 1 time.
|
1 | assert(u.authority().buffer() == "user:pass@example.com:443"); |
| 2245 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.userinfo() == "user:pass"); |
| 2246 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.user() == "user"); |
| 2247 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.password() == "pass"); |
| 2248 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.host() == "example.com"); |
| 2249 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.port() == "443"); |
| 2250 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "/path/to/my-file.txt"); |
| 2251 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.query() == "id=42&name=John Doe+Jingleheimer-Schmidt"); |
| 2252 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.fragment() == "page anchor"); |
| 2253 | } | ||
| 2254 | |||
| 2255 | { | ||
| 2256 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); |
| 2257 |
3/3✓ Branch 4 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 1 time.
|
4 | for (auto seg: u.segments()) |
| 2258 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << seg << "\n"; |
| 2259 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << "\n"; |
| 2260 | |||
| 2261 |
3/3✓ Branch 4 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1 time.
|
3 | for (auto param: u.params()) |
| 2262 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | std::cout << param.key << ": " << param.value << "\n"; |
| 2263 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::cout << "\n"; |
| 2264 | } | ||
| 2265 | |||
| 2266 | { | ||
| 2267 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); |
| 2268 |
1/1✓ Branch 2 taken 1 time.
|
1 | std::string h = u.host(); |
| 2269 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(h == "example.com"); |
| 2270 | 1 | } | |
| 2271 | |||
| 2272 | { | ||
| 2273 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); |
| 2274 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string h2 = "host: "; |
| 2275 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.host(string_token::append_to(h2)); |
| 2276 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(h2 == "host: example.com"); |
| 2277 | 1 | } | |
| 2278 | |||
| 2279 | { | ||
| 2280 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u = parse_uri( "http://www.example.com" ).value(); |
| 2281 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.fragment().empty()); |
| 2282 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u.has_fragment()); |
| 2283 | } | ||
| 2284 | |||
| 2285 | { | ||
| 2286 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url_view u = parse_uri( "http://www.example.com/#" ).value(); |
| 2287 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.fragment().empty()); |
| 2288 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(u.has_fragment()); |
| 2289 | } | ||
| 2290 | |||
| 2291 | { | ||
| 2292 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); |
| 2293 | std::cout << | ||
| 2294 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | "url : " << u << "\n" |
| 2295 | "scheme : " << u.scheme() << "\n" | ||
| 2296 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "authority : " << u.encoded_authority() << "\n" |
| 2297 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "userinfo : " << u.encoded_userinfo() << "\n" |
| 2298 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "user : " << u.encoded_user() << "\n" |
| 2299 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "password : " << u.encoded_password() << "\n" |
| 2300 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "host : " << u.encoded_host() << "\n" |
| 2301 | "port : " << u.port() << "\n" | ||
| 2302 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 12 taken 1 time.
|
1 | "path : " << u.encoded_path() << "\n" |
| 2303 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | "query : " << u.encoded_query() << "\n" |
| 2304 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | "fragment : " << u.encoded_fragment() << "\n"; |
| 2305 | } | ||
| 2306 | |||
| 2307 | { | ||
| 2308 |
1/1✓ Branch 2 taken 1 time.
|
1 | decode_view dv("id=42&name=John%20Doe%20Jingleheimer%2DSchmidt"); |
| 2309 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << dv << "\n"; |
| 2310 | } | ||
| 2311 | |||
| 2312 | { | ||
| 2313 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u1 = parse_uri( "https://www.example.com" ).value(); |
| 2314 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u2 = parse_uri( "https://boost.org" ).value(); |
| 2315 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | u1.set_host(u2.host()); |
| 2316 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | BOOST_TEST(u1.host() == u2.host()); |
| 2317 | 1 | } | |
| 2318 | |||
| 2319 | { | ||
| 2320 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); |
| 2321 | 1 | boost::filesystem::path p; | |
| 2322 |
3/3✓ Branch 4 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 1 time.
|
4 | for (auto seg: u.segments()) |
| 2323 | 6 | p.append(seg.begin(), seg.end()); | |
| 2324 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | std::cout << "path: " << p << "\n"; |
| 2325 | 1 | } | |
| 2326 | |||
| 2327 | { | ||
| 2328 | auto match = []( | ||
| 2329 | std::vector<std::string> const& route, | ||
| 2330 | url_view u) | ||
| 2331 | { | ||
| 2332 | auto segs = u.segments(); | ||
| 2333 | if (route.size() != segs.size()) | ||
| 2334 | return false; | ||
| 2335 | return std::equal( | ||
| 2336 | route.begin(), | ||
| 2337 | route.end(), | ||
| 2338 | segs.begin()); | ||
| 2339 | }; | ||
| 2340 | boost::ignore_unused(match); | ||
| 2341 | } | ||
| 2342 | |||
| 2343 | { | ||
| 2344 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.example.com/community/reviews.html" ); |
| 2345 | 1 | auto handle_route = []( | |
| 2346 | std::vector<std::string> const&, | ||
| 2347 | url_view) | ||
| 2348 | { | ||
| 2349 | 1 | }; | |
| 2350 | |||
| 2351 | 1 | auto match = []( | |
| 2352 | std::vector<std::string> const& route, | ||
| 2353 | url_view u) | ||
| 2354 | { | ||
| 2355 | 1 | auto segs = u.segments(); | |
| 2356 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
|
1 | if (route.size() != segs.size()) |
| 2357 | ✗ | return false; | |
| 2358 |
1/1✓ Branch 4 taken 1 time.
|
1 | return std::equal( |
| 2359 | route.begin(), | ||
| 2360 | route.end(), | ||
| 2361 | 1 | segs.begin()); | |
| 2362 | }; | ||
| 2363 | |||
| 2364 | std::vector<std::string> route = | ||
| 2365 |
1/1✓ Branch 1 taken 1 time.
|
2 | {"community", "reviews.html"}; |
| 2366 |
2/3✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
1 | if (match(route, u)) |
| 2367 | { | ||
| 2368 | 1 | handle_route(route, u); | |
| 2369 | } | ||
| 2370 | 1 | } | |
| 2371 | |||
| 2372 | { | ||
| 2373 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.example.com/path/to/file.txt" ); |
| 2374 | 1 | segments_encoded_view segs = u.encoded_segments(); | |
| 2375 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for( auto v : segs ) |
| 2376 | { | ||
| 2377 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << v << "\n"; |
| 2378 | } | ||
| 2379 | } | ||
| 2380 | |||
| 2381 | { | ||
| 2382 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.example.com/path/to/my%2dfile.txt" ); |
| 2383 | 1 | segments_encoded_view segs2 = u.encoded_segments(); | |
| 2384 |
2/2✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
|
4 | for( pct_string_view v : segs2 ) |
| 2385 | { | ||
| 2386 | 3 | decode_view dv2 = *v; | |
| 2387 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::cout << dv2 << "\n"; |
| 2388 | } | ||
| 2389 | } | ||
| 2390 | |||
| 2391 | { | ||
| 2392 |
1/1✓ Branch 1 taken 1 time.
|
1 | url_view u( "https://www.example.com/path/to/file.txt?id=42&name=John%20Doe" ); |
| 2393 | 1 | params_encoded_view params_ref = u.encoded_params(); | |
| 2394 | |||
| 2395 |
2/2✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 time.
|
3 | for( auto v : params_ref ) |
| 2396 | { | ||
| 2397 | 2 | decode_view dk(v.key); | |
| 2398 | 2 | decode_view dv3(v.value); | |
| 2399 | std::cout << | ||
| 2400 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | "key = " << dk << |
| 2401 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | ", value = " << dv3 << "\n"; |
| 2402 | } | ||
| 2403 | } | ||
| 2404 | |||
| 2405 | { | ||
| 2406 | 1 | boost::core::string_view s = "https://www.example.com"; | |
| 2407 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | url u = parse_uri( s ).value(); |
| 2408 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST(!u.buffer().empty()); |
| 2409 | 1 | } | |
| 2410 | |||
| 2411 | { | ||
| 2412 | 1 | boost::core::string_view s = "https://www.example.com"; | |
| 2413 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | static_url<1024> u = parse_uri( s ).value(); |
| 2414 |
1/1✓ Branch 3 taken 1 time.
|
1 | BOOST_TEST(!u.buffer().empty()); |
| 2415 | 1 | } | |
| 2416 | |||
| 2417 | { | ||
| 2418 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri( "https://www.example.com" ).value(); |
| 2419 |
1/1✓ Branch 2 taken 1 time.
|
1 | u.set_scheme( "https" ); |
| 2420 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "https"); |
| 2421 | 1 | } | |
| 2422 | |||
| 2423 | { | ||
| 2424 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri( "https://www.example.com" ).value(); |
| 2425 |
1/1✓ Branch 1 taken 1 time.
|
1 | u.set_scheme_id( scheme::https ); // equivalent to u.set_scheme( "https" ); |
| 2426 |
1/1✓ Branch 4 taken 1 time.
|
1 | BOOST_TEST(u.scheme() == "https"); |
| 2427 | 1 | } | |
| 2428 | |||
| 2429 | { | ||
| 2430 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri( "https://user:pass@example.com:443" ).value(); |
| 2431 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | u.set_host_ipv4( ipv4_address( "192.168.0.1" ) ) |
| 2432 |
1/1✓ Branch 1 taken 1 time.
|
1 | .set_port_number( 8080 ) |
| 2433 | 1 | .remove_userinfo(); | |
| 2434 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << u << "\n"; |
| 2435 | 1 | } | |
| 2436 | |||
| 2437 | { | ||
| 2438 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
|
1 | url u = parse_uri( "http://www.example.com/?name=John" ).value(); |
| 2439 | 1 | params_ref p = u.params(); | |
| 2440 |
1/1✓ Branch 6 taken 1 time.
|
1 | p.replace(p.find("name"), {"name", "John Doe"}); |
| 2441 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | std::cout << u << "\n"; |
| 2442 | 1 | } | |
| 2443 | |||
| 2444 | // I have spent a lot of time on this and have no | ||
| 2445 | // idea how to fix this bug in GCC 4.8 and GCC 5.0 | ||
| 2446 | // without help from the pros. | ||
| 2447 | #if !BOOST_WORKAROUND( BOOST_GCC_VERSION, < 60000 ) | ||
| 2448 | { | ||
| 2449 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{}://{}:{}/rfc/{}", "https", "www.ietf.org", 80, "rfc2396.txt"); |
| 2450 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.ietf.org:80/rfc/rfc2396.txt"); |
| 2451 | 1 | } | |
| 2452 | |||
| 2453 | { | ||
| 2454 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("https://{}/{}", "www.boost.org", "Hello world!"); |
| 2455 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.boost.org/Hello%20world!"); |
| 2456 | 1 | } | |
| 2457 | |||
| 2458 | { | ||
| 2459 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{}:{}", "mailto", "someone@example.com"); |
| 2460 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "mailto:someone@example.com"); |
| 2461 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.scheme() == "mailto"); |
| 2462 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "someone@example.com"); |
| 2463 | 1 | } | |
| 2464 | |||
| 2465 | { | ||
| 2466 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{}{}", "mailto:", "someone@example.com"); |
| 2467 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "mailto%3Asomeone@example.com"); |
| 2468 |
1/1✓ Branch 2 taken 1 time.
|
1 | assert(!u.has_scheme()); |
| 2469 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | assert(u.path() == "mailto:someone@example.com"); |
| 2470 |
2/3✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
|
1 | assert(u.encoded_path() == "mailto%3Asomeone@example.com"); |
| 2471 | 1 | } | |
| 2472 | |||
| 2473 | { | ||
| 2474 | 1 | static_url<50> u; | |
| 2475 |
1/1✓ Branch 2 taken 1 time.
|
1 | format_to(u, "{}://{}:{}/rfc/{}", "https", "www.ietf.org", 80, "rfc2396.txt"); |
| 2476 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.ietf.org:80/rfc/rfc2396.txt"); |
| 2477 | 1 | } | |
| 2478 | |||
| 2479 | { | ||
| 2480 |
1/1✓ Branch 2 taken 1 time.
|
1 | url u = format("{0}://{2}:{1}/{3}{4}{3}", "https", 80, "www.ietf.org", "abra", "cad"); |
| 2481 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://www.ietf.org:80/abracadabra"); |
| 2482 | 1 | } | |
| 2483 | |||
| 2484 | { | ||
| 2485 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
|
1 | url u = format("https://example.com/~{username}", arg("username", "mark")); |
| 2486 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://example.com/~mark"); |
| 2487 | 1 | } | |
| 2488 | |||
| 2489 | { | ||
| 2490 | 1 | boost::core::string_view fmt = "{scheme}://{host}:{port}/{dir}/{file}"; | |
| 2491 |
6/6✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 18 taken 1 time.
✓ Branch 21 taken 1 time.
|
1 | url u = format(fmt, {{"scheme", "https"}, {"port", 80}, {"host", "example.com"}, {"dir", "path/to"}, {"file", "file.txt"}}); |
| 2492 |
1/1✓ Branch 4 taken 1 time.
|
1 | assert(u.buffer() == "https://example.com:80/path/to/file.txt"); |
| 2493 | 1 | } | |
| 2494 | #endif | ||
| 2495 | 1 | } | |
| 2496 | |||
| 2497 | // tag::snippet_using_static_pool_1[] | ||
| 2498 | // VFALCO NOPE | ||
| 2499 | // end::snippet_using_static_pool_1[] | ||
| 2500 | |||
| 2501 | namespace { | ||
| 2502 | |||
| 2503 | class cout_redirect | ||
| 2504 | { | ||
| 2505 | std::ostream& os_; | ||
| 2506 | std::streambuf* old_; | ||
| 2507 | |||
| 2508 | public: | ||
| 2509 | 13 | cout_redirect( | |
| 2510 | std::ostream& os, | ||
| 2511 | std::streambuf* newbuf) noexcept | ||
| 2512 | 13 | : os_(os) | |
| 2513 | 13 | , old_(os.rdbuf(newbuf)) | |
| 2514 | { | ||
| 2515 | 13 | } | |
| 2516 | |||
| 2517 | 13 | ~cout_redirect() | |
| 2518 | { | ||
| 2519 | 13 | os_.rdbuf(old_); | |
| 2520 | 13 | } | |
| 2521 | }; | ||
| 2522 | |||
| 2523 | void | ||
| 2524 | 13 | run_silent(void (*fn)()) | |
| 2525 | { | ||
| 2526 |
1/1✓ Branch 1 taken 13 times.
|
13 | std::ostringstream oss; |
| 2527 | 13 | cout_redirect guard(std::cout, oss.rdbuf()); | |
| 2528 | boost::ignore_unused(guard); | ||
| 2529 |
1/1✓ Branch 1 taken 13 times.
|
13 | fn(); |
| 2530 | 13 | } | |
| 2531 | |||
| 2532 | } // namespace | ||
| 2533 | |||
| 2534 | namespace boost { | ||
| 2535 | namespace urls { | ||
| 2536 | |||
| 2537 | class snippets_test | ||
| 2538 | { | ||
| 2539 | public: | ||
| 2540 | void | ||
| 2541 | 1 | run() | |
| 2542 | { | ||
| 2543 | 1 | run_silent(&using_url_views); | |
| 2544 | 1 | run_silent(&using_urls); | |
| 2545 | 1 | run_silent(&parsing_urls); | |
| 2546 | 1 | parsing_components(); | |
| 2547 | 1 | formatting_components(); | |
| 2548 | 1 | run_silent(&parsing_scheme); | |
| 2549 | 1 | run_silent(&parsing_authority); | |
| 2550 | 1 | run_silent(&parsing_path); | |
| 2551 | 1 | run_silent(&parsing_query); | |
| 2552 | 1 | run_silent(&parsing_fragment); | |
| 2553 | 1 | run_silent(&using_modifying); | |
| 2554 | 1 | run_silent(&grammar_parse); | |
| 2555 | 1 | run_silent(&grammar_customization); | |
| 2556 | 1 | run_silent(&modifying_path); | |
| 2557 | 1 | normalizing(); | |
| 2558 | 1 | decode_with_token(); | |
| 2559 | 1 | encoding(); | |
| 2560 | 1 | decoding_helpers(); | |
| 2561 | 1 | run_silent(&readme_snippets); | |
| 2562 | |||
| 2563 | 1 | BOOST_TEST_PASS(); | |
| 2564 | 1 | } | |
| 2565 | }; | ||
| 2566 | |||
| 2567 | TEST_SUITE(snippets_test, "boost.url.snippets"); | ||
| 2568 | |||
| 2569 | } // urls | ||
| 2570 | } // boost | ||
| 2571 |