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