:relfileprefix: ../../ [#boost-urls-encode] == xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::encode Apply percent-encoding to a string === Synopsis [source,cpp,subs="verbatim,macros,-callouts"] ---- template std::size_t xref:boost/urls/encode-09.adoc[pass:[encode]]( char* dest, std::size_t size, core::string_view s, CharSet const& unreserved, xref:boost/urls/encoding_opts.adoc[encoding_opts] opt = = {}); ---- [source,cpp,subs="verbatim,macros,-callouts"] ---- template< class StringToken = xref:boost/urls/string_token.adoc[string_token]::xref:boost/urls/string_token/return_string.adoc[return_string], class CharSet> StringToken::result_type xref:boost/urls/encode-04.adoc[pass:[encode]]( core::string_view s, CharSet const& unreserved, xref:boost/urls/encoding_opts.adoc[encoding_opts] opt = = {}, StringToken&& token) noexcept; ---- === Description 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. [,cpp] ---- char buf[100]; assert( encode( buf, sizeof(buf), "Program Files", pchars ) == 15 ); ---- === Throws nothing. * link:https://datatracker.ietf.org/doc/html/rfc3986#section-2.1[2.1. Percent-Encoding (rfc3986)] === Return Value The number of characters written to the destination buffer. === Parameters |=== | Name | Description | *dest* | The destination buffer to write to. | *size* | The number of writable characters pointed to by `dest`. If this is less than `encoded_size(s)`, the result is truncated. | *s* | The string to encode. | *unreserved* | The set of characters that is not percent-encoded. | *opt* | The options for encoding. If this parameter is omitted, the default options are used. | *token* | A string token. |=== === See Also xref:boost/urls/encode-04.adoc[encode] , xref:boost/urls/encoded_size.adoc[encoded_size] , xref:boost/urls/make_pct_string_view.adoc[make_pct_string_view] .