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 41715b1c50.
PrevUpHomeNext

encode_to_string

Return a string with percent-encoding applied.

Synopsis

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

template<
    class CharSet = grammar::all_chars_t,
    class Allocator = std::allocator<char>>
std::basic_string< char, std::char_traits< char >, Allocator >
encode_to_string(
    string_view s,
    encode_opts const& opt = {},
    CharSet const& allowed = {},
    Allocator const& a = {});
Description

This function applies percent-encoding to the given plain string, by escaping all characters that are not in the specified CharSet. The result is returned as a std::basic_string, using the optionally specified allocator.

Example
encode_opts opt;
opt.space_to_plus = true;
std::string s = encode( "My Stuff", opt, pchars );

assert( s == "My+Stuff" );
Exception Safety

Calls to allocate may throw.

Return Value

A std::basic_string holding the encoded string, using the specified allocator.

Parameters

Name

Description

s

The string to encode.

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.

opt

The options for encoding. If this parameter is omitted, the default options will be used.

a

An optional allocator the returned string will use. If this parameter is omitted, the default allocator is used. In this case the return type will be std::string.

Specification
See Also

encode, encoded_size, encode_opts,

Convenience header <boost/url.hpp>


PrevUpHomeNext