1  
//
1  
//
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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 "ipvfuture_rule.hpp"
12  
#include "ipvfuture_rule.hpp"
13  
#include <boost/url/error.hpp>
13  
#include <boost/url/error.hpp>
14  
#include "charsets.hpp"
14  
#include "charsets.hpp"
15  
#include <boost/url/grammar/charset.hpp>
15  
#include <boost/url/grammar/charset.hpp>
16  
#include <boost/url/grammar/delim_rule.hpp>
16  
#include <boost/url/grammar/delim_rule.hpp>
17  
#include <boost/url/grammar/hexdig_chars.hpp>
17  
#include <boost/url/grammar/hexdig_chars.hpp>
18  
#include <boost/url/grammar/parse.hpp>
18  
#include <boost/url/grammar/parse.hpp>
19  
#include <boost/url/grammar/token_rule.hpp>
19  
#include <boost/url/grammar/token_rule.hpp>
20  
#include <boost/url/grammar/tuple_rule.hpp>
20  
#include <boost/url/grammar/tuple_rule.hpp>
21  

21  

22  
namespace boost {
22  
namespace boost {
23  
namespace urls {
23  
namespace urls {
24  
namespace detail {
24  
namespace detail {
25  

25  

26  
auto
26  
auto
27  
ipvfuture_rule_t::
27  
ipvfuture_rule_t::
28  
parse(
28  
parse(
29  
    char const*& it,
29  
    char const*& it,
30  
    char const* const end
30  
    char const* const end
31  
        ) const noexcept ->
31  
        ) const noexcept ->
32  
    system::result<value_type>
32  
    system::result<value_type>
33  
{
33  
{
34  
    static constexpr auto
34  
    static constexpr auto
35  
        minor_chars = 
35  
        minor_chars = 
36  
            unreserved_chars +
36  
            unreserved_chars +
37  
            sub_delim_chars + ':';
37  
            sub_delim_chars + ':';
38  
    auto const it0 = it;
38  
    auto const it0 = it;
39  
    auto rv = grammar::parse(
39  
    auto rv = grammar::parse(
40  
        it, end,
40  
        it, end,
41  
        grammar::tuple_rule(
41  
        grammar::tuple_rule(
42  
            grammar::delim_rule('v'),
42  
            grammar::delim_rule('v'),
43  
            grammar::token_rule(
43  
            grammar::token_rule(
44  
                grammar::hexdig_chars),
44  
                grammar::hexdig_chars),
45  
            grammar::delim_rule('.'),
45  
            grammar::delim_rule('.'),
46  
            grammar::token_rule(minor_chars)));
46  
            grammar::token_rule(minor_chars)));
47  
    if(! rv)
47  
    if(! rv)
48  
        return rv.error();
48  
        return rv.error();
49  
    value_type t;
49  
    value_type t;
50  
    t.major = std::get<0>(*rv);
50  
    t.major = std::get<0>(*rv);
51  
    t.minor = std::get<1>(*rv);
51  
    t.minor = std::get<1>(*rv);
52  
    if(t.major.empty())
52  
    if(t.major.empty())
53  
    {
53  
    {
54  
        // can't be empty
54  
        // can't be empty
55  
        BOOST_URL_RETURN_EC(
55  
        BOOST_URL_RETURN_EC(
56  
            grammar::error::invalid);
56  
            grammar::error::invalid);
57  
    }
57  
    }
58  
    if(t.minor.empty())
58  
    if(t.minor.empty())
59  
    {
59  
    {
60  
        // can't be empty
60  
        // can't be empty
61  
        BOOST_URL_RETURN_EC(
61  
        BOOST_URL_RETURN_EC(
62  
            grammar::error::invalid);
62  
            grammar::error::invalid);
63  
    }
63  
    }
64  
    t.str = core::string_view(
64  
    t.str = core::string_view(
65  
        it0, it - it0);
65  
        it0, it - it0);
66  
    return t;
66  
    return t;
67  
}
67  
}
68  

68  

69  
} // detail
69  
} // detail
70  
} // urls
70  
} // urls
71  
} // boost
71  
} // boost
72  

72