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_IMPL_PCT_ENCODED_RULE_HPP | ||
11 | #define BOOST_URL_RFC_IMPL_PCT_ENCODED_RULE_HPP | ||
12 | |||
13 | #include <boost/url/grammar/charset.hpp> | ||
14 | #include <boost/url/grammar/error.hpp> | ||
15 | #include <boost/url/grammar/hexdig_chars.hpp> | ||
16 | |||
17 | namespace boost { | ||
18 | namespace urls { | ||
19 | |||
20 | namespace detail { | ||
21 | |||
22 | template<class CharSet> | ||
23 | auto | ||
24 | 11415 | parse_encoded( | |
25 | char const*& it, | ||
26 | char const* end, | ||
27 | CharSet const& cs) noexcept -> | ||
28 | system::result<pct_string_view> | ||
29 | { | ||
30 | 11415 | auto const start = it; | |
31 | 11415 | std::size_t n = 0; | |
32 | char const* it0; | ||
33 | 11842 | skip: | |
34 | 11842 | it0 = it; | |
35 | 11842 | it = grammar::find_if_not( | |
36 | it0, end, cs); | ||
37 | 11842 | n += it - it0; | |
38 |
2/2✓ Branch 0 taken 2772 times.
✓ Branch 1 taken 6679 times.
|
11842 | if(it == end) |
39 | 3117 | goto finish; | |
40 |
2/2✓ Branch 0 taken 6272 times.
✓ Branch 1 taken 407 times.
|
8725 | if(*it != '%') |
41 | 8178 | goto finish; | |
42 | 301 | for(;;) | |
43 | { | ||
44 | 848 | ++it; | |
45 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 605 times.
|
848 | if(it == end) |
46 | { | ||
47 | // expected HEXDIG | ||
48 | 18 | BOOST_URL_RETURN_EC( | |
49 | grammar::error::invalid); | ||
50 | } | ||
51 | 830 | auto r = grammar::hexdig_value(*it); | |
52 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 593 times.
|
830 | if(r < 0) |
53 | { | ||
54 | // expected HEXDIG | ||
55 | 16 | BOOST_URL_RETURN_EC( | |
56 | grammar::error::invalid); | ||
57 | } | ||
58 | 814 | ++it; | |
59 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 588 times.
|
814 | if(it == end) |
60 | { | ||
61 | // expected HEXDIG | ||
62 | 6 | BOOST_URL_RETURN_EC( | |
63 | grammar::error::invalid); | ||
64 | } | ||
65 | 808 | r = grammar::hexdig_value(*it); | |
66 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 580 times.
|
808 | if(r < 0) |
67 | { | ||
68 | // expected HEXDIG | ||
69 | 10 | BOOST_URL_RETURN_EC( | |
70 | grammar::error::invalid); | ||
71 | } | ||
72 | 798 | ++n; | |
73 | 798 | ++it; | |
74 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 520 times.
|
798 | if(it == end) |
75 | 70 | break; | |
76 |
2/2✓ Branch 0 taken 308 times.
✓ Branch 1 taken 212 times.
|
728 | if(*it != '%') |
77 | 427 | goto skip; | |
78 | } | ||
79 | 11365 | finish: | |
80 | 11365 | return make_pct_string_view_unsafe( | |
81 | 11365 | start, it - start, n); | |
82 | } | ||
83 | |||
84 | } // detail | ||
85 | |||
86 | //------------------------------------------------ | ||
87 | |||
88 | template<class CharSet> | ||
89 | auto | ||
90 | 9143 | implementation_defined::pct_encoded_rule_t<CharSet>:: | |
91 | parse( | ||
92 | char const*& it, | ||
93 | char const* end) const noexcept -> | ||
94 | system::result<value_type> | ||
95 | { | ||
96 | 9143 | return detail::parse_encoded( | |
97 | 9143 | it, end, cs_); | |
98 | } | ||
99 | |||
100 | } // urls | ||
101 | } // boost | ||
102 | |||
103 | #endif | ||
104 |