1 +
//
 
2 +
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
 
3 +
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
 
4 +
//
 
5 +
// Distributed under the Boost Software License, Version 1.0. (See accompanying
 
6 +
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
7 +
//
 
8 +
// Official repository: https://github.com/boostorg/url
 
9 +
//
 
10 +

 
11 +
#ifndef BOOST_URL_RFC_DETAIL_IMPL_IP_LITERAL_RULE_HPP
 
12 +
#define BOOST_URL_RFC_DETAIL_IMPL_IP_LITERAL_RULE_HPP
 
13 +

 
14 +
#include <boost/url/detail/config.hpp>
 
15 +
#include <boost/url/rfc/ipv6_address_rule.hpp>
 
16 +
#include <boost/url/rfc/detail/ipv6_addrz_rule.hpp>
 
17 +
#include <boost/url/rfc/detail/ipvfuture_rule.hpp>
 
18 +
#include <boost/url/grammar/delim_rule.hpp>
 
19 +
#include <boost/url/grammar/error.hpp>
 
20 +
#include <boost/url/grammar/parse.hpp>
 
21 +
#include <boost/url/grammar/tuple_rule.hpp>
 
22 +

 
23 +
namespace boost {
 
24 +
namespace urls {
 
25 +
namespace detail {
 
26 +

 
27 +
inline BOOST_URL_CXX20_CONSTEXPR
 
28 +
auto
 
29 +
ip_literal_rule_t::
 
30 +
parse(
 
31 +
    char const*& it,
 
32 +
    char const* const end
 
33 +
        ) const noexcept ->
 
34 +
    system::result<value_type>
 
35 +
{
 
36 +
    value_type t;
 
37 +

 
38 +
    // '['
 
39 +
    {
 
40 +
        auto rv = grammar::parse(
 
41 +
            it, end, grammar::delim_rule('['));
 
42 +
        if(! rv)
 
43 +
            return rv.error();
 
44 +
    }
 
45 +
    if(it == end)
 
46 +
    {
 
47 +
        BOOST_URL_CONSTEXPR_RETURN_EC(
 
48 +
            grammar::error::invalid);
 
49 +
    }
 
50 +
    if(*it != 'v')
 
51 +
    {
 
52 +
        // IPv6address
 
53 +
        auto it0 = it;
 
54 +
        auto rv = grammar::parse(
 
55 +
            it, end,
 
56 +
            grammar::tuple_rule(
 
57 +
                ipv6_address_rule,
 
58 +
                grammar::squelch(
 
59 +
                    grammar::delim_rule(']'))));
 
60 +
        if(! rv)
 
61 +
        {
 
62 +
            // IPv6addrz
 
63 +
            it = it0;
 
64 +
            auto rv2 = grammar::parse(
 
65 +
                it, end,
 
66 +
                grammar::tuple_rule(
 
67 +
                    ipv6_addrz_rule,
 
68 +
                    grammar::squelch(
 
69 +
                        grammar::delim_rule(']'))));
 
70 +
            if(! rv2)
 
71 +
                return rv2.error();
 
72 +
            t.ipv6 = rv2->ipv6;
 
73 +
            t.is_ipv6 = true;
 
74 +
            return t;
 
75 +
        }
 
76 +
        t.ipv6 = *rv;
 
77 +
        t.is_ipv6 = true;
 
78 +
        return t;
 
79 +
    }
 
80 +
    {
 
81 +
        // IPvFuture
 
82 +
        auto rv = grammar::parse(
 
83 +
            it, end,
 
84 +
            grammar::tuple_rule(
 
85 +
                ipvfuture_rule,
 
86 +
                grammar::squelch(
 
87 +
                    grammar::delim_rule(']'))));
 
88 +
        if(! rv)
 
89 +
            return rv.error();
 
90 +
        t.is_ipv6 = false;
 
91 +
        t.ipvfuture = rv->str;
 
92 +
        return t;
 
93 +
    }
 
94 +
}
 
95 +

 
96 +
} // detail
 
97 +
} // urls
 
98 +
} // boost
 
99 +

 
100 +

 
101 +
#endif