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_IMPL_GRAMMAR_DEC_OCTET_RULE_IPP | ||
11 | #define BOOST_URL_IMPL_GRAMMAR_DEC_OCTET_RULE_IPP | ||
12 | |||
13 | #include <boost/url/detail/config.hpp> | ||
14 | #include <boost/url/grammar/charset.hpp> | ||
15 | #include <boost/url/grammar/dec_octet_rule.hpp> | ||
16 | #include <boost/url/grammar/digit_chars.hpp> | ||
17 | #include <boost/url/grammar/error.hpp> | ||
18 | |||
19 | namespace boost { | ||
20 | namespace urls { | ||
21 | namespace grammar { | ||
22 | |||
23 | auto | ||
24 | 2276 | dec_octet_rule_t:: | |
25 | parse( | ||
26 | char const*& it, | ||
27 | char const* const end | ||
28 | ) const noexcept -> | ||
29 | system::result<value_type> | ||
30 | { | ||
31 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2262 times.
|
2276 | if(it == end) |
32 | { | ||
33 | // end | ||
34 | 14 | BOOST_URL_RETURN_EC( | |
35 | error::mismatch); | ||
36 | } | ||
37 |
2/2✓ Branch 1 taken 1632 times.
✓ Branch 2 taken 630 times.
|
2262 | if(! digit_chars(*it)) |
38 | { | ||
39 | // expected DIGIT | ||
40 | 1632 | BOOST_URL_RETURN_EC( | |
41 | error::mismatch); | ||
42 | } | ||
43 | 630 | unsigned v = *it - '0'; | |
44 | 630 | ++it; | |
45 |
4/4✓ Branch 0 taken 564 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 424 times.
✓ Branch 3 taken 206 times.
|
1194 | if( it == end || |
46 |
2/2✓ Branch 1 taken 358 times.
✓ Branch 2 taken 206 times.
|
564 | ! digit_chars(*it)) |
47 | { | ||
48 | 424 | return static_cast< | |
49 | 424 | value_type>(v); | |
50 | } | ||
51 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 195 times.
|
206 | if(v == 0) |
52 | { | ||
53 | // leading '0' | ||
54 | 11 | BOOST_URL_RETURN_EC( | |
55 | error::invalid); | ||
56 | } | ||
57 | 195 | v = (10 * v) + *it - '0'; | |
58 | 195 | ++it; | |
59 |
4/4✓ Branch 0 taken 191 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 172 times.
|
386 | if( it == end || |
60 |
2/2✓ Branch 1 taken 19 times.
✓ Branch 2 taken 172 times.
|
191 | ! digit_chars(*it)) |
61 | { | ||
62 | 23 | return static_cast< | |
63 | 23 | value_type>(v); | |
64 | } | ||
65 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 159 times.
|
172 | if(v > 25) |
66 | { | ||
67 | // integer overflow | ||
68 | 13 | BOOST_URL_RETURN_EC( | |
69 | error::invalid); | ||
70 | } | ||
71 | 159 | v = (10 * v) + *it - '0'; | |
72 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 142 times.
|
159 | if(v > 255) |
73 | { | ||
74 | // integer overflow | ||
75 | 17 | BOOST_URL_RETURN_EC( | |
76 | error::invalid); | ||
77 | } | ||
78 | 142 | ++it; | |
79 |
6/6✓ Branch 0 taken 130 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 123 times.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 135 times.
|
272 | if( it != end && |
80 | 130 | digit_chars(*it)) | |
81 | { | ||
82 | // integer overflow | ||
83 | 7 | BOOST_URL_RETURN_EC( | |
84 | error::invalid); | ||
85 | } | ||
86 | 135 | return static_cast< | |
87 | 135 | value_type>(v); | |
88 | } | ||
89 | |||
90 | } // grammar | ||
91 | } // urls | ||
92 | } // boost | ||
93 | |||
94 | #endif | ||
95 |