Validate a percent encoded string and return the number of decoded bytes.
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 = {});
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.
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 );
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() );
Throws nothing.
The number of bytes needed, excluding any null terminator.
Name |
Description |
---|---|
|
The percent-encoded string to analyze. |
|
The options for decoding. If this parameter is omitted, the default options will be used. |
|
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 |
pct_decode
,
pct_decode_bytes_unchecked
, pct_decode_opts
,
pct_decode_unchecked
,
Convenience header <boost/url.hpp>