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  
#ifndef BOOST_URL_GRAMMAR_IMPL_PARSE_HPP
10  
#ifndef BOOST_URL_GRAMMAR_IMPL_PARSE_HPP
11  
#define BOOST_URL_GRAMMAR_IMPL_PARSE_HPP
11  
#define BOOST_URL_GRAMMAR_IMPL_PARSE_HPP
12  

12  

13  
#include <boost/url/grammar/error.hpp>
13  
#include <boost/url/grammar/error.hpp>
14  
#include <boost/url/grammar/type_traits.hpp>
14  
#include <boost/url/grammar/type_traits.hpp>
15  

15  

16  
namespace boost {
16  
namespace boost {
17  
namespace urls {
17  
namespace urls {
18  
namespace grammar {
18  
namespace grammar {
19  

19  

20  
template<BOOST_URL_CONSTRAINT(Rule) R>
20  
template<BOOST_URL_CONSTRAINT(Rule) R>
21  
BOOST_URL_NO_INLINE
21  
BOOST_URL_NO_INLINE
22  
auto
22  
auto
23  
parse(
23  
parse(
24  
    char const*& it,
24  
    char const*& it,
25  
    char const* end,
25  
    char const* end,
26  
    R const& r) ->
26  
    R const& r) ->
27  
        system::result<typename R::value_type>
27  
        system::result<typename R::value_type>
28  
{
28  
{
29  
    // If this goes off, it means the rule
29  
    // If this goes off, it means the rule
30  
    // passed in did not meet the requirements.
30  
    // passed in did not meet the requirements.
31  
    // Please check the documentation.
31  
    // Please check the documentation.
32  
    static_assert(
32  
    static_assert(
33  
        is_rule<R>::value,
33  
        is_rule<R>::value,
34  
        "Rule requirements not met");
34  
        "Rule requirements not met");
35  

35  

36  
    return r.parse(it, end);
36  
    return r.parse(it, end);
37  
}
37  
}
38  

38  

39  
template<BOOST_URL_CONSTRAINT(Rule) R>
39  
template<BOOST_URL_CONSTRAINT(Rule) R>
40  
BOOST_URL_NO_INLINE
40  
BOOST_URL_NO_INLINE
41  
auto
41  
auto
42  
parse(
42  
parse(
43  
    core::string_view s,
43  
    core::string_view s,
44  
    R const& r) ->
44  
    R const& r) ->
45  
        system::result<typename R::value_type>
45  
        system::result<typename R::value_type>
46  
{
46  
{
47  
    // If this goes off, it means the rule
47  
    // If this goes off, it means the rule
48  
    // passed in did not meet the requirements.
48  
    // passed in did not meet the requirements.
49  
    // Please check the documentation.
49  
    // Please check the documentation.
50  
    static_assert(
50  
    static_assert(
51  
        is_rule<R>::value,
51  
        is_rule<R>::value,
52  
        "Rule requirements not met");
52  
        "Rule requirements not met");
53  

53  

54  
    auto it = s.data();
54  
    auto it = s.data();
55  
    auto const end = it + s.size();
55  
    auto const end = it + s.size();
56  
    auto rv = r.parse(it, end);
56  
    auto rv = r.parse(it, end);
57  
    if( rv &&
57  
    if( rv &&
58  
        it != end)
58  
        it != end)
59  
        return error::leftover;
59  
        return error::leftover;
60  
    return rv;
60  
    return rv;
61  
}
61  
}
62  

62  

63  
} // grammar
63  
} // grammar
64  
} // urls
64  
} // urls
65  
} // boost
65  
} // boost
66  

66  

67  
#endif
67  
#endif