1  
//
1  
//
2  
// Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2022 Vinnie Falco (vinnie.falco@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/rfc/ipv4_address_rule.hpp>
12  
#include <boost/url/rfc/ipv4_address_rule.hpp>
13  
#include <boost/url/grammar/delim_rule.hpp>
13  
#include <boost/url/grammar/delim_rule.hpp>
14  
#include <boost/url/grammar/dec_octet_rule.hpp>
14  
#include <boost/url/grammar/dec_octet_rule.hpp>
15  
#include <boost/url/grammar/parse.hpp>
15  
#include <boost/url/grammar/parse.hpp>
16  
#include <boost/url/grammar/tuple_rule.hpp>
16  
#include <boost/url/grammar/tuple_rule.hpp>
17  

17  

18  
namespace boost {
18  
namespace boost {
19  
namespace urls {
19  
namespace urls {
20  

20  

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

45  

46  
} // urls
46  
} // urls
47  
} // boost
47  
} // boost
48  

48