1  
//
1  
//
2  
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
2  
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/boostorg/url
7  
// Official repository: https://github.com/boostorg/url
8  
//
8  
//
9  

9  

10  

10  

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

17  

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

21  

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

36  

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

48  

49  
    // ZoneID = 1*( unreserved / pct-encoded )
49  
    // ZoneID = 1*( unreserved / pct-encoded )
50  
    // Parse as many (unreserved / pct-encoded)
50  
    // Parse as many (unreserved / pct-encoded)
51  
    // as available
51  
    // as available
52  
    auto rv2 = grammar::parse(
52  
    auto rv2 = grammar::parse(
53  
            it, end,
53  
            it, end,
54  
            pct_encoded_rule(unreserved_chars));
54  
            pct_encoded_rule(unreserved_chars));
55  
    if(!rv2 || rv2->empty())
55  
    if(!rv2 || rv2->empty())
56  
    {
56  
    {
57  
        it = it0;
57  
        it = it0;
58  
        BOOST_URL_RETURN_EC(
58  
        BOOST_URL_RETURN_EC(
59  
            grammar::error::invalid);
59  
            grammar::error::invalid);
60  
    }
60  
    }
61  
    else
61  
    else
62  
    {
62  
    {
63  
        t.zone_id = *rv2;
63  
        t.zone_id = *rv2;
64  
    }
64  
    }
65  
    return t;
65  
    return t;
66  
}
66  
}
67  

67  

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

71