Boost.URL Logo

PrevUpHomeNext
validate_pct_encoding (1 of 2 overloads)

Validate a percent encoded string and return the number of decoded bytes.

Synopsis

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

template<
    class CharSet>
result< std::size_t >
validate_pct_encoding(
    string_view s,
    CharSet const& allowed,
    pct_decode_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 decoded using the given options. No encoding is actually performed. Since not all encoded strings are valid, this function also performs checking to ensure that the encoding is valid for the character set, setting the error if the string is invalid.

Example 1

This validates and calculates the decoded length of a valid percent-encoded string.

error_code ec;
std::size_t decoded_size = validate_pct_encoding( "Program%20Files",
        ec, pchars, pct_decode_opts{} );
assert( ! ec.failed() );
assert( decoded_size == 13 );
Example 2

This shows how validation can fail using an error code.

error_code ec;
std::size_t decoded_size = validate_pct_encoding( "bad%escape",
        ec, pchars, pct_decode_opts{});
assert( ec.failed() );
Exception Safety

Throws nothing.

Return Value

The number of bytes needed, excluding any null terminator.

Parameters

Name

Description

s

The percent-encoded string to analyze.

opt

The options for decoding. 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_decode_bytes_unchecked, pct_decode_opts, pct_decode_unchecked,

Convenience header <boost/url.hpp>


PrevUpHomeNext