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

encoded_size

Return the number of bytes needed to store a string with percent-encoding applied.

Synopsis

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

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

This function examines the characters in the string to determine the number of bytes necessary if the string were to be percent encoded using the given options and character set. No encoding is actually performed.

Example 1

Find the number of bytes needed to encode a string without transforming ' ' to '+'.

encode_opts opt;
opt.space_to_plus = false;
std::size_t n = encoded_size( "My Stuff", pchars, opt );

assert( n == 10 );
Example 2

Find the number of bytes needed to encode a string when transforming ' ' to '+'.

encode_opts opt;
opt.space_to_plus = true;
std::size_t n = encoded_size( "My Stuff", opt, pchars );

assert( n == 8 );
Exception Safety

Throws nothing.

Return Value

The number of bytes needed, excluding any null terminator.

Parameters

Name

Description

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, encode_opts.

Convenience header <boost/url.hpp>


PrevUpHomeNext