Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit 9fc5439165.
PrevUpHomeNext

encode

Write a string with percent-encoding into a buffer.

Synopsis

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

template<
    class CharSet = grammar::all_chars_t>
std::size_t
encode(
    char* dest,
    char const* end,
    string_view s,
    encode_opts const& opt = {},
    CharSet const& allowed = {});
Description

This function applies percent-encoding to the given plain string, by escaping all characters that are not in the specified CharSet. The output is written to the destination, and will be truncated if there is insufficient space.

Example
char *dest = new char[MAX_LENGTH];
std::size_t encoded_size = encode( dest, dest + MAX_LENGTH,
        "Program Files", encode_opts{}, pchars );

assert( encoded_size == 15 );
assert( strncmp( "Program%20Files", dest, encoded_size ) == 0 );
Exception Safety

Throws nothing.

Return Value

true if the output was large enough to hold the entire result.

Parameters

Name

Description

dest

A pointer to the beginning of the output buffer. Upon return, the argument will be changed to one past the last character written.

end

A pointer to one past the end of the output buffer.

s

The string to encode.

opt

The options for encoding. If this parameter is omitted, the default options will be used.

allowed

The set of characters allowed to appear unescaped. This type must satisfy the requirements of CharSet. If this parameter is omitted, then no characters are considered special. The character set is ignored if opt.non_normal_is_error == false.

Specification
See Also

decode, encode, encoded_size.

Convenience header <boost/url.hpp>


PrevUpHomeNext