97.78% Lines (44/45)
100.00% Functions (2/2)
| 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_RFC_DETAIL_IMPL_PORT_RULE_HPP | 11 | #ifndef BOOST_URL_RFC_DETAIL_IMPL_PORT_RULE_HPP | |||||
| 12 | #define BOOST_URL_RFC_DETAIL_IMPL_PORT_RULE_HPP | 12 | #define BOOST_URL_RFC_DETAIL_IMPL_PORT_RULE_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/url/detail/config.hpp> | 14 | #include <boost/url/detail/config.hpp> | |||||
| 15 | #include <boost/url/grammar/digit_chars.hpp> | 15 | #include <boost/url/grammar/digit_chars.hpp> | |||||
| 16 | #include <boost/url/grammar/parse.hpp> | 16 | #include <boost/url/grammar/parse.hpp> | |||||
| 17 | #include <boost/url/grammar/unsigned_rule.hpp> | 17 | #include <boost/url/grammar/unsigned_rule.hpp> | |||||
| 18 | 18 | |||||||
| 19 | namespace boost { | 19 | namespace boost { | |||||
| 20 | namespace urls { | 20 | namespace urls { | |||||
| 21 | namespace detail { | 21 | namespace detail { | |||||
| 22 | 22 | |||||||
| 23 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | 23 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | |||||
| 24 | auto | 24 | auto | |||||
| HITCBC | 25 | 788 | port_rule:: | 25 | 788 | port_rule:: | ||
| 26 | parse( | 26 | parse( | |||||
| 27 | char const*& it, | 27 | char const*& it, | |||||
| 28 | char const* end) const noexcept -> | 28 | char const* end) const noexcept -> | |||||
| 29 | system::result<value_type> | 29 | system::result<value_type> | |||||
| 30 | { | 30 | { | |||||
| HITCBC | 31 | 788 | value_type t; | 31 | 788 | value_type t; | ||
| HITCBC | 32 | 788 | auto const start = it; | 32 | 788 | auto const start = it; | ||
| HITCBC | 33 | 788 | while( | 33 | 788 | while( | ||
| HITCBC | 34 | 920 | it != end && | 34 | 920 | it != end && | ||
| HITCBC | 35 | 716 | *it == '0') | 35 | 716 | *it == '0') | ||
| 36 | { | 36 | { | |||||
| HITCBC | 37 | 132 | ++it; | 37 | 132 | ++it; | ||
| 38 | } | 38 | } | |||||
| 39 | 39 | |||||||
| HITCBC | 40 | 788 | if (it != end) | 40 | 788 | if (it != end) | ||
| 41 | { | 41 | { | |||||
| 42 | grammar::unsigned_rule<std::uint16_t> r; | 42 | grammar::unsigned_rule<std::uint16_t> r; | |||||
| HITCBC | 43 | 584 | auto it0 = it; | 43 | 584 | auto it0 = it; | ||
| HITCBC | 44 | 584 | auto rv = r.parse(it, end); | 44 | 584 | auto rv = r.parse(it, end); | ||
| HITCBC | 45 | 584 | if (rv) | 45 | 584 | if (rv) | ||
| 46 | { | 46 | { | |||||
| 47 | // number < max uint16_t | 47 | // number < max uint16_t | |||||
| HITCBC | 48 | 528 | t.str = core::string_view(start, it); | 48 | 528 | t.str = core::string_view(start, it); | ||
| HITCBC | 49 | 528 | t.has_number = true; | 49 | 528 | t.has_number = true; | ||
| HITCBC | 50 | 528 | t.number = *rv; | 50 | 528 | t.number = *rv; | ||
| HITCBC | 51 | 549 | return t; | 51 | 549 | return t; | ||
| 52 | } | 52 | } | |||||
| HITCBC | 53 | 56 | it = it0; | 53 | 56 | it = it0; | ||
| HITCBC | 54 | 56 | if (grammar::digit_chars(*it)) | 54 | 56 | if (grammar::digit_chars(*it)) | ||
| 55 | { | 55 | { | |||||
| 56 | // number > max uint16_t | 56 | // number > max uint16_t | |||||
| HITCBC | 57 | 21 | while ( | 57 | 21 | while ( | ||
| HITCBC | 58 | 366 | it != end && | 58 | 366 | it != end && | ||
| HITCBC | 59 | 177 | grammar::digit_chars(*it)) | 59 | 177 | grammar::digit_chars(*it)) | ||
| 60 | { | 60 | { | |||||
| HITCBC | 61 | 168 | ++it; | 61 | 168 | ++it; | ||
| 62 | } | 62 | } | |||||
| HITCBC | 63 | 21 | t.str = core::string_view(start, it); | 63 | 21 | t.str = core::string_view(start, it); | ||
| HITCBC | 64 | 21 | t.has_number = true; | 64 | 21 | t.has_number = true; | ||
| HITCBC | 65 | 21 | t.number = 0; | 65 | 21 | t.number = 0; | ||
| HITCBC | 66 | 21 | return t; | 66 | 21 | return t; | ||
| 67 | } | 67 | } | |||||
| 68 | } | 68 | } | |||||
| 69 | // no digits | 69 | // no digits | |||||
| HITCBC | 70 | 239 | t.str = core::string_view(start, it); | 70 | 239 | t.str = core::string_view(start, it); | ||
| HITCBC | 71 | 239 | t.has_number = it != start; | 71 | 239 | t.has_number = it != start; | ||
| HITCBC | 72 | 239 | t.number = 0; | 72 | 239 | t.number = 0; | ||
| HITCBC | 73 | 239 | return t; | 73 | 239 | return t; | ||
| 74 | } | 74 | } | |||||
| 75 | 75 | |||||||
| 76 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | 76 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | |||||
| 77 | auto | 77 | auto | |||||
| HITCBC | 78 | 6634 | port_part_rule_t:: | 78 | 6634 | port_part_rule_t:: | ||
| 79 | parse( | 79 | parse( | |||||
| 80 | char const*& it, | 80 | char const*& it, | |||||
| 81 | char const* end) const noexcept -> | 81 | char const* end) const noexcept -> | |||||
| 82 | system::result<value_type> | 82 | system::result<value_type> | |||||
| 83 | { | 83 | { | |||||
| HITCBC | 84 | 6634 | value_type t; | 84 | 6634 | value_type t; | ||
| HITCBC | 85 | 6634 | if( it == end || | 85 | 6634 | if( it == end || | ||
| HITCBC | 86 | 5986 | *it != ':') | 86 | 5986 | *it != ':') | ||
| 87 | { | 87 | { | |||||
| HITCBC | 88 | 6235 | t.has_port = false; | 88 | 6235 | t.has_port = false; | ||
| HITCBC | 89 | 6235 | return t; | 89 | 6235 | return t; | ||
| 90 | } | 90 | } | |||||
| HITCBC | 91 | 399 | ++it; | 91 | 399 | ++it; | ||
| HITCBC | 92 | 399 | auto rv = grammar::parse( | 92 | 399 | auto rv = grammar::parse( | ||
| HITCBC | 93 | 399 | it, end, port_rule{}); | 93 | 399 | it, end, port_rule{}); | ||
| HITCBC | 94 | 399 | if(! rv) | 94 | 399 | if(! rv) | ||
| MISUBC | 95 | ✗ | return rv.error(); | 95 | ✗ | return rv.error(); | ||
| HITCBC | 96 | 399 | t.has_port = true; | 96 | 399 | t.has_port = true; | ||
| HITCBC | 97 | 399 | t.port = rv->str; | 97 | 399 | t.port = rv->str; | ||
| HITCBC | 98 | 399 | t.has_number = rv->has_number; | 98 | 399 | t.has_number = rv->has_number; | ||
| HITCBC | 99 | 399 | t.port_number = rv->number; | 99 | 399 | t.port_number = rv->number; | ||
| HITCBC | 100 | 399 | return t; | 100 | 399 | return t; | ||
| 101 | } | 101 | } | |||||
| 102 | 102 | |||||||
| 103 | } // detail | 103 | } // detail | |||||
| 104 | } // urls | 104 | } // urls | |||||
| 105 | } // boost | 105 | } // boost | |||||
| 106 | 106 | |||||||
| 107 | 107 | |||||||
| 108 | #endif | 108 | #endif | |||||