include/boost/url/rfc/detail/impl/hier_part_rule.hpp
98.2% Lines (56/57)
100.0% Functions (1/1)
97.4% Branches (37/38)
include/boost/url/rfc/detail/impl/hier_part_rule.hpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | ||
| 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/boostorg/url | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_HPP | ||
| 12 | #define BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/config.hpp> | ||
| 15 | #include <boost/url/rfc/detail/path_rules.hpp> | ||
| 16 | #include <boost/url/grammar/parse.hpp> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace urls { | ||
| 20 | namespace detail { | ||
| 21 | |||
| 22 | inline BOOST_URL_CXX20_CONSTEXPR | ||
| 23 | auto | ||
| 24 | 2430 | hier_part_rule_t:: | |
| 25 | parse( | ||
| 26 | char const*& it, | ||
| 27 | char const* const end | ||
| 28 | ) const noexcept -> | ||
| 29 | system::result<value_type> | ||
| 30 | { | ||
| 31 | 2430 | value_type t; | |
| 32 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 2386 times.
|
2430 | if(it == end) |
| 33 | { | ||
| 34 | 44 | return t; | |
| 35 | } | ||
| 36 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 2350 times.
|
2386 | if(end - it == 1) |
| 37 | { | ||
| 38 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 10 times.
|
36 | if(*it == '/') |
| 39 | { | ||
| 40 | 26 | t.path = make_pct_string_view_unsafe( | |
| 41 | it, 1, 1); | ||
| 42 | 26 | t.segment_count = 1; | |
| 43 | 26 | ++it; | |
| 44 | 26 | return t; | |
| 45 | } | ||
| 46 | 10 | auto rv = grammar::parse( | |
| 47 | it, end, segment_rule); | ||
| 48 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if(! rv) |
| 49 | ✗ | return rv.error(); | |
| 50 | 10 | t.path = *rv; | |
| 51 | 10 | t.segment_count = !t.path.empty(); | |
| 52 | 10 | return t; | |
| 53 | } | ||
| 54 |
2/2✓ Branch 0 taken 1739 times.
✓ Branch 1 taken 611 times.
|
2350 | if( it[0] == '/' && |
| 55 |
2/2✓ Branch 0 taken 1641 times.
✓ Branch 1 taken 98 times.
|
1739 | it[1] == '/') |
| 56 | { | ||
| 57 | 1641 | it += 2; | |
| 58 | auto rv = grammar::parse( | ||
| 59 | 1641 | it, end, authority_rule); | |
| 60 |
2/2✓ Branch 1 taken 30 times.
✓ Branch 2 taken 1611 times.
|
1641 | if(! rv) |
| 61 | 30 | return rv.error(); | |
| 62 | 1611 | t.authority = *rv; | |
| 63 | 1611 | t.has_authority = true; | |
| 64 | 1641 | } | |
| 65 |
2/2✓ Branch 0 taken 1868 times.
✓ Branch 1 taken 452 times.
|
2320 | if(it == end || ( |
| 66 |
2/2✓ Branch 0 taken 1159 times.
✓ Branch 1 taken 709 times.
|
1868 | t.has_authority && ( |
| 67 |
2/2✓ Branch 0 taken 150 times.
✓ Branch 1 taken 1009 times.
|
1159 | *it != '/' && |
| 68 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 45 times.
|
150 | *it != '?' && |
| 69 |
2/2✓ Branch 0 taken 89 times.
✓ Branch 1 taken 16 times.
|
105 | *it != '#'))) |
| 70 | { | ||
| 71 | 541 | return t; | |
| 72 | } | ||
| 73 | 1779 | auto const it0 = it; | |
| 74 | 1779 | std::size_t dn = 0; | |
| 75 |
2/2✓ Branch 0 taken 672 times.
✓ Branch 1 taken 1107 times.
|
1779 | if(*it != '/') |
| 76 | { | ||
| 77 | 672 | auto rv = grammar::parse( | |
| 78 | it, end, segment_rule); | ||
| 79 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 670 times.
|
672 | if(! rv) |
| 80 | 2 | return rv.error(); | |
| 81 |
2/2✓ Branch 2 taken 79 times.
✓ Branch 3 taken 591 times.
|
670 | if(rv->empty()) |
| 82 | 79 | return t; | |
| 83 | 591 | dn += rv->decoded_size(); | |
| 84 | 591 | ++t.segment_count; | |
| 85 | } | ||
| 86 |
2/2✓ Branch 0 taken 3497 times.
✓ Branch 1 taken 1457 times.
|
4954 | while(it != end) |
| 87 | { | ||
| 88 |
2/2✓ Branch 0 taken 1918 times.
✓ Branch 1 taken 1579 times.
|
3497 | if(*it == '/') |
| 89 | { | ||
| 90 | 1918 | ++dn; | |
| 91 | 1918 | ++it; | |
| 92 | 1918 | ++t.segment_count; | |
| 93 | 1918 | continue; | |
| 94 | } | ||
| 95 | 1579 | auto rv = grammar::parse( | |
| 96 | it, end, segment_rule); | ||
| 97 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1575 times.
|
1579 | if(! rv) |
| 98 | 4 | return rv.error(); | |
| 99 |
2/2✓ Branch 2 taken 237 times.
✓ Branch 3 taken 1338 times.
|
1575 | if(rv->empty()) |
| 100 | 237 | break; | |
| 101 | 1338 | dn += rv->decoded_size(); | |
| 102 | } | ||
| 103 | 1694 | t.path = make_pct_string_view_unsafe( | |
| 104 | 1694 | it0, it - it0, dn); | |
| 105 | 1694 | return t; | |
| 106 | 2430 | } | |
| 107 | |||
| 108 | } // detail | ||
| 109 | } // urls | ||
| 110 | } // boost | ||
| 111 | |||
| 112 | |||
| 113 | #endif | ||
| 114 |