include/boost/url/rfc/detail/fragment_part_rule.hpp

100.0% Lines (13/13) 100.0% Functions (1/1) 100.0% Branches (6/6)
include/boost/url/rfc/detail/fragment_part_rule.hpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
4 //
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)
7 //
8 // Official repository: https://github.com/boostorg/url
9 //
10
11 #ifndef BOOST_URL_RFC_DETAIL_FRAGMENT_PART_RULE_HPP
12 #define BOOST_URL_RFC_DETAIL_FRAGMENT_PART_RULE_HPP
13
14 #include "boost/url/rfc/pct_encoded_rule.hpp"
15 #include <boost/url/rfc/detail/charsets.hpp>
16 #include "boost/url/grammar/parse.hpp"
17
18 namespace boost {
19 namespace urls {
20 namespace detail {
21
22 /** Rule for fragment-part
23
24 @par BNF
25 @code
26 fragment-part = [ "#" fragment ]
27
28 fragment = *( pchar / "/" / "?" )
29 @endcode
30
31 @par Specification
32 @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5"
33 >3.5. Fragment (rfc3986)</a>
34 */
35 struct fragment_part_rule_t
36 {
37 struct value_type
38 {
39 pct_string_view fragment;
40 bool has_fragment = false;
41 };
42
43 BOOST_URL_CXX14_CONSTEXPR
44 system::result<value_type>
45 3690 parse(
46 char const*& it,
47 char const* end
48 ) const noexcept
49 {
50
2/2
✓ Branch 0 taken 418 times.
✓ Branch 1 taken 3272 times.
3690 if( it == end ||
51
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 246 times.
418 *it != '#')
52 3444 return {};
53 246 ++it;
54 246 auto rv = grammar::parse(
55 246 it, end, pct_encoded_rule(
56 fragment_chars));
57
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 244 times.
246 if(! rv)
58 2 return rv.error();
59 244 value_type t;
60 244 t.fragment = *rv;
61 244 t.has_fragment = true;
62 244 return t;
63 }
64 };
65 constexpr fragment_part_rule_t fragment_part_rule{};
66
67 } // detail
68 } // urls
69 } // boost
70
71 #endif
72