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 <boost/url/rfc/origin_form_rule.hpp>
12  
#include <boost/url/rfc/origin_form_rule.hpp>
13  
#include <boost/url/rfc/query_rule.hpp>
13  
#include <boost/url/rfc/query_rule.hpp>
14  
#include "boost/url/rfc/detail/path_rules.hpp"
14  
#include "boost/url/rfc/detail/path_rules.hpp"
15  
#include "detail/query_part_rule.hpp"
15  
#include "detail/query_part_rule.hpp"
16  
#include <boost/url/grammar/delim_rule.hpp>
16  
#include <boost/url/grammar/delim_rule.hpp>
17  
#include <boost/url/grammar/range_rule.hpp>
17  
#include <boost/url/grammar/range_rule.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  
auto
23  
auto
24  
implementation_defined::origin_form_rule_t::
24  
implementation_defined::origin_form_rule_t::
25  
parse(
25  
parse(
26  
    char const*& it,
26  
    char const*& it,
27  
    char const* end
27  
    char const* end
28  
        ) const noexcept ->
28  
        ) const noexcept ->
29  
    system::result<value_type>
29  
    system::result<value_type>
30  
{
30  
{
31  
    detail::url_impl u(detail::url_impl::from::string);
31  
    detail::url_impl u(detail::url_impl::from::string);
32  
    u.cs_ = it;
32  
    u.cs_ = it;
33  

33  

34  
    {
34  
    {
35  
        auto rv = grammar::parse(it, end,
35  
        auto rv = grammar::parse(it, end,
36  
            grammar::range_rule(
36  
            grammar::range_rule(
37  
                grammar::tuple_rule(
37  
                grammar::tuple_rule(
38  
                    grammar::delim_rule('/'),
38  
                    grammar::delim_rule('/'),
39  
                    detail::segment_rule),
39  
                    detail::segment_rule),
40  
                1));
40  
                1));
41  
        if(! rv)
41  
        if(! rv)
42  
            return rv.error();
42  
            return rv.error();
43  
        u.apply_path(
43  
        u.apply_path(
44  
            rv->string(),
44  
            rv->string(),
45  
            rv->size());
45  
            rv->size());
46  
    }
46  
    }
47  

47  

48  
    // [ "?" query ]
48  
    // [ "?" query ]
49  
    {
49  
    {
50  
        auto rv = grammar::parse(
50  
        auto rv = grammar::parse(
51  
            it, end, detail::query_part_rule);
51  
            it, end, detail::query_part_rule);
52  
        if(! rv)
52  
        if(! rv)
53  
            return rv.error();
53  
            return rv.error();
54  
        if(rv->has_query)
54  
        if(rv->has_query)
55  
        {
55  
        {
56  
            // map "?" to { {} }
56  
            // map "?" to { {} }
57  
            u.apply_query(
57  
            u.apply_query(
58  
                rv->query,
58  
                rv->query,
59  
                rv->count);
59  
                rv->count);
60  
        }
60  
        }
61  
    }
61  
    }
62  

62  

63  
    return u.construct();
63  
    return u.construct();
64  
}
64  
}
65  

65  

66  
} // urls
66  
} // urls
67  
} // boost
67  
} // boost
68  

68