include/boost/url/rfc/detail/impl/port_rule.hpp
97.8% Lines (44/45)
100.0% Functions (2/2)
95.5% Branches (21/22)
include/boost/url/rfc/detail/impl/port_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_RFC_DETAIL_IMPL_PORT_RULE_HPP | ||
| 12 | #define BOOST_URL_RFC_DETAIL_IMPL_PORT_RULE_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/config.hpp> | ||
| 15 | #include <boost/url/grammar/digit_chars.hpp> | ||
| 16 | #include <boost/url/grammar/parse.hpp> | ||
| 17 | #include <boost/url/grammar/unsigned_rule.hpp> | ||
| 18 | |||
| 19 | namespace boost { | ||
| 20 | namespace urls { | ||
| 21 | namespace detail { | ||
| 22 | |||
| 23 | inline BOOST_URL_CXX20_CONSTEXPR | ||
| 24 | auto | ||
| 25 | 395 | port_rule:: | |
| 26 | parse( | ||
| 27 | char const*& it, | ||
| 28 | char const* end) const noexcept -> | ||
| 29 | system::result<value_type> | ||
| 30 | { | ||
| 31 | 395 | value_type t; | |
| 32 | 395 | auto const start = it; | |
| 33 | 395 | while( | |
| 34 |
2/2✓ Branch 0 taken 461 times.
✓ Branch 1 taken 62 times.
|
523 | it != end && |
| 35 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 333 times.
|
461 | *it == '0') |
| 36 | { | ||
| 37 | 128 | ++it; | |
| 38 | } | ||
| 39 | |||
| 40 |
2/2✓ Branch 0 taken 333 times.
✓ Branch 1 taken 62 times.
|
395 | if (it != end) |
| 41 | { | ||
| 42 | grammar::unsigned_rule<std::uint16_t> r; | ||
| 43 | 333 | auto it0 = it; | |
| 44 | 333 | auto rv = r.parse(it, end); | |
| 45 |
2/2✓ Branch 1 taken 279 times.
✓ Branch 2 taken 54 times.
|
333 | if (rv) |
| 46 | { | ||
| 47 | 279 | t.str = core::string_view(start, it); | |
| 48 | 279 | t.has_number = true; | |
| 49 | 279 | t.number = *rv; | |
| 50 | 300 | return t; | |
| 51 | } | ||
| 52 | 54 | it = it0; | |
| 53 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 33 times.
|
54 | if (grammar::digit_chars(*it)) |
| 54 | { | ||
| 55 | 21 | while ( | |
| 56 |
6/6✓ Branch 0 taken 177 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 168 times.
✓ Branch 5 taken 21 times.
|
366 | it != end && |
| 57 | 177 | grammar::digit_chars(*it)) | |
| 58 | { | ||
| 59 | 168 | ++it; | |
| 60 | } | ||
| 61 | 21 | t.str = core::string_view(start, it); | |
| 62 | 21 | t.has_number = true; | |
| 63 | 21 | t.number = 0; | |
| 64 | 21 | return t; | |
| 65 | } | ||
| 66 | } | ||
| 67 | 95 | t.str = core::string_view(start, it); | |
| 68 | 95 | t.has_number = it != end; | |
| 69 | 95 | t.number = 0; | |
| 70 | 95 | return t; | |
| 71 | } | ||
| 72 | |||
| 73 | inline BOOST_URL_CXX20_CONSTEXPR | ||
| 74 | auto | ||
| 75 | 2042 | port_part_rule_t:: | |
| 76 | parse( | ||
| 77 | char const*& it, | ||
| 78 | char const* end) const noexcept -> | ||
| 79 | system::result<value_type> | ||
| 80 | { | ||
| 81 | 2042 | value_type t; | |
| 82 |
2/2✓ Branch 0 taken 1413 times.
✓ Branch 1 taken 629 times.
|
2042 | if( it == end || |
| 83 |
2/2✓ Branch 0 taken 1108 times.
✓ Branch 1 taken 305 times.
|
1413 | *it != ':') |
| 84 | { | ||
| 85 | 1737 | t.has_port = false; | |
| 86 | 1737 | return t; | |
| 87 | } | ||
| 88 | 305 | ++it; | |
| 89 | 305 | auto rv = grammar::parse( | |
| 90 | 305 | it, end, port_rule{}); | |
| 91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 305 times.
|
305 | if(! rv) |
| 92 | ✗ | return rv.error(); | |
| 93 | 305 | t.has_port = true; | |
| 94 | 305 | t.port = rv->str; | |
| 95 | 305 | t.has_number = rv->has_number; | |
| 96 | 305 | t.port_number = rv->number; | |
| 97 | 305 | return t; | |
| 98 | } | ||
| 99 | |||
| 100 | } // detail | ||
| 101 | } // urls | ||
| 102 | } // boost | ||
| 103 | |||
| 104 | |||
| 105 | #endif | ||
| 106 |