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_DETAIL_FRAGMENT_PART_RULE_HPP
11  
#ifndef BOOST_URL_RFC_DETAIL_FRAGMENT_PART_RULE_HPP
12  
#define BOOST_URL_RFC_DETAIL_FRAGMENT_PART_RULE_HPP
12  
#define BOOST_URL_RFC_DETAIL_FRAGMENT_PART_RULE_HPP
13  

13  

14  
#include <boost/url/rfc/pct_encoded_rule.hpp>
14  
#include <boost/url/rfc/pct_encoded_rule.hpp>
15  
#include <boost/url/rfc/detail/charsets.hpp>
15  
#include <boost/url/rfc/detail/charsets.hpp>
16  
#include <boost/url/grammar/parse.hpp>
16  
#include <boost/url/grammar/parse.hpp>
17  

17  

18  
namespace boost {
18  
namespace boost {
19  
namespace urls {
19  
namespace urls {
20  
namespace detail {
20  
namespace detail {
21  

21  

22  
/** Rule for fragment-part
22  
/** Rule for fragment-part
23  

23  

24  
    @par BNF
24  
    @par BNF
25  
    @code
25  
    @code
26  
    fragment-part   = [ "#" fragment ]
26  
    fragment-part   = [ "#" fragment ]
27  

27  

28  
    fragment        = *( pchar / "/" / "?" )
28  
    fragment        = *( pchar / "/" / "?" )
29  
    @endcode
29  
    @endcode
30  

30  

31  
    @par Specification
31  
    @par Specification
32  
    @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5"
32  
    @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5"
33  
        >3.5. Fragment (rfc3986)</a>
33  
        >3.5. Fragment (rfc3986)</a>
34  
*/
34  
*/
35  
struct fragment_part_rule_t
35  
struct fragment_part_rule_t
36  
{
36  
{
37  
    struct value_type
37  
    struct value_type
38  
    {
38  
    {
39  
        pct_string_view fragment;
39  
        pct_string_view fragment;
40  
        bool has_fragment = false;
40  
        bool has_fragment = false;
41  
    };
41  
    };
42  

42  

43  
    BOOST_URL_CXX14_CONSTEXPR
43  
    BOOST_URL_CXX14_CONSTEXPR
44  
    system::result<value_type>
44  
    system::result<value_type>
45  
    parse(
45  
    parse(
46  
        char const*& it,
46  
        char const*& it,
47  
        char const* end
47  
        char const* end
48  
            ) const noexcept
48  
            ) const noexcept
49  
    {
49  
    {
50  
        if( it == end ||
50  
        if( it == end ||
51  
            *it != '#')
51  
            *it != '#')
52  
            return {};
52  
            return {};
53  
        ++it;
53  
        ++it;
54  
        auto rv = grammar::parse(
54  
        auto rv = grammar::parse(
55  
            it, end, pct_encoded_rule(
55  
            it, end, pct_encoded_rule(
56  
                fragment_chars));
56  
                fragment_chars));
57  
        if(! rv)
57  
        if(! rv)
58  
            return rv.error();
58  
            return rv.error();
59  
        value_type t;
59  
        value_type t;
60  
        t.fragment = *rv;
60  
        t.fragment = *rv;
61  
        t.has_fragment = true;
61  
        t.has_fragment = true;
62  
        return t;
62  
        return t;
63  
    }
63  
    }
64  
};
64  
};
65  
constexpr fragment_part_rule_t fragment_part_rule{};
65  
constexpr fragment_part_rule_t fragment_part_rule{};
66  

66  

67  
} // detail
67  
} // detail
68  
} // urls
68  
} // urls
69  
} // boost
69  
} // boost
70  

70  

71  
#endif
71  
#endif