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 -

 
11 -
#include <boost/url/detail/config.hpp>
 
12 -
#include <boost/url/grammar/parse.hpp>
 
13 -
#include "ipv6_addrz_rule.hpp"
 
14 -
#include <boost/url/rfc/ipv6_address_rule.hpp>
 
15 -
#include <boost/url/rfc/unreserved_chars.hpp>
 
16 -
#include <boost/url/rfc/pct_encoded_rule.hpp>
 
17 -

 
18 -
namespace boost {
 
19 -
namespace urls {
 
20 -
namespace detail {
 
21 -

 
22 -
auto
 
23 -
ipv6_addrz_rule_t::
 
24 -
parse(
 
25 -
    char const*& it,
 
26 -
    char const* const end
 
27 -
        ) const noexcept ->
 
28 -
    system::result<value_type>
 
29 -
{
 
30 -
    value_type t;
 
31 -
    auto rv1 = grammar::parse(
 
32 -
        it, end, ipv6_address_rule);
 
33 -
    if (! rv1)
 
34 -
        return rv1.error();
 
35 -
    t.ipv6 = *rv1;
 
36 -

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

 
49 -
    // ZoneID = 1*( unreserved / pct-encoded )
 
50 -
    // Parse as many (unreserved / pct-encoded)
 
51 -
    // as available
 
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_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 -