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 | 7223 | 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 | 7223 | value_type t; | |
| 32 | 7223 | if(it == end) | |
| 33 | { | ||
| 34 | // path-empty | ||
| 35 | 47 | return t; | |
| 36 | } | ||
| 37 | 7176 | if(end - it == 1) | |
| 38 | { | ||
| 39 | 37 | 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 | 11 | auto rv = grammar::parse( | |
| 50 | it, end, segment_rule); | ||
| 51 | 11 | if(! rv) | |
| 52 | ✗ | return rv.error(); | |
| 53 | 11 | t.path = *rv; | |
| 54 | 11 | t.segment_count = !t.path.empty(); | |
| 55 | 11 | return t; | |
| 56 | } | ||
| 57 | 7139 | if( it[0] == '/' && | |
| 58 | 6308 | it[1] == '/') | |
| 59 | { | ||
| 60 | // "//" authority | ||
| 61 | 6210 | it += 2; | |
| 62 | auto rv = grammar::parse( | ||
| 63 | 6210 | it, end, authority_rule); | |
| 64 | 6210 | if(! rv) | |
| 65 | 31 | return rv.error(); | |
| 66 | 6179 | t.authority = *rv; | |
| 67 | 6179 | t.has_authority = true; | |
| 68 | 6210 | } | |
| 69 | // the authority requires an absolute path | ||
| 70 | // or an empty path | ||
| 71 | 7108 | if(it == end || ( | |
| 72 | 6651 | t.has_authority && ( | |
| 73 | 5722 | *it != '/' && | |
| 74 | 151 | *it != '?' && | |
| 75 | 106 | *it != '#'))) | |
| 76 | { | ||
| 77 | // path-empty | ||
| 78 | 547 | return t; | |
| 79 | } | ||
| 80 | 6561 | auto const it0 = it; | |
| 81 | 6561 | std::size_t dn = 0; | |
| 82 | 6561 | if(*it != '/') | |
| 83 | { | ||
| 84 | 892 | auto rv = grammar::parse( | |
| 85 | it, end, segment_rule); | ||
| 86 | 892 | if(! rv) | |
| 87 | 2 | return rv.error(); | |
| 88 | 890 | if(rv->empty()) | |
| 89 | 122 | return t; | |
| 90 | 768 | dn += rv->decoded_size(); | |
| 91 | 768 | ++t.segment_count; | |
| 92 | } | ||
| 93 | 25713 | while(it != end) | |
| 94 | { | ||
| 95 | 23020 | if(*it == '/') | |
| 96 | { | ||
| 97 | 10433 | ++dn; | |
| 98 | 10433 | ++it; | |
| 99 | 10433 | ++t.segment_count; | |
| 100 | 10433 | continue; | |
| 101 | } | ||
| 102 | 12587 | auto rv = grammar::parse( | |
| 103 | it, end, segment_rule); | ||
| 104 | 12587 | if(! rv) | |
| 105 | 11 | return rv.error(); | |
| 106 | 12576 | if(rv->empty()) | |
| 107 | 3733 | break; | |
| 108 | 8843 | dn += rv->decoded_size(); | |
| 109 | } | ||
| 110 | 6426 | t.path = make_pct_string_view_unsafe( | |
| 111 | 6426 | it0, it - it0, dn); | |
| 112 | 6426 | return t; | |
| 113 | 7223 | } | |
| 114 | |||
| 115 | } // detail | ||
| 116 | } // urls | ||
| 117 | } // boost | ||
| 118 | |||
| 119 | |||
| 120 | #endif | ||
| 121 |