Line data Source code
1 : //
2 : // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.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_IMPL_IPV4_ADDRESS_RULE_HPP
12 : #define BOOST_URL_RFC_IMPL_IPV4_ADDRESS_RULE_HPP
13 :
14 : #include <boost/url/detail/config.hpp>
15 : #include <boost/url/grammar/delim_rule.hpp>
16 : #include <boost/url/grammar/dec_octet_rule.hpp>
17 : #include <boost/url/grammar/parse.hpp>
18 : #include <boost/url/grammar/tuple_rule.hpp>
19 :
20 : namespace boost {
21 : namespace urls {
22 :
23 : inline BOOST_URL_CXX20_CONSTEXPR
24 : auto
25 2012 : implementation_defined::ipv4_address_rule_t::
26 : parse(
27 : char const*& it,
28 : char const* end
29 : ) const noexcept ->
30 : system::result<value_type>
31 : {
32 : using namespace grammar;
33 : auto rv = grammar::parse(
34 2012 : it, end, tuple_rule(
35 2012 : dec_octet_rule, squelch(delim_rule('.')),
36 2012 : dec_octet_rule, squelch(delim_rule('.')),
37 2012 : dec_octet_rule, squelch(delim_rule('.')),
38 2012 : dec_octet_rule));
39 2012 : if(! rv)
40 1895 : return rv.error();
41 : std::array<unsigned char, 4> v;
42 117 : v[0] = std::get<0>(*rv);
43 117 : v[1] = std::get<1>(*rv);
44 117 : v[2] = std::get<2>(*rv);
45 117 : v[3] = std::get<3>(*rv);
46 117 : return ipv4_address(v);
47 : }
48 :
49 : } // urls
50 : } // boost
51 :
52 :
53 : #endif
|