libs/url/src/grammar/dec_octet_rule.cpp
| 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 <boost/url/grammar/charset.hpp> | ||
| 13 | #include <boost/url/grammar/dec_octet_rule.hpp> | ||
| 14 | #include <boost/url/grammar/digit_chars.hpp> | ||
| 15 | #include <boost/url/grammar/error.hpp> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace urls { | ||
| 19 | namespace grammar { | ||
| 20 | namespace implementation_defined { | ||
| 21 | auto | ||
| 22 | 2463 | dec_octet_rule_t:: | |
| 23 | parse( | ||
| 24 | char const*& it, | ||
| 25 | char const* const end | ||
| 26 | ) const noexcept -> | ||
| 27 | system::result<value_type> | ||
| 28 | { | ||
| 29 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2449 times.
|
2463 | if(it == end) |
| 30 | { | ||
| 31 | // end | ||
| 32 | 14 | BOOST_URL_RETURN_EC( | |
| 33 | error::mismatch); | ||
| 34 | } | ||
| 35 |
2/2✓ Branch 1 taken 1803 times.
✓ Branch 2 taken 646 times.
|
2449 | if(! digit_chars(*it)) |
| 36 | { | ||
| 37 | // expected DIGIT | ||
| 38 | 1803 | BOOST_URL_RETURN_EC( | |
| 39 | error::mismatch); | ||
| 40 | } | ||
| 41 | 646 | unsigned v = *it - '0'; | |
| 42 | 646 | ++it; | |
| 43 |
4/4✓ Branch 0 taken 577 times.
✓ Branch 1 taken 69 times.
✓ Branch 2 taken 433 times.
✓ Branch 3 taken 213 times.
|
1223 | if( it == end || |
| 44 |
2/2✓ Branch 1 taken 364 times.
✓ Branch 2 taken 213 times.
|
577 | ! digit_chars(*it)) |
| 45 | { | ||
| 46 | 433 | return static_cast< | |
| 47 | 433 | value_type>(v); | |
| 48 | } | ||
| 49 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 202 times.
|
213 | if(v == 0) |
| 50 | { | ||
| 51 | // leading '0' | ||
| 52 | 11 | BOOST_URL_RETURN_EC( | |
| 53 | error::invalid); | ||
| 54 | } | ||
| 55 | 202 | v = (10 * v) + *it - '0'; | |
| 56 | 202 | ++it; | |
| 57 |
4/4✓ Branch 0 taken 198 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 179 times.
|
400 | if( it == end || |
| 58 |
2/2✓ Branch 1 taken 19 times.
✓ Branch 2 taken 179 times.
|
198 | ! digit_chars(*it)) |
| 59 | { | ||
| 60 | 23 | return static_cast< | |
| 61 | 23 | value_type>(v); | |
| 62 | } | ||
| 63 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 166 times.
|
179 | if(v > 25) |
| 64 | { | ||
| 65 | // integer overflow | ||
| 66 | 13 | BOOST_URL_RETURN_EC( | |
| 67 | error::invalid); | ||
| 68 | } | ||
| 69 | 166 | v = (10 * v) + *it - '0'; | |
| 70 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 149 times.
|
166 | if(v > 255) |
| 71 | { | ||
| 72 | // integer overflow | ||
| 73 | 17 | BOOST_URL_RETURN_EC( | |
| 74 | error::invalid); | ||
| 75 | } | ||
| 76 | 149 | ++it; | |
| 77 |
6/6✓ Branch 0 taken 137 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 130 times.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 142 times.
|
286 | if( it != end && |
| 78 | 137 | digit_chars(*it)) | |
| 79 | { | ||
| 80 | // integer overflow | ||
| 81 | 7 | BOOST_URL_RETURN_EC( | |
| 82 | error::invalid); | ||
| 83 | } | ||
| 84 | 142 | return static_cast< | |
| 85 | 142 | value_type>(v); | |
| 86 | } | ||
| 87 | } // implementation_defined | ||
| 88 | } // grammar | ||
| 89 | } // urls | ||
| 90 | } // boost | ||
| 91 | |||
| 92 |