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

10  

11  
#ifndef BOOST_URL_RFC_IMPL_IPV4_ADDRESS_RULE_HPP
11  
#ifndef BOOST_URL_RFC_IMPL_IPV4_ADDRESS_RULE_HPP
12  
#define BOOST_URL_RFC_IMPL_IPV4_ADDRESS_RULE_HPP
12  
#define BOOST_URL_RFC_IMPL_IPV4_ADDRESS_RULE_HPP
13  

13  

14  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/detail/config.hpp>
15  
#include <boost/url/grammar/delim_rule.hpp>
15  
#include <boost/url/grammar/delim_rule.hpp>
16  
#include <boost/url/grammar/dec_octet_rule.hpp>
16  
#include <boost/url/grammar/dec_octet_rule.hpp>
17  
#include <boost/url/grammar/parse.hpp>
17  
#include <boost/url/grammar/parse.hpp>
18  
#include <boost/url/grammar/tuple_rule.hpp>
18  
#include <boost/url/grammar/tuple_rule.hpp>
19  

19  

20  
namespace boost {
20  
namespace boost {
21  
namespace urls {
21  
namespace urls {
22  

22  

23  
BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
23  
BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
24  
auto
24  
auto
25  
implementation_defined::ipv4_address_rule_t::
25  
implementation_defined::ipv4_address_rule_t::
26  
parse(
26  
parse(
27  
    char const*& it,
27  
    char const*& it,
28  
    char const* end
28  
    char const* end
29  
        ) const noexcept ->
29  
        ) const noexcept ->
30  
    system::result<value_type>
30  
    system::result<value_type>
31  
{
31  
{
32  
    using namespace grammar;
32  
    using namespace grammar;
33  
    auto rv = grammar::parse(
33  
    auto rv = grammar::parse(
34  
        it, end, tuple_rule(
34  
        it, end, tuple_rule(
35  
            dec_octet_rule, squelch(delim_rule('.')),
35  
            dec_octet_rule, squelch(delim_rule('.')),
36  
            dec_octet_rule, squelch(delim_rule('.')),
36  
            dec_octet_rule, squelch(delim_rule('.')),
37  
            dec_octet_rule, squelch(delim_rule('.')),
37  
            dec_octet_rule, squelch(delim_rule('.')),
38  
            dec_octet_rule));
38  
            dec_octet_rule));
39  
    if(! rv)
39  
    if(! rv)
40  
        return rv.error();
40  
        return rv.error();
41  
    std::array<unsigned char, 4> v;
41  
    std::array<unsigned char, 4> v;
42  
    v[0] = std::get<0>(*rv);
42  
    v[0] = std::get<0>(*rv);
43  
    v[1] = std::get<1>(*rv);
43  
    v[1] = std::get<1>(*rv);
44  
    v[2] = std::get<2>(*rv);
44  
    v[2] = std::get<2>(*rv);
45  
    v[3] = std::get<3>(*rv);
45  
    v[3] = std::get<3>(*rv);
46  
    return ipv4_address(v);
46  
    return ipv4_address(v);
47  
}
47  
}
48  

48  

49  
} // urls
49  
} // urls
50  
} // boost
50  
} // boost
51  

51  

52  

52  

53  
#endif
53  
#endif