Boost.URL Logo

PrevUpHomeNext
validate_pct_encoding (2 of 2 overloads)

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

Synopsis

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

result< std::size_t >
validate_pct_encoding(
    string_view s,
    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. This function does not perform checking to ensure that the unencoded characters belong to specified character set.

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

Specification
See Also

pct_decode, pct_decode_bytes_unchecked, pct_decode_opts, pct_decode_unchecked,

Convenience header <boost/url.hpp>


PrevUpHomeNext