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 | #ifndef BOOST_URL_RFC_DETAIL_IMPL_RELATIVE_PART_RULE_IPP | ||
11 | #define BOOST_URL_RFC_DETAIL_IMPL_RELATIVE_PART_RULE_IPP | ||
12 | |||
13 | #include <boost/url/detail/config.hpp> | ||
14 | #include <boost/url/rfc/detail/relative_part_rule.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 | constexpr auto pchars_nc = pchars - ':'; | ||
23 | |||
24 | auto | ||
25 | 1331 | relative_part_rule_t:: | |
26 | parse( | ||
27 | char const*& it, | ||
28 | char const* const end | ||
29 | ) const noexcept -> | ||
30 | system::result<value_type> | ||
31 | { | ||
32 | 2662 | value_type t; | |
33 |
2/2✓ Branch 0 taken 125 times.
✓ Branch 1 taken 1206 times.
|
1331 | if(it == end) |
34 | { | ||
35 | // path-empty | ||
36 | 125 | return t; | |
37 | } | ||
38 |
2/2✓ Branch 0 taken 142 times.
✓ Branch 1 taken 1064 times.
|
1206 | if(end - it == 1) |
39 | { | ||
40 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 64 times.
|
142 | if(*it == '/') |
41 | { | ||
42 | // path-absolute | ||
43 | t.path = make_pct_string_view_unsafe( | ||
44 | 78 | it, 1, 1); | |
45 | 78 | t.segment_count = 1; | |
46 | 78 | ++it; | |
47 | 78 | return t; | |
48 | } | ||
49 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 1 times.
|
64 | if(*it != ':') |
50 | { | ||
51 | // path-noscheme or | ||
52 | // path-empty | ||
53 | auto rv = grammar::parse( | ||
54 | 63 | it, end, segment_rule); | |
55 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
|
63 | if(! rv) |
56 | ✗ | return rv.error(); | |
57 |
2/2✓ Branch 2 taken 29 times.
✓ Branch 3 taken 34 times.
|
63 | if(! rv->empty()) |
58 | { | ||
59 | 29 | t.path = *rv; | |
60 | 29 | t.segment_count = 1; | |
61 | } | ||
62 | } | ||
63 | // path-empty | ||
64 | 64 | return t; | |
65 | } | ||
66 |
2/2✓ Branch 0 taken 523 times.
✓ Branch 1 taken 541 times.
|
1064 | if( it[0] == '/' && |
67 |
2/2✓ Branch 0 taken 244 times.
✓ Branch 1 taken 279 times.
|
523 | it[1] == '/') |
68 | { | ||
69 | // "//" authority | ||
70 | 244 | it += 2; | |
71 | auto rv = grammar::parse( | ||
72 | 244 | it, end, authority_rule); | |
73 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
|
244 | if(! rv) |
74 | ✗ | return rv.error(); | |
75 | 244 | t.authority = *rv; | |
76 | 244 | t.has_authority = true; | |
77 | } | ||
78 |
2/2✓ Branch 0 taken 123 times.
✓ Branch 1 taken 941 times.
|
1064 | if(it == end) |
79 | { | ||
80 | // path-empty | ||
81 | 123 | return t; | |
82 | } | ||
83 | 941 | auto const it0 = it; | |
84 | 941 | std::size_t dn = 0; | |
85 |
2/2✓ Branch 0 taken 544 times.
✓ Branch 1 taken 397 times.
|
941 | if(*it != '/') |
86 | { | ||
87 | // segment_nc | ||
88 | auto rv = grammar::parse(it, end, | ||
89 | 544 | pct_encoded_rule(pchars_nc)); | |
90 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 543 times.
|
544 | if(! rv) |
91 | 1 | return rv.error(); | |
92 |
2/2✓ Branch 2 taken 207 times.
✓ Branch 3 taken 336 times.
|
543 | if(rv->empty()) |
93 | 207 | return t; | |
94 | 336 | dn += rv->decoded_size(); | |
95 | 336 | ++t.segment_count; | |
96 |
2/2✓ Branch 0 taken 261 times.
✓ Branch 1 taken 75 times.
|
336 | if( it != end && |
97 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 220 times.
|
261 | *it == ':') |
98 | { | ||
99 | 41 | BOOST_URL_RETURN_EC( | |
100 | grammar::error::mismatch); | ||
101 | } | ||
102 | } | ||
103 |
2/2✓ Branch 0 taken 2438 times.
✓ Branch 1 taken 639 times.
|
3077 | while(it != end) |
104 | { | ||
105 |
2/2✓ Branch 0 taken 1291 times.
✓ Branch 1 taken 1147 times.
|
2438 | if(*it == '/') |
106 | { | ||
107 | 1291 | ++dn; | |
108 | 1291 | ++it; | |
109 | 1291 | ++t.segment_count; | |
110 | 1291 | continue; | |
111 | } | ||
112 | auto rv = grammar::parse( | ||
113 | 1147 | it, end, segment_rule); | |
114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1147 times.
|
1147 | if(! rv) |
115 | ✗ | return rv.error(); | |
116 |
2/2✓ Branch 2 taken 53 times.
✓ Branch 3 taken 1094 times.
|
1147 | if(rv->empty()) |
117 | 53 | break; | |
118 | 1094 | dn += rv->decoded_size(); | |
119 | } | ||
120 | t.path = make_pct_string_view_unsafe( | ||
121 | 692 | it0, it - it0, dn); | |
122 | 692 | return t; | |
123 | } | ||
124 | |||
125 | } // detail | ||
126 | } // urls | ||
127 | } // boost | ||
128 | |||
129 | #endif | ||
130 |