98.25% Lines (56/57)
100.00% Functions (1/1)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | |||||
| 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/boostorg/url | 8 | // Official repository: https://github.com/boostorg/url | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_HPP | 11 | #ifndef BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_HPP | |||||
| 12 | #define BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_HPP | 12 | #define BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/url/detail/config.hpp> | 14 | #include <boost/url/detail/config.hpp> | |||||
| 15 | #include <boost/url/rfc/detail/path_rules.hpp> | 15 | #include <boost/url/rfc/detail/path_rules.hpp> | |||||
| 16 | #include <boost/url/grammar/parse.hpp> | 16 | #include <boost/url/grammar/parse.hpp> | |||||
| 17 | 17 | |||||||
| 18 | namespace boost { | 18 | namespace boost { | |||||
| 19 | namespace urls { | 19 | namespace urls { | |||||
| 20 | namespace detail { | 20 | namespace detail { | |||||
| 21 | 21 | |||||||
| 22 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | 22 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | |||||
| 23 | auto | 23 | auto | |||||
| HITCBC | 24 | 7235 | hier_part_rule_t:: | 24 | 7235 | hier_part_rule_t:: | ||
| 25 | parse( | 25 | parse( | |||||
| 26 | char const*& it, | 26 | char const*& it, | |||||
| 27 | char const* const end | 27 | char const* const end | |||||
| 28 | ) const noexcept -> | 28 | ) const noexcept -> | |||||
| 29 | system::result<value_type> | 29 | system::result<value_type> | |||||
| 30 | { | 30 | { | |||||
| HITCBC | 31 | 7235 | value_type t; | 31 | 7235 | value_type t; | ||
| HITCBC | 32 | 7235 | if(it == end) | 32 | 7235 | if(it == end) | ||
| 33 | { | 33 | { | |||||
| 34 | // path-empty | 34 | // path-empty | |||||
| HITCBC | 35 | 47 | return t; | 35 | 47 | return t; | ||
| 36 | } | 36 | } | |||||
| HITCBC | 37 | 7188 | if(end - it == 1) | 37 | 7188 | if(end - it == 1) | ||
| 38 | { | 38 | { | |||||
| HITCBC | 39 | 37 | if(*it == '/') | 39 | 37 | if(*it == '/') | ||
| 40 | { | 40 | { | |||||
| 41 | // path-absolute | 41 | // path-absolute | |||||
| HITCBC | 42 | 26 | t.path = make_pct_string_view_unsafe( | 42 | 26 | t.path = make_pct_string_view_unsafe( | ||
| 43 | it, 1, 1); | 43 | it, 1, 1); | |||||
| HITCBC | 44 | 26 | t.segment_count = 1; | 44 | 26 | t.segment_count = 1; | ||
| HITCBC | 45 | 26 | ++it; | 45 | 26 | ++it; | ||
| HITCBC | 46 | 26 | return t; | 46 | 26 | return t; | ||
| 47 | } | 47 | } | |||||
| 48 | // path-rootless | 48 | // path-rootless | |||||
| HITCBC | 49 | 11 | auto rv = grammar::parse( | 49 | 11 | auto rv = grammar::parse( | ||
| 50 | it, end, segment_rule); | 50 | it, end, segment_rule); | |||||
| HITCBC | 51 | 11 | if(! rv) | 51 | 11 | if(! rv) | ||
| MISUBC | 52 | ✗ | return rv.error(); | 52 | ✗ | return rv.error(); | ||
| HITCBC | 53 | 11 | t.path = *rv; | 53 | 11 | t.path = *rv; | ||
| HITCBC | 54 | 11 | t.segment_count = !t.path.empty(); | 54 | 11 | t.segment_count = !t.path.empty(); | ||
| HITCBC | 55 | 11 | return t; | 55 | 11 | return t; | ||
| 56 | } | 56 | } | |||||
| HITCBC | 57 | 7151 | if( it[0] == '/' && | 57 | 7151 | if( it[0] == '/' && | ||
| HITCBC | 58 | 6320 | it[1] == '/') | 58 | 6320 | it[1] == '/') | ||
| 59 | { | 59 | { | |||||
| 60 | // "//" authority | 60 | // "//" authority | |||||
| HITCBC | 61 | 6210 | it += 2; | 61 | 6210 | it += 2; | ||
| 62 | auto rv = grammar::parse( | 62 | auto rv = grammar::parse( | |||||
| HITCBC | 63 | 6210 | it, end, authority_rule); | 63 | 6210 | it, end, authority_rule); | ||
| HITCBC | 64 | 6210 | if(! rv) | 64 | 6210 | if(! rv) | ||
| HITCBC | 65 | 31 | return rv.error(); | 65 | 31 | return rv.error(); | ||
| HITCBC | 66 | 6179 | t.authority = *rv; | 66 | 6179 | t.authority = *rv; | ||
| HITCBC | 67 | 6179 | t.has_authority = true; | 67 | 6179 | t.has_authority = true; | ||
| HITCBC | 68 | 6210 | } | 68 | 6210 | } | ||
| 69 | // the authority requires an absolute path | 69 | // the authority requires an absolute path | |||||
| 70 | // or an empty path | 70 | // or an empty path | |||||
| HITCBC | 71 | 7120 | if(it == end || ( | 71 | 7120 | if(it == end || ( | ||
| HITCBC | 72 | 6663 | t.has_authority && ( | 72 | 6663 | t.has_authority && ( | ||
| HITCBC | 73 | 5722 | *it != '/' && | 73 | 5722 | *it != '/' && | ||
| HITCBC | 74 | 151 | *it != '?' && | 74 | 151 | *it != '?' && | ||
| HITCBC | 75 | 106 | *it != '#'))) | 75 | 106 | *it != '#'))) | ||
| 76 | { | 76 | { | |||||
| 77 | // path-empty | 77 | // path-empty | |||||
| HITCBC | 78 | 547 | return t; | 78 | 547 | return t; | ||
| 79 | } | 79 | } | |||||
| HITCBC | 80 | 6573 | auto const it0 = it; | 80 | 6573 | auto const it0 = it; | ||
| HITCBC | 81 | 6573 | std::size_t dn = 0; | 81 | 6573 | std::size_t dn = 0; | ||
| HITCBC | 82 | 6573 | if(*it != '/') | 82 | 6573 | if(*it != '/') | ||
| 83 | { | 83 | { | |||||
| HITCBC | 84 | 892 | auto rv = grammar::parse( | 84 | 892 | auto rv = grammar::parse( | ||
| 85 | it, end, segment_rule); | 85 | it, end, segment_rule); | |||||
| HITCBC | 86 | 892 | if(! rv) | 86 | 892 | if(! rv) | ||
| HITCBC | 87 | 2 | return rv.error(); | 87 | 2 | return rv.error(); | ||
| HITCBC | 88 | 890 | if(rv->empty()) | 88 | 890 | if(rv->empty()) | ||
| HITCBC | 89 | 122 | return t; | 89 | 122 | return t; | ||
| HITCBC | 90 | 768 | dn += rv->decoded_size(); | 90 | 768 | dn += rv->decoded_size(); | ||
| HITCBC | 91 | 768 | ++t.segment_count; | 91 | 768 | ++t.segment_count; | ||
| 92 | } | 92 | } | |||||
| HITCBC | 93 | 25801 | while(it != end) | 93 | 25801 | while(it != end) | ||
| 94 | { | 94 | { | |||||
| HITCBC | 95 | 23096 | if(*it == '/') | 95 | 23096 | if(*it == '/') | ||
| 96 | { | 96 | { | |||||
| HITCBC | 97 | 10478 | ++dn; | 97 | 10478 | ++dn; | ||
| HITCBC | 98 | 10478 | ++it; | 98 | 10478 | ++it; | ||
| HITCBC | 99 | 10478 | ++t.segment_count; | 99 | 10478 | ++t.segment_count; | ||
| HITCBC | 100 | 10478 | continue; | 100 | 10478 | continue; | ||
| 101 | } | 101 | } | |||||
| HITCBC | 102 | 12618 | auto rv = grammar::parse( | 102 | 12618 | auto rv = grammar::parse( | ||
| 103 | it, end, segment_rule); | 103 | it, end, segment_rule); | |||||
| HITCBC | 104 | 12618 | if(! rv) | 104 | 12618 | if(! rv) | ||
| HITCBC | 105 | 11 | return rv.error(); | 105 | 11 | return rv.error(); | ||
| HITCBC | 106 | 12607 | if(rv->empty()) | 106 | 12607 | if(rv->empty()) | ||
| HITCBC | 107 | 3733 | break; | 107 | 3733 | break; | ||
| HITCBC | 108 | 8874 | dn += rv->decoded_size(); | 108 | 8874 | dn += rv->decoded_size(); | ||
| 109 | } | 109 | } | |||||
| HITCBC | 110 | 6438 | t.path = make_pct_string_view_unsafe( | 110 | 6438 | t.path = make_pct_string_view_unsafe( | ||
| HITCBC | 111 | 6438 | it0, it - it0, dn); | 111 | 6438 | it0, it - it0, dn); | ||
| HITCBC | 112 | 6438 | return t; | 112 | 6438 | return t; | ||
| HITCBC | 113 | 7235 | } | 113 | 7235 | } | ||
| 114 | 114 | |||||||
| 115 | } // detail | 115 | } // detail | |||||
| 116 | } // urls | 116 | } // urls | |||||
| 117 | } // boost | 117 | } // boost | |||||
| 118 | 118 | |||||||
| 119 | 119 | |||||||
| 120 | #endif | 120 | #endif | |||||