include/boost/url/rfc/detail/impl/ipv6_addrz_rule.hpp

100.0% Lines (20/20) 100.0% Functions (1/1) 87.5% Branches (14/16)
include/boost/url/rfc/detail/impl/ipv6_addrz_rule.hpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.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_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
11 #define BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
12
13 #include <boost/url/detail/config.hpp>
14 #include <boost/url/grammar/error.hpp>
15 #include <boost/url/grammar/parse.hpp>
16 #include <boost/url/rfc/ipv6_address_rule.hpp>
17 #include <boost/url/rfc/unreserved_chars.hpp>
18 #include <boost/url/rfc/pct_encoded_rule.hpp>
19
20 namespace boost {
21 namespace urls {
22 namespace detail {
23
24 inline BOOST_URL_CXX20_CONSTEXPR
25 auto
26 29 ipv6_addrz_rule_t::
27 parse(
28 char const*& it,
29 char const* const end
30 ) const noexcept ->
31 system::result<value_type>
32 {
33 29 value_type t;
34 29 auto rv1 = grammar::parse(
35 it, end, ipv6_address_rule);
36
2/2
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 12 times.
29 if (! rv1)
37 17 return rv1.error();
38 12 t.ipv6 = *rv1;
39
40 // "%25"
41 12 auto it0 = it;
42
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
12 if (end - it < 3 ||
43
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
10 *it != '%' ||
44
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 time.
7 *(it + 1) != '2' ||
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 *(it + 2) != '5')
46 {
47 6 BOOST_URL_CONSTEXPR_RETURN_EC(
48 grammar::error::invalid);
49 }
50 6 it += 3;
51
52 6 auto rv2 = grammar::parse(
53 it, end,
54 6 pct_encoded_rule(unreserved_chars));
55
5/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 5 times.
6 if(!rv2 || rv2->empty())
56 {
57 1 it = it0;
58 1 BOOST_URL_CONSTEXPR_RETURN_EC(
59 grammar::error::invalid);
60 }
61 else
62 {
63 5 t.zone_id = *rv2;
64 }
65 5 return t;
66 }
67
68 } // detail
69 } // urls
70 } // boost
71
72
73 #endif
74