GCC Code Coverage Report


Directory: libs/url/
File: include/boost/url/rfc/pct_encoded_rule.hpp
Date: 2025-04-22 15:26:26
Exec Total Coverage
Lines: 5 5 100.0%
Functions: 3 4 75.0%
Branches: 0 0 -%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7 // Official repository: https://github.com/boostorg/url
8 //
9
10 #ifndef BOOST_URL_RFC_PCT_ENCODED_RULE_HPP
11 #define BOOST_URL_RFC_PCT_ENCODED_RULE_HPP
12
13 #include <boost/url/detail/config.hpp>
14 #include <boost/url/error_types.hpp>
15 #include <boost/url/pct_string_view.hpp>
16 #include <boost/url/grammar/charset.hpp>
17
18 namespace boost {
19 namespace urls {
20
21 /** Rule for a string with percent-encoded escapes
22
23 This function returns a rule which matches
24 a percent-encoded string, permitting characters
25 in the string which are also in the specified
26 character set to be used unescaped.
27
28 @par Value Type
29 @code
30 using value_type = pct_string_view;
31 @endcode
32
33 @par Example
34 Rules are used with the function @ref grammar::parse.
35 @code
36 // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
37
38 system::result< pct_string_view > rv = grammar::parse( "Program%20Files", pct_encoded_rule( pchars ) );
39 @endcode
40
41 @par BNF
42 @code
43 pct-encoded = "%" HEXDIG HEXDIG
44 @endcode
45
46 @param cs The character set indicating
47 which characters are allowed without escapes.
48 Any character which is not in this set must be
49 escaped, or else parsing returns an error.
50
51 @par Specification
52 @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-2.1">
53 2.1. Percent-Encoding (rfc3986)</a>
54
55 @see
56 @ref grammar::parse,
57 @ref pchars,
58 @ref pct_string_view.
59 */
60 #ifdef BOOST_URL_DOCS
61 /**@{*/
62 template<class CharSet>
63 constexpr
64 __implementation_defined__
65 pct_encoded_rule( CharSet const& cs ) noexcept;
66 /**@}*/
67 #else
68 namespace implementation_defined {
69 template<class CharSet>
70 struct pct_encoded_rule_t
71 {
72 using value_type = pct_string_view;
73
74 system::result<value_type>
75 parse(
76 char const*& it,
77 char const* end) const noexcept;
78
79 constexpr
80 5508 pct_encoded_rule_t(
81 CharSet const& cs) noexcept
82 5508 : cs_(cs)
83 {
84 5508 }
85
86 private:
87 CharSet cs_;
88 };
89 } // implementation_defined
90
91 /** Rule for a string with percent-encoded escapes
92
93 This function returns a rule which matches
94 a percent-encoded string, permitting characters
95 in the string which are also in the specified
96 character set to be used unescaped.
97
98 @par Value Type
99 @code
100 using value_type = pct_string_view;
101 @endcode
102
103 @par Example
104 Rules are used with the function @ref grammar::parse.
105 @code
106 // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
107
108 system::result< pct_string_view > rv = grammar::parse( "Program%20Files", pct_encoded_rule( pchars ) );
109 @endcode
110
111 @par BNF
112 @code
113 pct-encoded = "%" HEXDIG HEXDIG
114 @endcode
115
116 @param cs The character set indicating
117 which characters are allowed without escapes.
118 Any character which is not in this set must be
119 escaped, or else parsing returns an error.
120
121 @return A rule object.
122
123 @par Specification
124 @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-2.1">
125 2.1. Percent-Encoding (rfc3986)</a>
126
127 @see
128 @ref grammar::parse,
129 @ref pchars,
130 @ref pct_string_view.
131 */
132 template<BOOST_URL_CONSTRAINT(grammar::CharSet) CS>
133 constexpr
134 auto
135 3258 pct_encoded_rule(CS const& cs) noexcept ->
136 implementation_defined::pct_encoded_rule_t<CS>
137 {
138 // If an error occurs here it means that
139 // the value of your type does not meet
140 // the requirements. Please check the
141 // documentation!
142 static_assert(
143 grammar::is_charset<CS>::value,
144 "CharSet requirements not met");
145
146 3258 return implementation_defined::pct_encoded_rule_t<CS>(cs);
147 }
148
149 #endif
150
151 } // urls
152 } // boost
153
154 #include <boost/url/rfc/impl/pct_encoded_rule.hpp>
155
156 #endif
157