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  
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
3  
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_URL_RFC_IMPL_RELATIVE_REF_RULE_HPP
11  
#ifndef BOOST_URL_RFC_IMPL_RELATIVE_REF_RULE_HPP
12  
#define BOOST_URL_RFC_IMPL_RELATIVE_REF_RULE_HPP
12  
#define BOOST_URL_RFC_IMPL_RELATIVE_REF_RULE_HPP
13  

13  

14  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/detail/config.hpp>
15  
#include <boost/url/url_view.hpp>
15  
#include <boost/url/url_view.hpp>
16  
#include <boost/url/grammar/delim_rule.hpp>
16  
#include <boost/url/grammar/delim_rule.hpp>
17  
#include <boost/url/grammar/tuple_rule.hpp>
17  
#include <boost/url/grammar/tuple_rule.hpp>
18  
#include <boost/url/grammar/optional_rule.hpp>
18  
#include <boost/url/grammar/optional_rule.hpp>
19  
#include <boost/url/grammar/parse.hpp>
19  
#include <boost/url/grammar/parse.hpp>
20  
#include <boost/url/rfc/detail/fragment_part_rule.hpp>
20  
#include <boost/url/rfc/detail/fragment_part_rule.hpp>
21  
#include <boost/url/rfc/detail/query_part_rule.hpp>
21  
#include <boost/url/rfc/detail/query_part_rule.hpp>
22  
#include <boost/url/rfc/detail/relative_part_rule.hpp>
22  
#include <boost/url/rfc/detail/relative_part_rule.hpp>
23  

23  

24  
namespace boost {
24  
namespace boost {
25  
namespace urls {
25  
namespace urls {
26  

26  

27  
BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
27  
BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
28  
auto
28  
auto
29  
implementation_defined::relative_ref_rule_t::
29  
implementation_defined::relative_ref_rule_t::
30  
parse(
30  
parse(
31  
    char const*& it,
31  
    char const*& it,
32  
    char const* const end
32  
    char const* const end
33  
        ) const noexcept ->
33  
        ) const noexcept ->
34  
    system::result<value_type>
34  
    system::result<value_type>
35  
{
35  
{
36  
    detail::url_impl u(detail::url_impl::from::string);
36  
    detail::url_impl u(detail::url_impl::from::string);
37  
    u.cs_ = it;
37  
    u.cs_ = it;
38  

38  

39  
    // relative-part
39  
    // relative-part
40  
    {
40  
    {
41  
        auto rv = grammar::parse(
41  
        auto rv = grammar::parse(
42  
            it, end,
42  
            it, end,
43  
            detail::relative_part_rule);
43  
            detail::relative_part_rule);
44  
        if(! rv)
44  
        if(! rv)
45  
            return rv.error();
45  
            return rv.error();
46  
        if(rv->has_authority)
46  
        if(rv->has_authority)
47  
            u.apply_authority(rv->authority.u_);
47  
            u.apply_authority(rv->authority.u_);
48  
        u.apply_path(
48  
        u.apply_path(
49  
            rv->path, rv->segment_count);
49  
            rv->path, rv->segment_count);
50  
    }
50  
    }
51  

51  

52  
    // [ "?" query ]
52  
    // [ "?" query ]
53  
    {
53  
    {
54  
        auto rv = grammar::parse(
54  
        auto rv = grammar::parse(
55  
            it, end, detail::query_part_rule);
55  
            it, end, detail::query_part_rule);
56  
        if(! rv)
56  
        if(! rv)
57  
            return rv.error();
57  
            return rv.error();
58  
        auto& v = *rv;
58  
        auto& v = *rv;
59  
        if(v.has_query)
59  
        if(v.has_query)
60  
        {
60  
        {
61  
            // map "?" to { {} }
61  
            // map "?" to { {} }
62  
            u.apply_query(
62  
            u.apply_query(
63  
                v.query,
63  
                v.query,
64  
                v.count);
64  
                v.count);
65  
        }
65  
        }
66  
    }
66  
    }
67  

67  

68  
    // [ "#" fragment ]
68  
    // [ "#" fragment ]
69  
    {
69  
    {
70  
        auto rv = grammar::parse(
70  
        auto rv = grammar::parse(
71  
            it, end, detail::fragment_part_rule);
71  
            it, end, detail::fragment_part_rule);
72  
        if(! rv)
72  
        if(! rv)
73  
            return rv.error();
73  
            return rv.error();
74  
        if(rv->has_fragment)
74  
        if(rv->has_fragment)
75  
            u.apply_frag(rv->fragment);
75  
            u.apply_frag(rv->fragment);
76  
    }
76  
    }
77  

77  

78  
    return url_view(u);
78  
    return url_view(u);
79  
}
79  
}
80  

80  

81  
} // urls
81  
} // urls
82  
} // boost
82  
} // boost
83  

83  

84  

84  

85  
#endif
85  
#endif