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 +
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 +
    value_type t;
 
34 +
    auto rv1 = grammar::parse(
 
35 +
        it, end, ipv6_address_rule);
 
36 +
    if (! rv1)
 
37 +
        return rv1.error();
 
38 +
    t.ipv6 = *rv1;
 
39 +

 
40 +
    // "%25"
 
41 +
    auto it0 = it;
 
42 +
    if (end - it < 3 ||
 
43 +
        *it != '%' ||
 
44 +
        *(it + 1) != '2' ||
 
45 +
        *(it + 2) != '5')
 
46 +
    {
 
47 +
        BOOST_URL_CONSTEXPR_RETURN_EC(
 
48 +
            grammar::error::invalid);
 
49 +
    }
 
50 +
    it += 3;
 
51 +

 
52 +
    auto rv2 = grammar::parse(
 
53 +
            it, end,
 
54 +
            pct_encoded_rule(unreserved_chars));
 
55 +
    if(!rv2 || rv2->empty())
 
56 +
    {
 
57 +
        it = it0;
 
58 +
        BOOST_URL_CONSTEXPR_RETURN_EC(
 
59 +
            grammar::error::invalid);
 
60 +
    }
 
61 +
    else
 
62 +
    {
 
63 +
        t.zone_id = *rv2;
 
64 +
    }
 
65 +
    return t;
 
66 +
}
 
67 +

 
68 +
} // detail
 
69 +
} // urls
 
70 +
} // boost
 
71 +

 
72 +

 
73 +
#endif