Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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_GRAMMAR_IMPL_LITERAL_RULE_IPP | ||
11 | #define BOOST_URL_GRAMMAR_IMPL_LITERAL_RULE_IPP | ||
12 | |||
13 | #include <boost/url/detail/config.hpp> | ||
14 | #include <boost/url/grammar/error.hpp> | ||
15 | #include <boost/url/grammar/literal_rule.hpp> | ||
16 | #include <boost/assert.hpp> | ||
17 | #include <cstring> | ||
18 | |||
19 | namespace boost { | ||
20 | namespace urls { | ||
21 | namespace grammar { | ||
22 | |||
23 | auto | ||
24 | 10 | literal_rule:: | |
25 | parse( | ||
26 | char const*& it, | ||
27 | char const* end) const noexcept -> | ||
28 | system::result<value_type> | ||
29 | { | ||
30 | // Can't have a literal | ||
31 | // with an empty string! | ||
32 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | BOOST_ASSERT(n_ > 0); |
33 | |||
34 | 10 | std::size_t n = end - it; | |
35 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
|
10 | if(n >= n_) |
36 | { | ||
37 | 4 | if(std::memcmp( | |
38 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | it, s_, n_) != 0) |
39 | { | ||
40 | // non-match | ||
41 | 1 | BOOST_URL_RETURN_EC( | |
42 | error::mismatch); | ||
43 | } | ||
44 | 3 | it += n_; | |
45 | 3 | return core::string_view( | |
46 | 3 | it - n_, it); | |
47 | } | ||
48 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
|
6 | if(n > 0) |
49 | { | ||
50 | // short input | ||
51 | 5 | if(std::memcmp( | |
52 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
|
5 | it, s_, n) != 0) |
53 | { | ||
54 | // non-match | ||
55 | 2 | BOOST_URL_RETURN_EC( | |
56 | error::mismatch); | ||
57 | } | ||
58 | // prefix matches | ||
59 | 3 | BOOST_URL_RETURN_EC( | |
60 | error::need_more); | ||
61 | } | ||
62 | // end | ||
63 | 1 | BOOST_URL_RETURN_EC( | |
64 | error::need_more); | ||
65 | } | ||
66 | |||
67 | } // grammar | ||
68 | } // urls | ||
69 | } // boost | ||
70 | |||
71 | #endif | ||
72 |