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  
#ifndef BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
10  
#ifndef BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
11  
#define BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
11  
#define BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
12  

12  

13  
#include <boost/url/detail/config.hpp>
13  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/grammar/error.hpp>
14  
#include <boost/url/grammar/error.hpp>
15  
#include <boost/url/grammar/parse.hpp>
15  
#include <boost/url/grammar/parse.hpp>
16  
#include <boost/url/rfc/ipv6_address_rule.hpp>
16  
#include <boost/url/rfc/ipv6_address_rule.hpp>
17  
#include <boost/url/rfc/unreserved_chars.hpp>
17  
#include <boost/url/rfc/unreserved_chars.hpp>
18  
#include <boost/url/rfc/pct_encoded_rule.hpp>
18  
#include <boost/url/rfc/pct_encoded_rule.hpp>
19  

19  

20  
namespace boost {
20  
namespace boost {
21  
namespace urls {
21  
namespace urls {
22  
namespace detail {
22  
namespace detail {
23  

23  

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

39  

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

51  

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

70  

71  
} // detail
71  
} // detail
72  
} // urls
72  
} // urls
73  
} // boost
73  
} // boost
74  

74  

75  

75  

76  
#endif
76  
#endif