| 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 | #ifndef BOOST_URL_IMPL_PORT_RULE_IPP | ||
| 11 | #define BOOST_URL_IMPL_PORT_RULE_IPP | ||
| 12 | |||
| 13 | #include <boost/url/detail/config.hpp> | ||
| 14 | #include <boost/url/rfc/detail/port_rule.hpp> | ||
| 15 | #include <boost/url/grammar/parse.hpp> | ||
| 16 | #include <boost/url/grammar/token_rule.hpp> | ||
| 17 | #include <boost/url/grammar/unsigned_rule.hpp> | ||
| 18 | #include <boost/static_assert.hpp> | ||
| 19 | #include <type_traits> | ||
| 20 | |||
| 21 | namespace boost { | ||
| 22 | namespace urls { | ||
| 23 | namespace detail { | ||
| 24 | |||
| 25 | auto | ||
| 26 | 342 | port_rule:: | |
| 27 | parse( | ||
| 28 | char const*& it, | ||
| 29 | char const* end) const noexcept -> | ||
| 30 | system::result<value_type> | ||
| 31 | { | ||
| 32 | 342 | value_type t; | |
| 33 | 342 | auto const start = it; | |
| 34 | 124 | while( | |
| 35 |
2/2✓ Branch 0 taken 406 times.
✓ Branch 1 taken 60 times.
|
466 | it != end && |
| 36 |
2/2✓ Branch 0 taken 124 times.
✓ Branch 1 taken 282 times.
|
406 | *it == '0') |
| 37 | { | ||
| 38 | 124 | ++it; | |
| 39 | } | ||
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 282 times.
✓ Branch 1 taken 60 times.
|
342 | if (it != end) |
| 42 | { | ||
| 43 | grammar::unsigned_rule<std::uint16_t> r; | ||
| 44 | 282 | auto it0 = it; | |
| 45 | 282 | auto rv = r.parse(it, end); | |
| 46 |
2/2✓ Branch 1 taken 228 times.
✓ Branch 2 taken 54 times.
|
282 | if (rv) |
| 47 | { | ||
| 48 | // number < max uint16_t | ||
| 49 | 228 | t.str = core::string_view(start, it); | |
| 50 | 228 | t.has_number = true; | |
| 51 | 228 | t.number = *rv; | |
| 52 | 249 | return t; | |
| 53 | } | ||
| 54 | 54 | it = it0; | |
| 55 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 33 times.
|
54 | if (grammar::digit_chars(*it)) |
| 56 | { | ||
| 57 | // number > max uint16_t | ||
| 58 | 168 | while ( | |
| 59 |
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 && |
| 60 | 177 | grammar::digit_chars(*it)) | |
| 61 | { | ||
| 62 | 168 | ++it; | |
| 63 | } | ||
| 64 | 21 | t.str = core::string_view(start, it); | |
| 65 | 21 | t.has_number = true; | |
| 66 | 21 | t.number = 0; | |
| 67 | 21 | return t; | |
| 68 | } | ||
| 69 | } | ||
| 70 | // no digits | ||
| 71 | 93 | t.str = core::string_view(start, it); | |
| 72 | 93 | t.has_number = it != end; | |
| 73 | 93 | t.number = 0; | |
| 74 | 93 | return t; | |
| 75 | } | ||
| 76 | |||
| 77 | auto | ||
| 78 | 1853 | port_part_rule_t:: | |
| 79 | parse( | ||
| 80 | char const*& it, | ||
| 81 | char const* end) const noexcept -> | ||
| 82 | system::result<value_type> | ||
| 83 | { | ||
| 84 | 1853 | value_type t; | |
| 85 |
2/2✓ Branch 0 taken 1258 times.
✓ Branch 1 taken 595 times.
|
1853 | if( it == end || |
| 86 |
2/2✓ Branch 0 taken 1006 times.
✓ Branch 1 taken 252 times.
|
1258 | *it != ':') |
| 87 | { | ||
| 88 | 1601 | t.has_port = false; | |
| 89 | 1601 | return t; | |
| 90 | } | ||
| 91 | 252 | ++it; | |
| 92 | auto rv = grammar::parse( | ||
| 93 | 252 | it, end, port_rule{}); | |
| 94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 252 times.
|
252 | if(! rv) |
| 95 | ✗ | return rv.error(); | |
| 96 | 252 | t.has_port = true; | |
| 97 | 252 | t.port = rv->str; | |
| 98 | 252 | t.has_number = rv->has_number; | |
| 99 | 252 | t.port_number = rv->number; | |
| 100 | 252 | return t; | |
| 101 | } | ||
| 102 | |||
| 103 | } // detail | ||
| 104 | } // urls | ||
| 105 | } // boost | ||
| 106 | |||
| 107 | #endif | ||
| 108 |