[#boost-urls-encode-09]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::encode
:relfileprefix: ../../
:mrdocs:

Apply percent&hyphen;encoding to a string

== Synopsis

Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/encode.hpp#L119[boost&sol;url&sol;encode&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;xref:boost/urls/grammar/CharSet.adoc[grammar::CharSet] CS&gt;
std::size&lowbar;t
encode(
    char* dest,
    std::size&lowbar;t size,
    core::string&lowbar;view s,
    CS const& allowed,
    xref:boost/urls/encoding_opts.adoc[encoding&lowbar;opts] opt = &lcub;&rcub;);
----

== Description

This function applies percent&hyphen;encoding to the string using the given options and character set&period; The destination buffer provided by the caller is used to store the result, which may be truncated if there is insufficient space&period;

== Example

[,cpp]
----
char buf[100];
assert( encode( buf, sizeof(buf), "Program Files", pchars ) == 15 );
----
== Exception Safety

Throws nothing&period;

== Specification

* https://datatracker.ietf.org/doc/html/rfc3986#section-2.1[2&period;1&period; Percent&hyphen;Encoding (rfc3986)]

== Return Value

The number of characters written to the destination buffer&period;

== Parameters

[cols="1,4"]
|===
|Name|Description

| *dest*
| The destination buffer to write to&period;
| *size*
| The number of writable characters pointed to by `dest`&period; If this is less than `encoded&lowbar;size(s)`, the result is truncated&period;
| *s*
| The string to encode&period;
| *allowed*
| The set of characters that is not percent&hyphen;encoded&period;
| *opt*
| The options for encoding&period; If this parameter is omitted, the default options are used&period;
|===

== See Also

xref:boost/urls/encode-0d.adoc[`encode`], xref:boost/urls/encoded_size.adoc[`encoded&lowbar;size`], xref:boost/urls/make_pct_string_view.adoc[`make&lowbar;pct&lowbar;string&lowbar;view`]&period;


[.small]#Created with https://www.mrdocs.com[MrDocs]#
