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

94.7% Lines (36 / 38) 100.0% Functions (1 / 1)
ip_literal_rule.hpp
f(x) Functions (1)
Line TLA 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_IP_LITERAL_RULE_HPP
12 #define BOOST_URL_RFC_DETAIL_IMPL_IP_LITERAL_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/rfc/ipv6_address_rule.hpp>
16 #include <boost/url/rfc/detail/ipv6_addrz_rule.hpp>
17 #include <boost/url/rfc/detail/ipvfuture_rule.hpp>
18 #include <boost/url/grammar/delim_rule.hpp>
19 #include <boost/url/grammar/error.hpp>
20 #include <boost/url/grammar/parse.hpp>
21 #include <boost/url/grammar/tuple_rule.hpp>
22
23 namespace boost {
24 namespace urls {
25 namespace detail {
26
27 BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
28 auto
29 92x ip_literal_rule_t::
30 parse(
31 char const*& it,
32 char const* const end
33 ) const noexcept ->
34 system::result<value_type>
35 {
36 92x value_type t;
37
38 // '['
39 {
40 92x auto rv = grammar::parse(
41 92x it, end, grammar::delim_rule('['));
42 92x if(! rv)
43 ✗ return rv.error();
44 }
45 92x if(it == end)
46 {
47 // end
48 1x BOOST_URL_CONSTEXPR_RETURN_EC(
49 grammar::error::invalid);
50 }
51 91x if(*it != 'v')
52 {
53 // IPv6address
54 86x auto it0 = it;
55 86x auto rv = grammar::parse(
56 it, end,
57 86x grammar::tuple_rule(
58 ipv6_address_rule,
59 86x grammar::squelch(
60 86x grammar::delim_rule(']'))));
61 86x if(! rv)
62 {
63 // IPv6addrz: https://datatracker.ietf.org/doc/html/rfc6874
64 46x it = it0;
65 46x auto rv2 = grammar::parse(
66 it, end,
67 46x grammar::tuple_rule(
68 ipv6_addrz_rule,
69 46x grammar::squelch(
70 46x grammar::delim_rule(']'))));
71 46x if(! rv2)
72 25x return rv2.error();
73 21x t.ipv6 = rv2->ipv6;
74 21x t.zone_id = rv2->zone_id;
75 21x t.is_ipv6 = true;
76 21x return t;
77 }
78 40x t.ipv6 = *rv;
79 40x t.is_ipv6 = true;
80 40x return t;
81 }
82 {
83 // IPvFuture
84 5x auto rv = grammar::parse(
85 it, end,
86 5x grammar::tuple_rule(
87 ipvfuture_rule,
88 5x grammar::squelch(
89 5x grammar::delim_rule(']'))));
90 5x if(! rv)
91 ✗ return rv.error();
92 5x t.is_ipv6 = false;
93 5x t.ipvfuture = rv->str;
94 5x return t;
95 }
96 }
97
98 } // detail
99 } // urls
100 } // boost
101
102
103 #endif
104