Blame view

3rdparty/boost_1_81_0/boost/url/encode.hpp 4.61 KB
dbf9e800   Hu Chunming   提交_GLIBCXX_USE_CX...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
  //
  // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
  //
  // Distributed under the Boost Software License, Version 1.0. (See accompanying
  // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  //
  // Official repository: https://github.com/boostorg/url
  //
  
  #ifndef BOOST_URL_ENCODE_HPP
  #define BOOST_URL_ENCODE_HPP
  
  #include <boost/url/detail/config.hpp>
  #include <boost/url/encoding_opts.hpp>
  #include <boost/url/string_view.hpp>
  #include <boost/url/grammar/all_chars.hpp>
  #include <boost/url/grammar/string_token.hpp>
  
  namespace boost {
  namespace urls {
  
  /** Return the buffer size needed for percent-encoding
  
      This function returns the exact number
      of bytes necessary to store the result
      of applying percent-encoding to the
      string using the given options and
      character set.
      No encoding is actually performed.
  
      @par Example
      @code
      assert( encoded_size( "My Stuff", pchars ) == 10 );
      @endcode
  
      @par Exception Safety
      Throws nothing.
  
      @return The number of bytes needed,
      excluding any null terminator.
  
      @param s The string to measure.
  
      @param unreserved The set of characters
      that is not percent-encoded.
  
      @param opt The options for encoding. If
      this parameter is omitted, the default
      options are be used.
  
      @par Specification
      @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-2.1"
          >2.1. Percent-Encoding (rfc3986)</a>
  
      @see
          @ref encode,
          @ref encoding_opts,
          @ref make_pct_string_view.
  */
  template<class CharSet>
  std::size_t
  encoded_size(
      string_view s,
      CharSet const& unreserved,
      encoding_opts opt = {}) noexcept;
  
  //------------------------------------------------
  
  /** Apply percent-encoding to a string
  
      This function applies percent-encoding
      to the string using the given options and
      character set. The destination buffer
      provided by the caller is used to store
      the result, which may be truncated if
      there is insufficient space.
  
      @par Example
      @code
      char buf[100];
      assert( encode( buf, sizeof(buf), "Program Files", pchars ) == 15 );
      @endcode
  
      @par Exception Safety
      Throws nothing.
  
      @return The number of characters written
      to the destination buffer.
  
      @param dest The destination buffer
      to write to.
  
      @param size The number of writable
      characters pointed to by `dest`.
      If this is less than `encoded_size(s)`,
      the result is truncated.
  
      @param s The string to encode.
  
      @param unreserved The set of characters
      that is not percent-encoded.
  
      @param opt The options for encoding. If
      this parameter is omitted, the default
      options are used.
  
      @par Specification
      @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-2.1"
          >2.1. Percent-Encoding (rfc3986)</a>
  
      @see
          @ref encode,
          @ref encoded_size,
          @ref make_pct_string_view.
  */
  template<class CharSet>
  std::size_t
  encode(
      char* dest,
      std::size_t size,
      string_view s,
      CharSet const& unreserved,
      encoding_opts opt = {});
  
  #ifndef BOOST_URL_DOCS
  // VFALCO semi-private for now
  template<class CharSet>
  std::size_t
  encode_unsafe(
      char* dest,
      std::size_t size,
      string_view s,
      CharSet const& unreserved,
      encoding_opts opt);
  #endif
  
  //------------------------------------------------
  
  /** Return a percent-encoded string
  
      This function applies percent-encoding
      to the string using the given options and
      character set, and returns the result as
      a string when called with default arguments.
  
      @par Example
      @code
      encoding_opts opt;
      opt.space_as_plus = true;
      std::string s = encode( "My Stuff", opt, pchars );
  
      assert( s == "My+Stuff" );
      @endcode
  
      @par Exception Safety
      Calls to allocate may throw.
  
      @return The string
  
      @param s The string to encode.
  
      @param unreserved The set of characters
      that is not percent-encoded.
  
      @param opt The options for encoding. If
      this parameter is omitted, the default
      options are used.
  
      @param token A string token.
  
      @par Specification
      @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-2.1"
          >2.1. Percent-Encoding (rfc3986)</a>
  
      @see
          @ref encode,
          @ref encoded_size,
          @ref encoding_opts,
  */
  template<
      BOOST_URL_STRTOK_TPARAM,
      class CharSet>
  BOOST_URL_STRTOK_RETURN
  encode(
      string_view s,
      CharSet const& unreserved,
      encoding_opts opt = {},
      BOOST_URL_STRTOK_ARG(token)) noexcept;
  
  } // urls
  } // boost
  
  #include <boost/url/impl/encode.hpp>
  
  #endif