100.00% Lines (30/30)
100.00% Functions (1/1)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | |||||
| 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/boostorg/url | 8 | // Official repository: https://github.com/boostorg/url | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP | 11 | #ifndef BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP | |||||
| 12 | #define BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP | 12 | #define BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/url/detail/config.hpp> | 14 | #include <boost/url/detail/config.hpp> | |||||
| 15 | #include <boost/url/grammar/charset.hpp> | 15 | #include <boost/url/grammar/charset.hpp> | |||||
| 16 | #include <boost/url/grammar/digit_chars.hpp> | 16 | #include <boost/url/grammar/digit_chars.hpp> | |||||
| 17 | #include <boost/url/grammar/error.hpp> | 17 | #include <boost/url/grammar/error.hpp> | |||||
| 18 | 18 | |||||||
| 19 | namespace boost { | 19 | namespace boost { | |||||
| 20 | namespace urls { | 20 | namespace urls { | |||||
| 21 | namespace grammar { | 21 | namespace grammar { | |||||
| 22 | namespace implementation_defined { | 22 | namespace implementation_defined { | |||||
| 23 | 23 | |||||||
| 24 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | 24 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | |||||
| 25 | auto | 25 | auto | |||||
| HITCBC | 26 | 8214 | dec_octet_rule_t:: | 26 | 8214 | dec_octet_rule_t:: | ||
| 27 | parse( | 27 | parse( | |||||
| 28 | char const*& it, | 28 | char const*& it, | |||||
| 29 | char const* const end | 29 | char const* const end | |||||
| 30 | ) const noexcept -> | 30 | ) const noexcept -> | |||||
| 31 | system::result<value_type> | 31 | system::result<value_type> | |||||
| 32 | { | 32 | { | |||||
| HITCBC | 33 | 8214 | if(it == end) | 33 | 8214 | if(it == end) | ||
| 34 | { | 34 | { | |||||
| 35 | // end | 35 | // end | |||||
| HITCBC | 36 | 14 | BOOST_URL_CONSTEXPR_RETURN_EC( | 36 | 14 | BOOST_URL_CONSTEXPR_RETURN_EC( | ||
| 37 | error::mismatch); | 37 | error::mismatch); | |||||
| 38 | } | 38 | } | |||||
| HITCBC | 39 | 8200 | if(! digit_chars(*it)) | 39 | 8200 | if(! digit_chars(*it)) | ||
| 40 | { | 40 | { | |||||
| 41 | // expected DIGIT | 41 | // expected DIGIT | |||||
| HITCBC | 42 | 6483 | BOOST_URL_CONSTEXPR_RETURN_EC( | 42 | 6483 | BOOST_URL_CONSTEXPR_RETURN_EC( | ||
| 43 | error::mismatch); | 43 | error::mismatch); | |||||
| 44 | } | 44 | } | |||||
| HITCBC | 45 | 1717 | unsigned v = *it - '0'; | 45 | 1717 | unsigned v = *it - '0'; | ||
| HITCBC | 46 | 1717 | ++it; | 46 | 1717 | ++it; | ||
| HITCBC | 47 | 3228 | if( it == end || | 47 | 3228 | if( it == end || | ||
| HITCBC | 48 | 1511 | ! digit_chars(*it)) | 48 | 1511 | ! digit_chars(*it)) | ||
| 49 | { | 49 | { | |||||
| HITCBC | 50 | 1006 | return static_cast< | 50 | 1006 | return static_cast< | ||
| HITCBC | 51 | 1006 | value_type>(v); | 51 | 1006 | value_type>(v); | ||
| 52 | } | 52 | } | |||||
| HITCBC | 53 | 711 | if(v == 0) | 53 | 711 | if(v == 0) | ||
| 54 | { | 54 | { | |||||
| 55 | // leading '0' | 55 | // leading '0' | |||||
| HITCBC | 56 | 11 | BOOST_URL_CONSTEXPR_RETURN_EC( | 56 | 11 | BOOST_URL_CONSTEXPR_RETURN_EC( | ||
| 57 | error::invalid); | 57 | error::invalid); | |||||
| 58 | } | 58 | } | |||||
| HITCBC | 59 | 700 | v = (10 * v) + *it - '0'; | 59 | 700 | v = (10 * v) + *it - '0'; | ||
| HITCBC | 60 | 700 | ++it; | 60 | 700 | ++it; | ||
| HITCBC | 61 | 1380 | if( it == end || | 61 | 1380 | if( it == end || | ||
| HITCBC | 62 | 680 | ! digit_chars(*it)) | 62 | 680 | ! digit_chars(*it)) | ||
| 63 | { | 63 | { | |||||
| HITCBC | 64 | 99 | return static_cast< | 64 | 99 | return static_cast< | ||
| HITCBC | 65 | 99 | value_type>(v); | 65 | 99 | value_type>(v); | ||
| 66 | } | 66 | } | |||||
| HITCBC | 67 | 601 | if(v > 25) | 67 | 601 | if(v > 25) | ||
| 68 | { | 68 | { | |||||
| 69 | // integer overflow | 69 | // integer overflow | |||||
| HITCBC | 70 | 13 | BOOST_URL_CONSTEXPR_RETURN_EC( | 70 | 13 | BOOST_URL_CONSTEXPR_RETURN_EC( | ||
| 71 | error::invalid); | 71 | error::invalid); | |||||
| 72 | } | 72 | } | |||||
| HITCBC | 73 | 588 | v = (10 * v) + *it - '0'; | 73 | 588 | v = (10 * v) + *it - '0'; | ||
| HITCBC | 74 | 588 | if(v > 255) | 74 | 588 | if(v > 255) | ||
| 75 | { | 75 | { | |||||
| 76 | // integer overflow | 76 | // integer overflow | |||||
| HITCBC | 77 | 17 | BOOST_URL_CONSTEXPR_RETURN_EC( | 77 | 17 | BOOST_URL_CONSTEXPR_RETURN_EC( | ||
| 78 | error::invalid); | 78 | error::invalid); | |||||
| 79 | } | 79 | } | |||||
| HITCBC | 80 | 571 | ++it; | 80 | 571 | ++it; | ||
| HITCBC | 81 | 1095 | if( it != end && | 81 | 1095 | if( it != end && | ||
| HITCBC | 82 | 524 | digit_chars(*it)) | 82 | 524 | digit_chars(*it)) | ||
| 83 | { | 83 | { | |||||
| 84 | // integer overflow | 84 | // integer overflow | |||||
| HITCBC | 85 | 7 | BOOST_URL_CONSTEXPR_RETURN_EC( | 85 | 7 | BOOST_URL_CONSTEXPR_RETURN_EC( | ||
| 86 | error::invalid); | 86 | error::invalid); | |||||
| 87 | } | 87 | } | |||||
| HITCBC | 88 | 564 | return static_cast< | 88 | 564 | return static_cast< | ||
| HITCBC | 89 | 564 | value_type>(v); | 89 | 564 | value_type>(v); | ||
| 90 | } | 90 | } | |||||
| 91 | 91 | |||||||
| 92 | } // implementation_defined | 92 | } // implementation_defined | |||||
| 93 | } // grammar | 93 | } // grammar | |||||
| 94 | } // urls | 94 | } // urls | |||||
| 95 | } // boost | 95 | } // boost | |||||
| 96 | 96 | |||||||
| 97 | #endif | 97 | #endif | |||||