include/boost/url/rfc/detail/impl/hier_part_rule.hpp
98.2% Lines (56/57)
100.0% Functions (1/1)
| Line | TLA | 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 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | ||
| 23 | auto | ||
| 24 | 2432 | 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 | 2432 | value_type t; | |
| 32 | 2432 | if(it == end) | |
| 33 | { | ||
| 34 | // path-empty | ||
| 35 | 44 | return t; | |
| 36 | } | ||
| 37 | 2388 | if(end - it == 1) | |
| 38 | { | ||
| 39 | 36 | if(*it == '/') | |
| 40 | { | ||
| 41 | // path-absolute | ||
| 42 | 26 | t.path = make_pct_string_view_unsafe( | |
| 43 | it, 1, 1); | ||
| 44 | 26 | t.segment_count = 1; | |
| 45 | 26 | ++it; | |
| 46 | 26 | return t; | |
| 47 | } | ||
| 48 | // path-rootless | ||
| 49 | 10 | auto rv = grammar::parse( | |
| 50 | it, end, segment_rule); | ||
| 51 | 10 | if(! rv) | |
| 52 | ✗ | return rv.error(); | |
| 53 | 10 | t.path = *rv; | |
| 54 | 10 | t.segment_count = !t.path.empty(); | |
| 55 | 10 | return t; | |
| 56 | } | ||
| 57 | 2352 | if( it[0] == '/' && | |
| 58 | 1741 | it[1] == '/') | |
| 59 | { | ||
| 60 | // "//" authority | ||
| 61 | 1643 | it += 2; | |
| 62 | auto rv = grammar::parse( | ||
| 63 | 1643 | it, end, authority_rule); | |
| 64 | 1643 | if(! rv) | |
| 65 | 31 | return rv.error(); | |
| 66 | 1612 | t.authority = *rv; | |
| 67 | 1612 | t.has_authority = true; | |
| 68 | 1643 | } | |
| 69 | // the authority requires an absolute path | ||
| 70 | // or an empty path | ||
| 71 | 2321 | if(it == end || ( | |
| 72 | 1869 | t.has_authority && ( | |
| 73 | 1160 | *it != '/' && | |
| 74 | 150 | *it != '?' && | |
| 75 | 105 | *it != '#'))) | |
| 76 | { | ||
| 77 | // path-empty | ||
| 78 | 541 | return t; | |
| 79 | } | ||
| 80 | 1780 | auto const it0 = it; | |
| 81 | 1780 | std::size_t dn = 0; | |
| 82 | 1780 | if(*it != '/') | |
| 83 | { | ||
| 84 | 672 | auto rv = grammar::parse( | |
| 85 | it, end, segment_rule); | ||
| 86 | 672 | if(! rv) | |
| 87 | 2 | return rv.error(); | |
| 88 | 670 | if(rv->empty()) | |
| 89 | 79 | return t; | |
| 90 | 591 | dn += rv->decoded_size(); | |
| 91 | 591 | ++t.segment_count; | |
| 92 | } | ||
| 93 | 4957 | while(it != end) | |
| 94 | { | ||
| 95 | 3500 | if(*it == '/') | |
| 96 | { | ||
| 97 | 1919 | ++dn; | |
| 98 | 1919 | ++it; | |
| 99 | 1919 | ++t.segment_count; | |
| 100 | 1919 | continue; | |
| 101 | } | ||
| 102 | 1581 | auto rv = grammar::parse( | |
| 103 | it, end, segment_rule); | ||
| 104 | 1581 | if(! rv) | |
| 105 | 4 | return rv.error(); | |
| 106 | 1577 | if(rv->empty()) | |
| 107 | 238 | break; | |
| 108 | 1339 | dn += rv->decoded_size(); | |
| 109 | } | ||
| 110 | 1695 | t.path = make_pct_string_view_unsafe( | |
| 111 | 1695 | it0, it - it0, dn); | |
| 112 | 1695 | return t; | |
| 113 | 2432 | } | |
| 114 | |||
| 115 | } // detail | ||
| 116 | } // urls | ||
| 117 | } // boost | ||
| 118 | |||
| 119 | |||
| 120 | #endif | ||
| 121 |