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/uri_rule.hpp>
12  
#include <boost/url/rfc/uri_rule.hpp>
13  
#include <boost/url/rfc/query_rule.hpp>
13  
#include <boost/url/rfc/query_rule.hpp>
14  
#include "detail/fragment_part_rule.hpp"
14  
#include "detail/fragment_part_rule.hpp"
15  
#include "detail/hier_part_rule.hpp"
15  
#include "detail/hier_part_rule.hpp"
16  
#include "detail/query_part_rule.hpp"
16  
#include "detail/query_part_rule.hpp"
17  
#include "detail/scheme_rule.hpp"
17  
#include "detail/scheme_rule.hpp"
18  
#include <boost/url/grammar/delim_rule.hpp>
18  
#include <boost/url/grammar/delim_rule.hpp>
19  
#include <boost/url/grammar/tuple_rule.hpp>
19  
#include <boost/url/grammar/tuple_rule.hpp>
20  
#include <boost/url/grammar/optional_rule.hpp>
20  
#include <boost/url/grammar/optional_rule.hpp>
21  
#include <boost/url/grammar/parse.hpp>
21  
#include <boost/url/grammar/parse.hpp>
22  

22  

23  
namespace boost {
23  
namespace boost {
24  
namespace urls {
24  
namespace urls {
25  

25  

26  
auto
26  
auto
27  
implementation_defined::uri_rule_t::
27  
implementation_defined::uri_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  
    detail::url_impl u(detail::url_impl::from::string);
34  
    detail::url_impl u(detail::url_impl::from::string);
35  
    u.cs_ = it;
35  
    u.cs_ = it;
36  

36  

37  
    // scheme
37  
    // scheme
38  
    {
38  
    {
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  
                detail::scheme_rule(),
42  
                detail::scheme_rule(),
43  
                grammar::squelch(
43  
                grammar::squelch(
44  
                    grammar::delim_rule(':'))));
44  
                    grammar::delim_rule(':'))));
45  
        if(! rv)
45  
        if(! rv)
46  
            return rv.error();
46  
            return rv.error();
47  
        u.apply_scheme(rv->scheme);
47  
        u.apply_scheme(rv->scheme);
48  
    }
48  
    }
49  

49  

50  
    // hier_part
50  
    // hier_part
51  
    {
51  
    {
52  
        auto rv = grammar::parse(
52  
        auto rv = grammar::parse(
53  
            it, end,
53  
            it, end,
54  
            detail::hier_part_rule);
54  
            detail::hier_part_rule);
55  
        if(! rv)
55  
        if(! rv)
56  
            return rv.error();
56  
            return rv.error();
57  
        if(rv->has_authority)
57  
        if(rv->has_authority)
58  
            u.apply_authority(rv->authority);
58  
            u.apply_authority(rv->authority);
59  
        u.apply_path(
59  
        u.apply_path(
60  
            rv->path,
60  
            rv->path,
61  
            rv->segment_count);
61  
            rv->segment_count);
62  
    }
62  
    }
63  

63  

64  
    // [ "?" query ]
64  
    // [ "?" query ]
65  
    {
65  
    {
66  
        auto rv = grammar::parse(
66  
        auto rv = grammar::parse(
67  
            it, end, detail::query_part_rule);
67  
            it, end, detail::query_part_rule);
68  
        if(! rv)
68  
        if(! rv)
69  
            return rv.error();
69  
            return rv.error();
70  
        if(rv->has_query)
70  
        if(rv->has_query)
71  
        {
71  
        {
72  
            // map "?" to { {} }
72  
            // map "?" to { {} }
73  
            u.apply_query(
73  
            u.apply_query(
74  
                rv->query,
74  
                rv->query,
75  
                rv->count);
75  
                rv->count);
76  
        }
76  
        }
77  
    }
77  
    }
78  

78  

79  
    // [ "#" fragment ]
79  
    // [ "#" fragment ]
80  
    {
80  
    {
81  
        auto rv = grammar::parse(
81  
        auto rv = grammar::parse(
82  
            it, end, detail::fragment_part_rule);
82  
            it, end, detail::fragment_part_rule);
83  
        if(! rv)
83  
        if(! rv)
84  
            return rv.error();
84  
            return rv.error();
85  
        if(rv->has_fragment)
85  
        if(rv->has_fragment)
86  
            u.apply_frag(rv->fragment);
86  
            u.apply_frag(rv->fragment);
87  
    }
87  
    }
88  

88  

89  
    return u.construct();
89  
    return u.construct();
90  
}
90  
}
91  

91  

92  
} // urls
92  
} // urls
93  
} // boost
93  
} // boost
94  

94