Boost.URL Logo

PrevUpHomeNext

pct_encode

Write a string with percent-encoding into a buffer.

Synopsis

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

template<
    class CharSet>
std::size_t
pct_encode(
    char* dest,
    char const* end,
    string_view s,
    CharSet const& allowed,
    pct_encode_opts const& opt = {});
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 = pct_encode( dest, dest + MAX_LENGTH,
        "Program Files", pct_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

pct_decode, pct_encode, pct_encode_bytes.

Convenience header <boost/url.hpp>


PrevUpHomeNext