Line data Source code
1 : //
2 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 : // Copyright (c) 2022 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_ENCODING_OPTS_HPP
12 : #define BOOST_URL_ENCODING_OPTS_HPP
13 :
14 : #include <boost/url/detail/config.hpp>
15 :
16 : namespace boost {
17 : namespace urls {
18 :
19 : /** Percent-encoding options
20 :
21 : These options are used to customize
22 : the behavior of algorithms which use
23 : percent escapes, such as encoding
24 : or decoding.
25 :
26 : @see
27 : @ref encode,
28 : @ref encoded_size,
29 : @ref pct_string_view.
30 : */
31 : struct encoding_opts
32 : {
33 : /** True if spaces encode to and from plus signs
34 :
35 : This option controls whether or not
36 : the PLUS character ("+") is used to
37 : represent the SP character (" ") when
38 : encoding or decoding.
39 : Although not prescribed by the RFC, plus
40 : signs are commonly treated as spaces upon
41 : decoding when used in the query of URLs
42 : using well known schemes such as HTTP.
43 :
44 : @par Specification
45 : @li <a href="https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1">
46 : application/x-www-form-urlencoded (w3.org)</a>
47 : */
48 : bool space_as_plus = false;
49 :
50 : /** True if hexadecimal digits are emitted as lower case
51 :
52 : By default, percent-encoding algorithms
53 : emit hexadecimal digits A through F as
54 : uppercase letters. When this option is
55 : `true`, lowercase letters are used.
56 : */
57 : bool lower_case = false;
58 :
59 : /** True if nulls are not allowed
60 :
61 : Normally all possible character values
62 : (from 0 to 255) are allowed, with reserved
63 : characters being replaced with escapes
64 : upon encoding. When this option is true,
65 : attempting to decode a null will result
66 : in an error.
67 : */
68 : bool disallow_null = false;
69 :
70 : /** Constructs an `encoding_opts` object with the specified options.
71 :
72 : @param space_as_plus If true, spaces will be encoded as plus signs.
73 : @param lower_case If true, hexadecimal digits will be emitted as lower case.
74 : @param disallow_null If true, null characters will not be allowed.
75 : */
76 : BOOST_CXX14_CONSTEXPR
77 : inline
78 7890 : encoding_opts(
79 : bool const space_as_plus = false,
80 : bool const lower_case = false,
81 : bool const disallow_null = false) noexcept
82 7890 : : space_as_plus(space_as_plus)
83 7890 : , lower_case(lower_case)
84 7890 : , disallow_null(disallow_null) {}
85 : };
86 :
87 : } // urls
88 : } // boost
89 :
90 : #endif
|