| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/url | ||
| 8 | // | ||
| 9 | |||
| 10 | |||
| 11 | #include <boost/url/detail/config.hpp> | ||
| 12 | #include "hier_part_rule.hpp" | ||
| 13 | #include "boost/url/rfc/detail/path_rules.hpp" | ||
| 14 | #include <boost/url/grammar/parse.hpp> | ||
| 15 | #include <boost/url/grammar/parse.hpp> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace urls { | ||
| 19 | namespace detail { | ||
| 20 | |||
| 21 | auto | ||
| 22 | 2249 | hier_part_rule_t:: | |
| 23 | parse( | ||
| 24 | char const*& it, | ||
| 25 | char const* const end | ||
| 26 | ) const noexcept -> | ||
| 27 | system::result<value_type> | ||
| 28 | { | ||
| 29 | 2249 | value_type t; | |
| 30 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 2205 times.
|
2249 | if(it == end) |
| 31 | { | ||
| 32 | // path-empty | ||
| 33 | 44 | return t; | |
| 34 | } | ||
| 35 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 2169 times.
|
2205 | if(end - it == 1) |
| 36 | { | ||
| 37 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 10 times.
|
36 | if(*it == '/') |
| 38 | { | ||
| 39 | // path-absolute | ||
| 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 | // path-rootless | ||
| 47 | 10 | auto rv = grammar::parse( | |
| 48 | it, end, segment_rule); | ||
| 49 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if(! rv) |
| 50 | ✗ | return rv.error(); | |
| 51 | 10 | t.path = *rv; | |
| 52 | 10 | t.segment_count = !t.path.empty(); | |
| 53 | 10 | return t; | |
| 54 | } | ||
| 55 |
2/2✓ Branch 0 taken 1571 times.
✓ Branch 1 taken 598 times.
|
2169 | if( it[0] == '/' && |
| 56 |
2/2✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 96 times.
|
1571 | it[1] == '/') |
| 57 | { | ||
| 58 | // "//" authority | ||
| 59 | 1475 | it += 2; | |
| 60 | auto rv = grammar::parse( | ||
| 61 | 1475 | it, end, authority_rule); | |
| 62 |
2/2✓ Branch 1 taken 30 times.
✓ Branch 2 taken 1445 times.
|
1475 | if(! rv) |
| 63 | 30 | return rv.error(); | |
| 64 | 1445 | t.authority = *rv; | |
| 65 | 1445 | t.has_authority = true; | |
| 66 |
2/2✓ Branch 1 taken 1445 times.
✓ Branch 2 taken 30 times.
|
1475 | } |
| 67 | // the authority requires an absolute path | ||
| 68 | // or an empty path | ||
| 69 |
2/2✓ Branch 0 taken 1720 times.
✓ Branch 1 taken 419 times.
|
2139 | if(it == end || ( |
| 70 |
2/2✓ Branch 0 taken 1026 times.
✓ Branch 1 taken 694 times.
|
1720 | t.has_authority && ( |
| 71 |
2/2✓ Branch 0 taken 146 times.
✓ Branch 1 taken 880 times.
|
1026 | *it != '/' && |
| 72 |
2/2✓ Branch 0 taken 103 times.
✓ Branch 1 taken 43 times.
|
146 | *it != '?' && |
| 73 |
2/2✓ Branch 0 taken 89 times.
✓ Branch 1 taken 14 times.
|
103 | *it != '#'))) |
| 74 | { | ||
| 75 | // path-empty | ||
| 76 | 508 | return t; | |
| 77 | } | ||
| 78 | 1631 | auto const it0 = it; | |
| 79 | 1631 | std::size_t dn = 0; | |
| 80 |
2/2✓ Branch 0 taken 655 times.
✓ Branch 1 taken 976 times.
|
1631 | if(*it != '/') |
| 81 | { | ||
| 82 | 655 | auto rv = grammar::parse( | |
| 83 | it, end, segment_rule); | ||
| 84 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 653 times.
|
655 | if(! rv) |
| 85 | 2 | return rv.error(); | |
| 86 |
2/2✓ Branch 2 taken 74 times.
✓ Branch 3 taken 579 times.
|
653 | if(rv->empty()) |
| 87 | 74 | return t; | |
| 88 | 579 | dn += rv->decoded_size(); | |
| 89 | 579 | ++t.segment_count; | |
| 90 | } | ||
| 91 |
2/2✓ Branch 0 taken 2941 times.
✓ Branch 1 taken 1363 times.
|
4304 | while(it != end) |
| 92 | { | ||
| 93 |
2/2✓ Branch 0 taken 1645 times.
✓ Branch 1 taken 1296 times.
|
2941 | if(*it == '/') |
| 94 | { | ||
| 95 | 1645 | ++dn; | |
| 96 | 1645 | ++it; | |
| 97 | 1645 | ++t.segment_count; | |
| 98 | 1645 | continue; | |
| 99 | } | ||
| 100 | 1296 | auto rv = grammar::parse( | |
| 101 | it, end, segment_rule); | ||
| 102 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1292 times.
|
1296 | if(! rv) |
| 103 | 4 | return rv.error(); | |
| 104 |
2/2✓ Branch 2 taken 188 times.
✓ Branch 3 taken 1104 times.
|
1292 | if(rv->empty()) |
| 105 | 188 | break; | |
| 106 | 1104 | dn += rv->decoded_size(); | |
| 107 | } | ||
| 108 | 1551 | t.path = make_pct_string_view_unsafe( | |
| 109 | 1551 | it0, it - it0, dn); | |
| 110 | 1551 | return t; | |
| 111 | 2249 | } | |
| 112 | |||
| 113 | } // detail | ||
| 114 | } // urls | ||
| 115 | } // boost | ||
| 116 | |||
| 117 |