Boost.URL Logo

PrevUpHomeNext

pct_encode_bytes

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

Synopsis

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

template<
    class CharSet>
std::size_t
pct_encode_bytes(
    string_view s,
    CharSet const& allowed,
    pct_encode_opts const& opt = {});
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 '+'.

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

assert( n == 10 );
Example 2

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

pct_encode_opts opt;
opt.space_to_plus = true;
std::size_t n = pct_encode_bytes( "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

pct_decode, pct_encode, pct_encode_opts.

Convenience header <boost/url.hpp>


PrevUpHomeNext