GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/rfc/detail/port_rule.cpp
Date: 2024-01-19 15:42:54
Exec Total Coverage
Lines: 43 44 97.7%
Functions: 2 2 100.0%
Branches: 21 22 95.5%

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 "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 350 port_rule::
27 parse(
28 char const*& it,
29 char const* end) const noexcept ->
30 system::result<value_type>
31 {
32 350 value_type t;
33 350 auto const start = it;
34 124 while(
35
2/2
✓ Branch 0 taken 414 times.
✓ Branch 1 taken 60 times.
474 it != end &&
36
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 290 times.
414 *it == '0')
37 {
38 124 ++it;
39 }
40
41
2/2
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 60 times.
350 if (it != end)
42 {
43 grammar::unsigned_rule<std::uint16_t> r;
44 290 auto it0 = it;
45 290 auto rv = r.parse(it, end);
46
2/2
✓ Branch 1 taken 236 times.
✓ Branch 2 taken 54 times.
290 if (rv)
47 {
48 // number < max uint16_t
49 236 t.str = core::string_view(start, it);
50 236 t.has_number = true;
51 236 t.number = *rv;
52 257 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 1861 port_part_rule_t::
79 parse(
80 char const*& it,
81 char const* end) const noexcept ->
82 system::result<value_type>
83 {
84 1861 value_type t;
85
2/2
✓ Branch 0 taken 1266 times.
✓ Branch 1 taken 595 times.
1861 if( it == end ||
86
2/2
✓ Branch 0 taken 1006 times.
✓ Branch 1 taken 260 times.
1266 *it != ':')
87 {
88 1601 t.has_port = false;
89 1601 return t;
90 }
91 260 ++it;
92 auto rv = grammar::parse(
93 260 it, end, port_rule{});
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 260 times.
260 if(! rv)
95 return rv.error();
96 260 t.has_port = true;
97 260 t.port = rv->str;
98 260 t.has_number = rv->has_number;
99 260 t.port_number = rv->number;
100 260 return t;
101 }
102
103 } // detail
104 } // urls
105 } // boost
106
107 #endif
108