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

12  

13  
#include "boost/url/rfc/pct_encoded_rule.hpp"
13  
#include "boost/url/rfc/pct_encoded_rule.hpp"
14  
#include "charsets.hpp"
14  
#include "charsets.hpp"
15  
#include "boost/url/grammar/parse.hpp"
15  
#include "boost/url/grammar/parse.hpp"
16  

16  

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

20  

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

22  

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

26  

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

29  

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

41  

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

64  

65  
} // detail
65  
} // detail
66  
} // urls
66  
} // urls
67  
} // boost
67  
} // boost
68  

68  

69  
#endif
69  
#endif