include/boost/url/rfc/detail/impl/relative_part_rule.hpp
95.0% Lines (57/60)
100.0% Functions (1/1)
92.1% Branches (35/38)
include/boost/url/rfc/detail/impl/relative_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_RELATIVE_PART_RULE_HPP | ||
| 12 | #define BOOST_URL_RFC_DETAIL_IMPL_RELATIVE_PART_RULE_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/config.hpp> | ||
| 15 | #include <boost/url/rfc/detail/path_rules.hpp> | ||
| 16 | #include <boost/url/rfc/pct_encoded_rule.hpp> | ||
| 17 | #include <boost/url/rfc/pchars.hpp> | ||
| 18 | #include <boost/url/grammar/error.hpp> | ||
| 19 | #include <boost/url/grammar/parse.hpp> | ||
| 20 | |||
| 21 | namespace boost { | ||
| 22 | namespace urls { | ||
| 23 | namespace detail { | ||
| 24 | |||
| 25 | inline BOOST_URL_CXX20_CONSTEXPR | ||
| 26 | auto | ||
| 27 | 1362 | relative_part_rule_t:: | |
| 28 | parse( | ||
| 29 | char const*& it, | ||
| 30 | char const* const end | ||
| 31 | ) const noexcept -> | ||
| 32 | system::result<value_type> | ||
| 33 | { | ||
| 34 | 1362 | constexpr auto pchars_nc = pchars - ':'; | |
| 35 | |||
| 36 | 1362 | value_type t; | |
| 37 |
2/2✓ Branch 0 taken 126 times.
✓ Branch 1 taken 1236 times.
|
1362 | if(it == end) |
| 38 | { | ||
| 39 | 126 | return t; | |
| 40 | } | ||
| 41 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1092 times.
|
1236 | if(end - it == 1) |
| 42 | { | ||
| 43 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 66 times.
|
144 | if(*it == '/') |
| 44 | { | ||
| 45 | 78 | t.path = make_pct_string_view_unsafe( | |
| 46 | it, 1, 1); | ||
| 47 | 78 | t.segment_count = 1; | |
| 48 | 78 | ++it; | |
| 49 | 78 | return t; | |
| 50 | } | ||
| 51 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 1 time.
|
66 | if(*it != ':') |
| 52 | { | ||
| 53 | 65 | auto rv = grammar::parse( | |
| 54 | it, end, segment_rule); | ||
| 55 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 65 times.
|
65 | if(! rv) |
| 56 | ✗ | return rv.error(); | |
| 57 |
2/2✓ Branch 2 taken 29 times.
✓ Branch 3 taken 36 times.
|
65 | if(! rv->empty()) |
| 58 | { | ||
| 59 | 29 | t.path = *rv; | |
| 60 | 29 | t.segment_count = 1; | |
| 61 | } | ||
| 62 | } | ||
| 63 | 66 | return t; | |
| 64 | } | ||
| 65 |
2/2✓ Branch 0 taken 531 times.
✓ Branch 1 taken 561 times.
|
1092 | if( it[0] == '/' && |
| 66 |
2/2✓ Branch 0 taken 244 times.
✓ Branch 1 taken 287 times.
|
531 | it[1] == '/') |
| 67 | { | ||
| 68 | 244 | it += 2; | |
| 69 | auto rv = grammar::parse( | ||
| 70 | 244 | it, end, authority_rule); | |
| 71 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
|
244 | if(! rv) |
| 72 | ✗ | return rv.error(); | |
| 73 | 244 | t.authority = *rv; | |
| 74 | 244 | t.has_authority = true; | |
| 75 | 244 | } | |
| 76 |
2/2✓ Branch 0 taken 123 times.
✓ Branch 1 taken 969 times.
|
1092 | if(it == end) |
| 77 | { | ||
| 78 | 123 | return t; | |
| 79 | } | ||
| 80 | 969 | auto const it0 = it; | |
| 81 | 969 | std::size_t dn = 0; | |
| 82 |
2/2✓ Branch 0 taken 564 times.
✓ Branch 1 taken 405 times.
|
969 | if(*it != '/') |
| 83 | { | ||
| 84 | 564 | auto rv = grammar::parse(it, end, | |
| 85 | 564 | pct_encoded_rule(pchars_nc)); | |
| 86 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 563 times.
|
564 | if(! rv) |
| 87 | 1 | return rv.error(); | |
| 88 |
2/2✓ Branch 2 taken 215 times.
✓ Branch 3 taken 348 times.
|
563 | if(rv->empty()) |
| 89 | 215 | return t; | |
| 90 | 348 | dn += rv->decoded_size(); | |
| 91 | 348 | ++t.segment_count; | |
| 92 |
2/2✓ Branch 0 taken 273 times.
✓ Branch 1 taken 75 times.
|
348 | if( it != end && |
| 93 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 233 times.
|
273 | *it == ':') |
| 94 | { | ||
| 95 | 40 | BOOST_URL_CONSTEXPR_RETURN_EC( | |
| 96 | grammar::error::mismatch); | ||
| 97 | } | ||
| 98 | } | ||
| 99 |
2/2✓ Branch 0 taken 2541 times.
✓ Branch 1 taken 657 times.
|
3198 | while(it != end) |
| 100 | { | ||
| 101 |
2/2✓ Branch 0 taken 1343 times.
✓ Branch 1 taken 1198 times.
|
2541 | if(*it == '/') |
| 102 | { | ||
| 103 | 1343 | ++dn; | |
| 104 | 1343 | ++it; | |
| 105 | 1343 | ++t.segment_count; | |
| 106 | 1343 | continue; | |
| 107 | } | ||
| 108 | 1198 | auto rv = grammar::parse( | |
| 109 | it, end, segment_rule); | ||
| 110 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1198 times.
|
1198 | if(! rv) |
| 111 | ✗ | return rv.error(); | |
| 112 |
2/2✓ Branch 2 taken 56 times.
✓ Branch 3 taken 1142 times.
|
1198 | if(rv->empty()) |
| 113 | 56 | break; | |
| 114 | 1142 | dn += rv->decoded_size(); | |
| 115 | } | ||
| 116 | 713 | t.path = make_pct_string_view_unsafe( | |
| 117 | 713 | it0, it - it0, dn); | |
| 118 | 713 | return t; | |
| 119 | 1362 | } | |
| 120 | |||
| 121 | } // detail | ||
| 122 | } // urls | ||
| 123 | } // boost | ||
| 124 | |||
| 125 | |||
| 126 | #endif | ||
| 127 |