Line data Source code
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 : template<class CharSet>
69 : struct pct_encoded_rule_t
70 : {
71 : using value_type = pct_string_view;
72 :
73 : template<class CharSet_>
74 : friend
75 : constexpr
76 : auto
77 : pct_encoded_rule(
78 : CharSet_ const& cs) noexcept ->
79 : pct_encoded_rule_t<CharSet_>;
80 :
81 : system::result<value_type>
82 : parse(
83 : char const*& it,
84 : char const* end) const noexcept;
85 :
86 : private:
87 : constexpr
88 3250 : pct_encoded_rule_t(
89 : CharSet const& cs) noexcept
90 3250 : : cs_(cs)
91 : {
92 3250 : }
93 :
94 : CharSet cs_;
95 : };
96 :
97 : template<class CharSet>
98 : constexpr
99 : auto
100 3250 : pct_encoded_rule(
101 : CharSet const& cs) noexcept ->
102 : pct_encoded_rule_t<CharSet>
103 : {
104 : // If an error occurs here it means that
105 : // the value of your type does not meet
106 : // the requirements. Please check the
107 : // documentation!
108 : static_assert(
109 : grammar::is_charset<CharSet>::value,
110 : "CharSet requirements not met");
111 :
112 3250 : return pct_encoded_rule_t<CharSet>(cs);
113 : }
114 :
115 : #endif
116 :
117 : } // urls
118 : } // boost
119 :
120 : #include <boost/url/rfc/impl/pct_encoded_rule.hpp>
121 :
122 : #endif
|