| Home | Libraries | People | FAQ | More

##### encode (1 of 2 overloads)

Apply percent-encoding to a string.

###### Synopsis

Defined in header `<boost/url/encode.hpp>`

    template<
        class CharSet>
    std::size_t
    encode(
        char* dest,
        std::size_t size,
        core::string_view s,
        CharSet const& unreserved,
        encoding_opts opt = {});

###### 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.

###### Example

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

###### Exception Safety

Throws nothing.

###### 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.

###### Specification

- 2.1. Percent-Encoding (rfc3986)

###### See Also

`encode`, `encoded_size`, `make_pct_string_view`.

Convenience header `<boost/url.hpp>`