include/boost/url/grammar/impl/dec_octet_rule.hpp
100.0% Lines (30/30)
100.0% Functions (1/1)
100.0% Branches (28/28)
include/boost/url/grammar/impl/dec_octet_rule.hpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | ||
| 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/boostorg/url | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP | ||
| 12 | #define BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/config.hpp> | ||
| 15 | #include <boost/url/grammar/charset.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 | namespace implementation_defined { | ||
| 23 | |||
| 24 | inline BOOST_URL_CXX20_CONSTEXPR | ||
| 25 | auto | ||
| 26 | 2477 | dec_octet_rule_t:: | |
| 27 | parse( | ||
| 28 | char const*& it, | ||
| 29 | char const* const end | ||
| 30 | ) const noexcept -> | ||
| 31 | system::result<value_type> | ||
| 32 | { | ||
| 33 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2463 times.
|
2477 | if(it == end) |
| 34 | { | ||
| 35 | 14 | BOOST_URL_CONSTEXPR_RETURN_EC( | |
| 36 | error::mismatch); | ||
| 37 | } | ||
| 38 |
2/2✓ Branch 1 taken 1817 times.
✓ Branch 2 taken 646 times.
|
2463 | if(! digit_chars(*it)) |
| 39 | { | ||
| 40 | 1817 | BOOST_URL_CONSTEXPR_RETURN_EC( | |
| 41 | error::mismatch); | ||
| 42 | } | ||
| 43 | 646 | unsigned v = *it - '0'; | |
| 44 | 646 | ++it; | |
| 45 |
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 || |
| 46 |
2/2✓ Branch 1 taken 364 times.
✓ Branch 2 taken 213 times.
|
577 | ! digit_chars(*it)) |
| 47 | { | ||
| 48 | 433 | return static_cast< | |
| 49 | 433 | value_type>(v); | |
| 50 | } | ||
| 51 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 202 times.
|
213 | if(v == 0) |
| 52 | { | ||
| 53 | 11 | BOOST_URL_CONSTEXPR_RETURN_EC( | |
| 54 | error::invalid); | ||
| 55 | } | ||
| 56 | 202 | v = (10 * v) + *it - '0'; | |
| 57 | 202 | ++it; | |
| 58 |
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 || |
| 59 |
2/2✓ Branch 1 taken 19 times.
✓ Branch 2 taken 179 times.
|
198 | ! digit_chars(*it)) |
| 60 | { | ||
| 61 | 23 | return static_cast< | |
| 62 | 23 | value_type>(v); | |
| 63 | } | ||
| 64 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 166 times.
|
179 | if(v > 25) |
| 65 | { | ||
| 66 | 13 | BOOST_URL_CONSTEXPR_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 | 17 | BOOST_URL_CONSTEXPR_RETURN_EC( | |
| 73 | error::invalid); | ||
| 74 | } | ||
| 75 | 149 | ++it; | |
| 76 |
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 && |
| 77 | 137 | digit_chars(*it)) | |
| 78 | { | ||
| 79 | 7 | BOOST_URL_CONSTEXPR_RETURN_EC( | |
| 80 | error::invalid); | ||
| 81 | } | ||
| 82 | 142 | return static_cast< | |
| 83 | 142 | value_type>(v); | |
| 84 | } | ||
| 85 | |||
| 86 | } // implementation_defined | ||
| 87 | } // grammar | ||
| 88 | } // urls | ||
| 89 | } // boost | ||
| 90 | |||
| 91 | #endif | ||
| 92 |