TLA Line data 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 : BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
25 : auto
26 HIT 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 29 : if (! rv1)
37 17 : return rv1.error();
38 12 : t.ipv6 = *rv1;
39 :
40 : // "%25"
41 12 : auto it0 = it;
42 12 : if (end - it < 3 ||
43 10 : *it != '%' ||
44 7 : *(it + 1) != '2' ||
45 6 : *(it + 2) != '5')
46 : {
47 6 : BOOST_URL_CONSTEXPR_RETURN_EC(
48 : grammar::error::invalid);
49 : }
50 6 : it += 3;
51 :
52 : // ZoneID = 1*( unreserved / pct-encoded )
53 : // Parse as many (unreserved / pct-encoded)
54 : // as available
55 6 : auto rv2 = grammar::parse(
56 : it, end,
57 6 : pct_encoded_rule(unreserved_chars));
58 6 : if(!rv2 || rv2->empty())
59 : {
60 1 : it = it0;
61 1 : BOOST_URL_CONSTEXPR_RETURN_EC(
62 : grammar::error::invalid);
63 : }
64 : else
65 : {
66 5 : t.zone_id = *rv2;
67 : }
68 5 : return t;
69 : }
70 :
71 : } // detail
72 : } // urls
73 : } // boost
74 :
75 :
76 : #endif
|