template
struct make_void;
typedef void type;
template
using void_t = make_void::type;
Percent-encoding options
struct encoding_opts;
These options are used to customize the behavior of algorithms which use percent escapes, such as encoding or decoding.
True if spaces encode to and from plus signs
bool space_as_plus = false;
This option controls whether or not the PLUS character ("+") is used to represent the SP character (" ") when encoding or decoding. Although not prescribed by the RFC, plus signs are commonly treated as spaces upon decoding when used in the query of URLs using well known schemes such as HTTP.
True if hexadecimal digits are emitted as lower case
bool lower_case = false;
By default, percent-encoding algorithms emit hexadecimal digits A through F as uppercase letters. When this option is `true`, lowercase letters are used.
True if nulls are not allowed
bool disallow_null = false;
Normally all possible character values (from 0 to 255) are allowed, with reserved characters being replaced with escapes upon encoding. When this option is true, attempting to decode a null will result in an error.
encoding_opts(
bool space_as_plus_ = false,
bool lower_case_ = false,
bool disallow_null_ = false) noexcept;
The type of error category used by the library
using error_category = system::error_category;
This alias is no longer supported and should not be used in new code. Please use `system::error_category` instead.
This alias is included for backwards compatibility with earlier versions of the library.
However, it will be removed in future releases, and using it in new code is not recommended.
Please use the updated version instead to ensure compatibility with future versions of the library.
The type of error code used by the library
using error_code = system::error_code;
This alias is no longer supported and should not be used in new code. Please use `system::error_code` instead.
This alias is included for backwards compatibility with earlier versions of the library.
However, it will be removed in future releases, and using it in new code is not recommended.
Please use the updated version instead to ensure compatibility with future versions of the library.
The type of error condition used by the library
using error_condition = system::error_condition;
This alias is no longer supported and should not be used in new code. Please use `system::error_condition` instead.
This alias is included for backwards compatibility with earlier versions of the library.
However, it will be removed in future releases, and using it in new code is not recommended.
Please use the updated version instead to ensure compatibility with future versions of the library.
The type of system error thrown by the library
using system_error = system::system_error;
This alias is no longer supported and should not be used in new code. Please use `system::system_error` instead.
This alias is included for backwards compatibility with earlier versions of the library.
However, it will be removed in future releases, and using it in new code is not recommended.
Please use the updated version instead to ensure compatibility with future versions of the library.
using system::generic_category
;
| Name |
|---|
using system::system_category
;
| Name |
|---|
namespace errc = system::errc
;
The type of result returned by library functions
template
using result = system::result;
This alias is no longer supported and should not be used in new code. Please use `system::result` instead.
This alias is included for backwards compatibility with earlier versions of the library.
However, it will be removed in future releases, and using it in new code is not recommended.
Please use the updated version instead to ensure compatibility with future versions of the library.
This is an alias template used as the return type for functions that can either return a container, or fail with an error code. This is a brief synopsis of the type:
template< class T >
class result
{
public:
//
// Return true if the result contains an error
//
constexpr bool has_error() const noexcept;
//
// Return the error
//
constexpr system::error_code error() const noexcept;
//
// Return true if the result contains a value
//
constexpr bool has_value() const noexcept;
constexpr explicit operator bool() const noexcept;
//
// Return the value, or throw an exception
//
constexpr T& value();
constexpr T const& value() const;
// Return the value.
// Precondition: has_value()==true
//
constexpr T& operator*() noexcept;
constexpr T* operator->() noexcept;
constexpr T const& operator*() const noexcept;
constexpr T const* operator->() const noexcept;
...more
Given the function parse_uri with this signature:
system::result< url_view > parse_uri( core::string_view s ) noexcept;
The following statement captures the value in a variable upon success, otherwise throws:
url_view u = parse_uri( "http://example.com/path/to/file.txt" ).value();
This statement captures the result in a local variable and inspects the error condition:
system::result< url_view > rv = parse_uri( "http://example.com/path/to/file.txt" );
if(! rv )
std::cout << rv.error();
else
std::cout << *rv;
Base class for string tokens, and algorithm parameters
struct arg;
This abstract interface provides a means for an algorithm to generically obtain a modifiable, contiguous character buffer of prescribed size. As the author of an algorithm simply declare an rvalue reference as a parameter type.
Instances of this type are intended only to be used once and then destroyed.
The declared function accepts any temporary instance of `arg` to be used for writing:
void algorithm( string_token::arg&& dest );
To implement the interface for your type or use-case, derive from the class and implement the prepare function.
Return a modifiable character buffer
virtual
char*
prepare(std::size_t n) = 0;
This function attempts to obtain a character buffer with space for at least `n` characters. Upon success, a pointer to the beginning of the buffer is returned. Ownership is not transferred; the caller should not attempt to free the storage. The buffer shall remain valid until `this` is destroyed.
This function may only be called once. After invoking the function, the only valid operation is destruction.
virtual
~arg() = default;
constexpr
arg() = default;
» more...
constexpr
arg(arg&&) = default;
» more...
arg(arg const&) = delete;
» more...
arg&
operator=(arg&&) = delete;
» more...
arg&
operator=(arg const&) = delete;
» more...
template<
class T,
class = void>
struct is_token
: std::false_type;
template
struct is_token().prepare(
std::declval())), decltype(std::declval().result())>>
: std::integral_constant().result()), typename T::result_type>::value && std::is_same().prepare(0)), char *>::value && std::is_base_of::value && std::is_convertible::value>;
struct return_string
: arg;
using result_type = std::string;
virtual
char*
prepare(std::size_t n) override;
result_type
result() noexcept;
template
struct append_to_t
: arg;
using string_type = std::basic_string, Alloc>;
using result_type = string_type&;
append_to_t(string_type& s) noexcept;
virtual
char*
prepare(std::size_t n) override;
result_type
result() noexcept;
template>
append_to_t
append_to(std::basic_string, Alloc>& s);
template
struct assign_to_t
: arg;
using string_type = std::basic_string, Alloc>;
using result_type = string_type&;
assign_to_t(string_type& s) noexcept;
virtual
char*
prepare(std::size_t n) override;
result_type
result() noexcept;
template>
assign_to_t
assign_to(std::basic_string, Alloc>& s);
template
struct preserve_size_t
: arg;
using result_type = core::string_view;
using string_type = std::basic_string, Alloc>;
preserve_size_t(string_type& s) noexcept;
virtual
char*
prepare(std::size_t n) override;
result_type
result() noexcept;
template>
preserve_size_t
preserve_size(std::basic_string, Alloc>& s);
namespace string_token = string_token
;
Common functionality for string views
class string_view_base;
This base class is used to provide common member functions for reference types that behave like string views. This cannot be instantiated directly; Instead, derive from the type and provide constructors which offer any desired preconditions and invariants.
The character traits
typedef std::char_traits traits_type;
The value type
typedef char value_type;
The pointer type
typedef char* pointer;
The const pointer type
typedef char const* const_pointer;
The reference type
typedef char& reference;
The const reference type
typedef char const& const_reference;
The const iterator type
typedef char const* const_iterator;
The iterator type
typedef const_iterator iterator;
The const reverse iterator type
typedef std::reverse_iterator const_reverse_iterator;
The reverse iterator type
typedef const_reverse_iterator reverse_iterator;
The size type
typedef std::size_t size_type;
The difference type
typedef std::ptrdiff_t difference_type;
A constant used to represent "no position"
constexpr
static
std::size_t const npos = core::string_view::npos;
Conversion
operator core::string_view() const noexcept;
Conversion
operator std::string() const noexcept;
Conversion to std::string is explicit because assigning to string using an implicit constructor does not preserve capacity.
Return an iterator to the beginning
constexpr
const_iterator
begin() const noexcept;
See `core::string_view::begin`
Return an iterator to the end
constexpr
const_iterator
end() const noexcept;
See `core::string_view::end`
Return an iterator to the beginning
constexpr
const_iterator
cbegin() const noexcept;
See `core::string_view::cbegin`
Return an iterator to the end
constexpr
const_iterator
cend() const noexcept;
See `core::string_view::cend`
constexpr
const_reverse_iterator
rbegin() const noexcept;
constexpr
const_reverse_iterator
rend() const noexcept;
constexpr
const_reverse_iterator
crbegin() const noexcept;
constexpr
const_reverse_iterator
crend() const noexcept;
Return the size
constexpr
size_type
size() const noexcept;
See `core::string_view::size`
Return the size
constexpr
size_type
length() const noexcept;
See `core::string_view::length`
Return the maximum allowed size
constexpr
size_type
max_size() const noexcept;
See `core::string_view::max_size`
Return true if the string is empty
constexpr
bool
empty() const noexcept;
See `core::string_view::size`
Access a character
constexpr
const_reference
operator[](size_type pos) const noexcept;
See `core::string_view::operator[]`
Access a character
constexpr
const_reference
at(size_type pos) const;
See `core::string_view::at`
Return the first character
constexpr
const_reference
front() const noexcept;
See `core::string_view::front`
Return the last character
constexpr
const_reference
back() const noexcept;
See `core::string_view::back`
Return a pointer to the character buffer
constexpr
const_pointer
data() const noexcept;
See `core::string_view::data`
Copy the characters to another buffer
constexpr
size_type
copy(
char* s,
size_type n,
size_type pos = 0) const;
See `core::string_view::copy`
Return a view to part of the string
constexpr
core::string_view
substr(
size_type pos = 0,
size_type n = core::string_view::npos) const;
See `core::string_view::substr`
Return the result of comparing to another string
constexpr
int
compare(core::string_view str) const noexcept;
» more...
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
core::string_view str) const;
» more...
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
core::string_view str,
size_type pos2,
size_type n2) const;
» more...
Return the result of comparing to another string
constexpr
int
compare(char const* s) const noexcept;
» more...
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
char const* s) const;
» more...
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
char const* s,
size_type n2) const;
» more...
Return true if a matching prefix exists
constexpr
bool
starts_with(core::string_view x) const noexcept;
» more...
Return true if a matching prefix exists
constexpr
bool
starts_with(char x) const noexcept;
» more...
Return true if a matching prefix exists
constexpr
bool
starts_with(char const* x) const noexcept;
» more...
Return true if a matching suffix exists
constexpr
bool
ends_with(core::string_view x) const noexcept;
» more...
Return true if a matching suffix exists
constexpr
bool
ends_with(char x) const noexcept;
» more...
Return true if a matching suffix exists
constexpr
bool
ends_with(char const* x) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
find(
core::string_view str,
size_type pos = 0) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
find(
char c,
size_type pos = 0) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
find(
char const* s,
size_type pos,
size_type n) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
find(
char const* s,
size_type pos = 0) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
rfind(
core::string_view str,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
rfind(
char c,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
rfind(
char const* s,
size_type pos,
size_type n) const noexcept;
» more...
Return the position of matching characters
constexpr
size_type
rfind(
char const* s,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of the first match
constexpr
size_type
find_first_of(
core::string_view str,
size_type pos = 0) const noexcept;
» more...
Return the position of the first match
constexpr
size_type
find_first_of(
char c,
size_type pos = 0) const noexcept;
» more...
Return the position of the first match
constexpr
size_type
find_first_of(
char const* s,
size_type pos,
size_type n) const noexcept;
» more...
Return the position of the first match
constexpr
size_type
find_first_of(
char const* s,
size_type pos = 0) const noexcept;
» more...
Return the position of the last match
constexpr
size_type
find_last_of(
core::string_view str,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of the last match
constexpr
size_type
find_last_of(
char c,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of the last match
constexpr
size_type
find_last_of(
char const* s,
size_type pos,
size_type n) const noexcept;
» more...
Return the position of the last match
constexpr
size_type
find_last_of(
char const* s,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
core::string_view str,
size_type pos = 0) const noexcept;
» more...
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
char c,
size_type pos = 0) const noexcept;
» more...
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
char const* s,
size_type pos,
size_type n) const noexcept;
» more...
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
char const* s,
size_type pos = 0) const noexcept;
» more...
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
core::string_view str,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
char c,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
char const* s,
size_type pos,
size_type n) const noexcept;
» more...
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
char const* s,
size_type pos = core::string_view::npos) const noexcept;
» more...
Return true if matching characters are found
constexpr
bool
contains(core::string_view sv) const noexcept;
» more...
Return true if matching characters are found
constexpr
bool
contains(char c) const noexcept;
» more...
Return true if matching characters are found
constexpr
bool
contains(char const* s) const noexcept;
» more...
template<
class S0,
class S1>
friend
constexpr
bool
operator==(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator!=(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator<(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator<=(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator>(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator>=(
S0 const& s0,
S1 const& s1) noexcept;
Return the hash of this value
friend
std::size_t
hash_value(string_view_base const& s) noexcept;
friend
std::ostream&
operator<<(
std::ostream& os,
string_view_base const& s);
template<
class S0,
class S1>
constexpr
bool
operator==(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
constexpr
bool
operator!=(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
constexpr
bool
operator<(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
constexpr
bool
operator<=(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
constexpr
bool
operator>(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
constexpr
bool
operator>=(
S0 const& s0,
S1 const& s1) noexcept;
Return the hash of this value
std::size_t
hash_value(string_view_base const& s) noexcept;
Format a string to an output stream
std::ostream&
operator<<(
std::ostream& os,
string_view_base const& s);
template<
class T,
class = void>
struct is_rule
: std::false_type;
template
struct is_rule&>() =
std::declval().parse(
std::declval(),
std::declval()))>>
: std::is_nothrow_copy_constructible;
struct hexdig_chars_t;
Return true if c is in the character set.
constexpr
bool
operator()(char c) const noexcept;
char const*
find_if(
char const* first,
char const* last) const noexcept;
char const*
find_if_not(
char const* first,
char const* last) const noexcept;
constexpr
hexdig_chars_t const hexdig_chars = {};
Return the decimal value of a hex character
signed char
hexdig_value(char ch) noexcept;
This function returns the decimal value of a hexadecimal character, or -1 if the argument is not a valid hexadecimal digit.
HEXDIG = DIGIT
/ "A" / "B" / "C" / "D" / "E" / "F"
/ "a" / "b" / "c" / "d" / "e" / "f"
A set of characters
class lut_chars;
The characters defined by instances of this set are provided upon construction. The `constexpr` implementation allows these to become compile-time constants.
Character sets are used with rules and the functions find_if and find_if_not .
constexpr lut_chars vowel_chars = "AEIOU" "aeiou";
system::result< core::string_view > rv = parse( "Aiea", token_rule( vowel_chars ) );
Constructor
constexpr
lut_chars(char ch) noexcept;
» more...
Constructor
constexpr
lut_chars(char const* s) noexcept;
» more...
template<
class Pred,
class = void>
constexpr
lut_chars(Pred const& pred) noexcept;
» more...
Return true if ch is in the character set.
constexpr
bool
operator()(unsigned char ch) const noexcept;
» more...
Return true if ch is in the character set.
constexpr
bool
operator()(char ch) const noexcept;
» more...
Return the union of two character sets.
friend
constexpr
lut_chars
operator+(
lut_chars const& cs0,
lut_chars const& cs1) noexcept;
This function returns a new character set which contains all of the characters in `cs0` as well as all of the characters in `cs`.
This creates a character set which includes all letters and numbers
constexpr lut_chars alpha_chars(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz");
constexpr lut_chars alnum_chars = alpha_chars + "0123456789";
Constant.
Return a new character set by subtracting
friend
constexpr
lut_chars
operator-(
lut_chars const& cs0,
lut_chars const& cs1) noexcept;
This function returns a new character set which is formed from all of the characters in `cs0` which are not in `cs`.
This statement declares a character set containing all the lowercase letters which are not vowels:
constexpr lut_chars consonants = lut_chars("abcdefghijklmnopqrstuvwxyz") - "aeiou";
Constant.
Return a new character set which is the complement of another character set.
constexpr
lut_chars
operator~() const noexcept;
This function returns a new character set which contains all of the characters that are not in `*this`.
This statement declares a character set containing everything but vowels:
constexpr lut_chars not_vowels = ~lut_chars( "AEIOU" "aeiou" );
Constant.
Throws nothing.
char const*
find_if(
char const* first,
char const* last) const noexcept;
char const*
find_if_not(
char const* first,
char const* last) const noexcept;
Return the union of two character sets.
constexpr
lut_chars
operator+(
lut_chars const& cs0,
lut_chars const& cs1) noexcept;
This function returns a new character set which contains all of the characters in `cs0` as well as all of the characters in `cs`.
This creates a character set which includes all letters and numbers
constexpr lut_chars alpha_chars(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz");
constexpr lut_chars alnum_chars = alpha_chars + "0123456789";
Constant.
Return a new character set by subtracting
constexpr
lut_chars
operator-(
lut_chars const& cs0,
lut_chars const& cs1) noexcept;
This function returns a new character set which is formed from all of the characters in `cs0` which are not in `cs`.
This statement declares a character set containing all the lowercase letters which are not vowels:
constexpr lut_chars consonants = lut_chars("abcdefghijklmnopqrstuvwxyz") - "aeiou";
Constant.
struct all_chars_t;
constexpr
all_chars_t() noexcept = default;
constexpr
bool
operator()(char) const noexcept;
char const*
find_if(
char const* first,
char const* last) const noexcept;
char const*
find_if_not(
char const* first,
char const* last) const noexcept;
A character set containing all characters.
constexpr
all_chars_t const all_chars = {};
template<
class T,
class = void>
struct is_charset
: std::false_type;
template
struct is_charset() =
std::declval().operator()(
std::declval()))>>
: std::true_type;
Find the first character in the string that is in the set.
template
char const*
find_if(
char const const* first,
char const const* last,
CharSet const& cs) noexcept;
Throws nothing.
Find the first character in the string that is not in CharSet
template
char const*
find_if_not(
char const const* first,
char const const* last,
CharSet const& cs) noexcept;
Throws nothing.
template
constexpr
detail::charset_ref
ref(CharSet const& cs) noexcept;
» more...
template
constexpr
detail::rule_ref
ref(Rule const& r) noexcept;
» more...
constexpr
void
ref() = delete;
» more...
Parse a character buffer using a rule
template
system::result
parse(
char const*& it,
char const* end,
Rule const& r);
» more...
Parse a character buffer using a rule
template
system::result
parse(
core::string_view s,
Rule const& r);
» more...
Error codes returned when using rules
enum error : int;
| Name | Description |
|---|---|
| need_more | More input is needed to match the rule |
| mismatch | The rule did not match the input. |
| end_of_range | A rule reached the end of a range |
| leftover | Leftover input remaining after match. |
| invalid | A rule encountered unrecoverable invalid input. |
| out_of_range | An integer overflowed during parsing. |
| syntax | An unspecified syntax error was found. |
More input is needed to match the rule
need_more = 1
A rule reached the end of the input, resulting in a partial match. The error is recoverable; the caller may obtain more input if possible and attempt to parse the character buffer again. Custom rules should only return this error if it is completely unambiguous that the rule cannot be matched without more input.
The rule did not match the input.
mismatch
This error is returned when a rule fails to match the input. The error is recoverable; the caller may rewind the input pointer and attempt to parse again using a different rule.
A rule reached the end of a range
end_of_range
This indicates that the input was consumed when parsing a range . The range_rule avoids rewinding the input buffer when this error is returned. Thus the consumed characters are be considered part of the range without contributing additional elements.
Leftover input remaining after match.
leftover
A rule encountered unrecoverable invalid input.
invalid
This error is returned when input is matching but one of the requirements is violated. For example if a percent escape is found, but one or both characters that follow are not valid hexadecimal digits. This is usually an unrecoverable error.
An integer overflowed during parsing.
out_of_range
An unspecified syntax error was found.
syntax
Error conditions for errors received from rules
enum condition : int;
| Name | Description |
|---|---|
| fatal | A fatal error in syntax was encountered. |
A fatal error in syntax was encountered.
fatal = 1
This indicates that parsing cannot continue.
system::error_code
make_error_code(error ev) noexcept;
system::error_condition
make_error_condition(condition c) noexcept;
Return c converted to lowercase
constexpr
char
to_lower(char c) noexcept;
This function returns the character, converting it to lowercase if it is uppercase. The function is defined only for low-ASCII characters.
assert( to_lower( 'A' ) == 'a' );
Throws nothing.
Return c converted to uppercase
constexpr
char
to_upper(char c) noexcept;
This function returns the character, converting it to uppercase if it is lowercase. The function is defined only for low-ASCII characters.
assert( to_upper( 'a' ) == 'A' );
Throws nothing.
Return the case-insensitive comparison of s0 and s1
int
ci_compare(
core::string_view s0,
core::string_view s1) noexcept;
This returns the lexicographical comparison of two strings, ignoring case. The function is defined only for strings containing low-ASCII characters.
assert( ci_compare( "boost", "Boost" ) == 0 );
Throws nothing.
Return the case-insensitive digest of a string
std::size_t
ci_digest(core::string_view s) noexcept;
The hash function is non-cryptographic and not hardened against algorithmic complexity attacks. Returned digests are suitable for usage in unordered containers. The function is defined only for strings containing low-ASCII characters.
template<
class String0,
class String1>
bool
ci_is_equal(
String0 const& s0,
String1 const& s1);
» more...
bool
ci_is_equal(
core::string_view s0,
core::string_view s1) noexcept;
» more...
Return true if s0 is less than s1 using case-insensitive comparison
bool
ci_is_less(
core::string_view s0,
core::string_view s1) noexcept;
The comparison algorithm implements a case-insensitive total order on the set of all strings; however, it is not a lexicographical comparison. The function is defined only for strings containing low-ASCII characters.
assert( ! ci_is_less( "Boost", "boost" ) );
struct ci_hash;
using is_transparent = void;
std::size_t
operator()(core::string_view s) const noexcept;
struct ci_equal;
using is_transparent = void;
template<
class String0,
class String1>
bool
operator()(
String0 s0,
String1 s1) const noexcept;
struct ci_less;
using is_transparent = void;
std::size_t
operator()(
core::string_view s0,
core::string_view s1) const noexcept;
template<
class R0,
class... Rn>
class variant_rule_t;
using value_type = variant;
system::result
parse(
char const*& it,
char const* end) const;
template<
class R0_,
class... Rn_>
friend
constexpr
variant_rule_t
variant_rule(
R0_ const& r0,
Rn_ const&... rn) noexcept;
template<
class R0_,
class... Rn_>
constexpr
variant_rule_t
variant_rule(
R0_ const& r0,
Rn_ const&... rn) noexcept;
» more...
template<
class R0,
class... Rn>
constexpr
variant_rule_t
variant_rule(
R0 const& r0,
Rn const&... rn) noexcept;
» more...
template
struct unsigned_rule;
using value_type = Unsigned;
system::result
parse(
char const*& it,
char const* end) const noexcept;
struct digit_chars_t;
constexpr
bool
operator()(char c) const noexcept;
char const*
find_if(
char const* first,
char const* last) const noexcept;
char const*
find_if_not(
char const* first,
char const* last) const noexcept;
constexpr
digit_chars_t const digit_chars = {};
struct ch_delim_rule;
using value_type = core::string_view;
constexpr
ch_delim_rule(char ch) noexcept;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
ch_delim_rule
delim_rule(char ch) noexcept;
» more...
template
constexpr
cs_delim_rule
delim_rule(CharSet const& cs) noexcept;
» more...
template
struct cs_delim_rule;
using value_type = core::string_view;
constexpr
cs_delim_rule(CharSet const& cs) noexcept;
system::result
parse(
char const*& it,
char const* end) const noexcept;
template
struct optional_rule_t;
using value_type = optional;
system::result
parse(
char const*& it,
char const* end) const;
template
friend
constexpr
optional_rule_t
optional_rule(R_ const& r);
template
constexpr
optional_rule_t
optional_rule(R_ const& r);
» more...
template
constexpr
optional_rule_t
optional_rule(Rule const& r);
» more...
template<
class R0,
class... Rn>
class tuple_rule_t;
using value_type = mp11::mp_eval_if_c;
template<
class R0_,
class... Rn_>
friend
constexpr
tuple_rule_t
tuple_rule(
R0_ const& r0,
Rn_ const&... rn) noexcept;
system::result
parse(
char const*& it,
char const* end) const;
template<
class R0_,
class... Rn_>
constexpr
tuple_rule_t
tuple_rule(
R0_ const& r0,
Rn_ const&... rn) noexcept;
» more...
template<
class R0,
class... Rn>
constexpr
tuple_rule_t
tuple_rule(
R0 const& r0,
Rn const&... rn) noexcept;
» more...
template
constexpr
detail::squelch_rule_t
squelch(Rule const& r) noexcept;
template
using aligned_storage = detail::aligned_storage_impl alignof(T)) ? alignof(::max_align_t) : alignof(T)>;
A thread-safe collection of instances of T
template
class recycled;
Instances of this type may be used to control where recycled instances of T come from when used with recycled_ptr .
static recycled< std::string > bin;
recycled_ptr< std::string > ps( bin );
// Put the string into a known state
ps->clear();
Destructor
~recycled();
All recycled instances of T are destroyed. Undefined behavior results if there are any recycled_ptr which reference this recycle bin.
Constructor
constexpr
recycled() = default;
A pointer to shared instance of T
template
class recycled_ptr;
This is a smart pointer container which can acquire shared ownership of an instance of `T` upon or after construction. The instance is guaranteed to be in a valid, but unknown state. Every recycled pointer references a valid recycle bin.
static recycled< std::string > bin;
recycled_ptr< std::string > ps( bin );
// Put the string into a known state
ps->clear();
Destructor
~recycled_ptr();
If this is not empty, shared ownership of the pointee is released. If this was the last reference, the object is returned to the original recycle bin.
this->release();
Constructor
recycled_ptr(recycled& bin);
» more...
Constructor
recycled_ptr(
recycled& bin,
std::nullptr_t) noexcept;
» more...
Constructor
recycled_ptr();
» more...
Constructor
recycled_ptr(std::nullptr_t) noexcept;
» more...
Constructor
recycled_ptr(recycled_ptr const& other) noexcept;
» more...
Constructor
recycled_ptr(recycled_ptr&& other) noexcept;
» more...
Assignment
recycled_ptr&
operator=(recycled_ptr&& other) noexcept;
» more...
Assignment
recycled_ptr&
operator=(recycled_ptr const& other) noexcept;
» more...
Return true if this does not reference an object
bool
empty() const noexcept;
Throws nothing.
Return true if this references an object
operator bool() const noexcept;
return ! this->empty();
Throws nothing.
Return the referenced recycle bin
recycled&
bin() const noexcept;
Throws nothing.
Return the referenced object
T*
get() const noexcept;
If this is empty, `nullptr` is returned.
Throws nothing.
Return the referenced object
T*
operator->() const noexcept;
If this is empty, `nullptr` is returned.
Throws nothing.
Return the referenced object
T&
operator*() const noexcept;
not this->empty()
Return the referenced object
T&
acquire();
If this references an object, it is returned. Otherwise, exclusive ownership of a new object of type `T` is acquired and returned.
not this->empty()
Release the referenced object
void
release() noexcept;
If this references an object, it is released to the referenced recycle bin. The pointer continues to reference the same recycle bin.
this->empty()
Throws nothing.
struct alpha_chars_t;
constexpr
alpha_chars_t() noexcept = default;
constexpr
bool
operator()(char c) const noexcept;
char const*
find_if(
char const* first,
char const* last) const noexcept;
char const*
find_if_not(
char const* first,
char const* last) const noexcept;
A character set containing the alphabetical characters.
constexpr
alpha_chars_t const alpha_chars = {};
template
struct token_rule_t;
using value_type = core::string_view;
system::result
parse(
char const*& it,
char const* end) const noexcept;
template
constexpr
token_rule_t
token_rule(CharSet const& cs) noexcept;
A forward range of parsed elements
template
class range;
Objects of this type are forward ranges returned when parsing using the range_rule . Iteration is performed by re-parsing the underlying character buffer. Ownership of the buffer is not transferred; the caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced by the range.
The implementation may use temporary, recycled storage for type-erasure. Objects of type `range` are intended to be used ephemerally. That is, for short durations such as within a function scope. If it is necessary to store the range for a long period of time or with static storage duration, it is necessary to copy the contents to an object of a different type.
The type of each element of the range
using value_type = T;
The type of each element of the range
using reference = T const&;
The type of each element of the range
using const_reference = T const&;
Provided for compatibility, unused
using pointer = void const*;
The type used to represent unsigned integers
using size_type = std::size_t;
The type used to represent signed integers
using difference_type = std::ptrdiff_t;
A constant, forward iterator to elements of the range
class iterator;
iterator() = default;
» more...
iterator(iterator const&) = default;
» more...
bool
operator==(iterator const& other) const noexcept;
bool
operator!=(iterator const& other) const noexcept;
iterator&
operator++() noexcept;
» more...
iterator
operator++(int) noexcept;
» more...
A constant, forward iterator to elements of the range
using const_iterator = iterator;
Destructor
~range();
Constructor
range() noexcept;
» more...
Constructor
range(range&& other) noexcept;
» more...
Constructor
range(range const& other) noexcept;
» more...
Assignment
range&
operator=(range&& other) noexcept;
» more...
Assignment
range&
operator=(range const& other) noexcept;
» more...
Return an iterator to the beginning
iterator
begin() const noexcept;
Return an iterator to the end
iterator
end() const noexcept;
Return true if the range is empty
bool
empty() const noexcept;
Return the number of elements in the range
std::size_t
size() const noexcept;
Return the matching part of the string
core::string_view
string() const noexcept;
template<
class R0,
class R1 = void>
struct range_rule_t;
using value_type = range;
system::result
parse(
char const*& it,
char const* end) const;
template
struct range_rule_t;
using value_type = range;
system::result
parse(
char const*& it,
char const* end) const;
template
constexpr
range_rule_t
range_rule(
Rule const& next,
std::size_t N = 0,
std::size_t M = std::size_t(-1)) noexcept;
» more...
template<
class Rule1,
class Rule2>
constexpr
range_rule_t
range_rule(
Rule1 const& first,
Rule2 const& next,
std::size_t N = 0,
std::size_t M = std::size_t(-1)) noexcept;
» more...
struct alnum_chars_t;
constexpr
bool
operator()(char c) const noexcept;
char const*
find_if(
char const* first,
char const* last) const noexcept;
char const*
find_if_not(
char const* first,
char const* last) const noexcept;
constexpr
alnum_chars_t const alnum_chars = {};
struct vchars_t;
constexpr
bool
operator()(char c) const noexcept;
char const*
find_if(
char const* first,
char const* last) const noexcept;
char const*
find_if_not(
char const* first,
char const* last) const noexcept;
constexpr
vchars_t const vchars = {};
struct dec_octet_rule_t;
using value_type = unsigned char;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
dec_octet_rule_t const dec_octet_rule = {};
class literal_rule;
using value_type = core::string_view;
constexpr
literal_rule(char const* s) noexcept;
system::result
parse(
char const*& it,
char const* end) const noexcept;
template
struct not_empty_rule_t;
using value_type = R::value_type;
system::result
parse(
char const*& it,
char const* end) const;
template
friend
constexpr
not_empty_rule_t
not_empty_rule(R_ const& r);
template
constexpr
not_empty_rule_t
not_empty_rule(R_ const& r);
» more...
template
constexpr
not_empty_rule_t
not_empty_rule(Rule const& r);
» more...
A reference to a valid, percent-encoded string
class decode_view;
These views reference strings in parts of URLs or other components that are percent-encoded. The special characters (those not in the allowed character set) are stored as three character escapes that consist of a percent sign ('%%') followed by a two-digit hexadecimal number of the corresponding unescaped character code, which may be part of a UTF-8 code point depending on the context.
The view refers to the original character buffer and only decodes escaped sequences when needed. In particular these operations perform percent-decoding automatically without the need to allocate memory:
These objects can only be constructed from strings that have a valid percent-encoding, otherwise construction fails. The caller is responsible for ensuring that the lifetime of the character buffer from which the view is constructed extends unmodified until the view is no longer accessed.
The following operators are supported between decode_view and any object that is convertible to `core::string_view`
bool operator==( decode_view, decode_view ) noexcept;
bool operator!=( decode_view, decode_view ) noexcept;
bool operator<=( decode_view, decode_view ) noexcept;
bool operator< ( decode_view, decode_view ) noexcept;
bool operator> ( decode_view, decode_view ) noexcept;
bool operator>=( decode_view, decode_view ) noexcept;
The value type
using value_type = char;
The reference type
using reference = char;
The reference type
using const_reference = char;
The unsigned integer type
using size_type = std::size_t;
The signed integer type
using difference_type = std::ptrdiff_t;
using value_type = char;
using reference = char;
using pointer = void const*;
using const_reference = char;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using iterator_category = std::bidirectional_iterator_tag;
constexpr
iterator() = default;
» more...
constexpr
iterator(iterator const&) = default;
» more...
constexpr
iterator&
operator=(iterator const&) = default;
reference
operator*() const noexcept;
iterator&
operator++() noexcept;
» more...
iterator
operator++(int) noexcept;
» more...
iterator&
operator--() noexcept;
» more...
iterator
operator--(int) noexcept;
» more...
char const*
base();
bool
operator==(iterator const& other) const noexcept;
bool
operator!=(iterator const& other) const noexcept;
iterator
using const_iterator = iterator;
Constructor
constexpr
decode_view() noexcept = default;
» more...
Constructor
decode_view(
pct_string_view s,
encoding_opts opt = = {}) noexcept;
» more...
Return true if the string is empty
bool
empty() const noexcept;
assert( decode_view( "" ).empty() );
Constant.
Throws nothing.
Return the number of decoded characters
size_type
size() const noexcept;
assert( decode_view( "Program%20Files" ).size() == 13 );
return std::distance( this->begin(), this->end() );
Constant.
Throws nothing.
Return an iterator to the beginning
iterator
begin() const noexcept;
auto it = this->begin();
Constant.
Throws nothing.
Return an iterator to the end
iterator
end() const noexcept;
auto it = this->end();
Constant.
Throws nothing.
Return the first character
reference
front() const noexcept;
assert( decode_view( "Program%20Files" ).front() == 'P' );
not this->empty()
Constant.
Throws nothing.
Return the last character
reference
back() const noexcept;
assert( decode_view( "Program%20Files" ).back() == 's' );
not this->empty()
Constant.
Throws nothing.
Checks if the string begins with the given prefix
bool
starts_with(core::string_view s) const noexcept;
» more...
Checks if the string begins with the given prefix
bool
starts_with(char ch) const noexcept;
» more...
Checks if the string ends with the given prefix
bool
ends_with(core::string_view s) const noexcept;
» more...
Checks if the string ends with the given prefix
bool
ends_with(char ch) const noexcept;
» more...
Finds the first occurrence of character in this view
const_iterator
find(char ch) const noexcept;
Linear.
Throws nothing.
Finds the first occurrence of character in this view
const_iterator
rfind(char ch) const noexcept;
Linear.
Throws nothing.
Remove the first characters
void
remove_prefix(size_type n);
decode_view d( "Program%20Files" );
d.remove_prefix( 8 );
assert( d == "Files" );
not this->empty()
Linear.
Remove the last characters
void
remove_suffix(size_type n);
decode_view d( "Program%20Files" );
d.remove_prefix( 6 );
assert( d == "Program" );
not this->empty()
Linear.
Return the decoding options
encoding_opts
options() const noexcept;
Return the result of comparing to another string
int
compare(core::string_view other) const noexcept;
» more...
Return the result of comparing to another string
int
compare(decode_view other) const noexcept;
» more...
template<
class S0,
class S1>
friend
constexpr
bool
operator==(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator!=(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator<(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator<=(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator>(
S0 const& s0,
S1 const& s1) noexcept;
template<
class S0,
class S1>
friend
constexpr
bool
operator>=(
S0 const& s0,
S1 const& s1) noexcept;
friend
std::ostream&
operator<<(
std::ostream& os,
decode_view const& s);
A reference to a valid percent-encoded string
class pct_string_view
: public grammar::string_view_base;
Objects of this type behave like a `core::string_view` and have the same interface, but offer an additional invariant: they can only be constructed from strings containing valid percent-escapes.
Attempting construction from a string containing invalid or malformed percent escapes results in an exception.
The following operators are supported between pct_string_view and any object that is convertible to `core::string_view`
bool operator==( pct_string_view, pct_string_view ) noexcept;
bool operator!=( pct_string_view, pct_string_view ) noexcept;
bool operator<=( pct_string_view, pct_string_view ) noexcept;
bool operator< ( pct_string_view, pct_string_view ) noexcept;
bool operator> ( pct_string_view, pct_string_view ) noexcept;
bool operator>=( pct_string_view, pct_string_view ) noexcept;
Constructor
constexpr
pct_string_view() = default;
» more...
Constructor
constexpr
pct_string_view(pct_string_view const& other) = default;
» more...
template<
class String,
class = void>
pct_string_view(String const& s);
» more...
Constructor (deleted)
pct_string_view(std::nullptr_t) = delete;
» more...
Constructor
pct_string_view(
char const* s,
std::size_t len);
» more...
Constructor
pct_string_view(core::string_view s);
» more...
Assignment
constexpr
pct_string_view&
operator=(pct_string_view const& other) = default;
The copy references the same underlying character buffer. Ownership is not transferred.
this->data() == other.data()
Constant.
Throws nothing.
friend
system::result
make_pct_string_view(core::string_view s) noexcept;
Return the decoded size
std::size_t
decoded_size() const noexcept;
This function returns the number of characters in the resulting string if percent escapes were converted into ordinary characters.
Constant.
Throws nothing.
Return the string as a range of decoded characters
decode_view
operator*() const noexcept;
Constant.
Throws nothing.
Return the string with percent-decoding
template
StringToken::result_type
decode(
encoding_opts opt = = {},
StringToken&& token) const;
This function converts percent escapes in the string into ordinary characters and returns the result. When called with no arguments, the return type is `std::string`. Otherwise, the return type and style of output is determined by which string token is passed.
assert( pct_string_view( "Program%20Files" ).decode() == "Program Files" );
Linear in `this->size()`.
Calls to allocate may throw. String tokens may throw exceptions.
pct_string_view const*
operator->() const noexcept;
Swap
void
swap(pct_string_view& s) noexcept;
pct_string_view
make_pct_string_view_unsafe(
char const* data,
std::size_t size,
std::size_t decoded_size) noexcept;
Return a valid percent-encoded string
system::result
make_pct_string_view(core::string_view s) noexcept;
If `s` is a valid percent-encoded string, the function returns the buffer as a valid view which may be used to perform decoding or measurements. Otherwise the result contains an error code. Upon success, the returned view references the original character buffer; Ownership is not transferred.
Linear in `s.size()`.
Throws nothing.
template<
class S0,
class S1>
constexpr
bool
operator==(
S0 const& s0,
S1 const& s1) noexcept;
» more...
Return true if two addresses are equal
bool
operator==(
ipv4_address const& a1,
ipv4_address const& a2) noexcept;
» more...
Return true if two addresses are equal
bool
operator==(
ipv6_address const& a1,
ipv6_address const& a2) noexcept;
» more...
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator==(
authority_view const& a0,
authority_view const& a1) noexcept;
» more...
bool
operator==(
iterator const& it0,
iterator const& it1) noexcept;
» more...
Return the result of comparing two URLs
bool
operator==(
url_view_base const& u0,
url_view_base const& u1) noexcept;
» more...
template<
class S0,
class S1>
constexpr
bool
operator!=(
S0 const& s0,
S1 const& s1) noexcept;
» more...
Return true if two addresses are not equal
bool
operator!=(
ipv4_address const& a1,
ipv4_address const& a2) noexcept;
» more...
Return true if two addresses are not equal
bool
operator!=(
ipv6_address const& a1,
ipv6_address const& a2) noexcept;
» more...
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator!=(
authority_view const& a0,
authority_view const& a1) noexcept;
» more...
bool
operator!=(
iterator const& it0,
iterator const& it1) noexcept;
» more...
Return the result of comparing two URLs
bool
operator!=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
» more...
template<
class S0,
class S1>
constexpr
bool
operator<(
S0 const& s0,
S1 const& s1) noexcept;
» more...
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator<(
authority_view const& a0,
authority_view const& a1) noexcept;
» more...
Return the result of comparing two URLs
bool
operator<(
url_view_base const& u0,
url_view_base const& u1) noexcept;
» more...
template<
class S0,
class S1>
constexpr
bool
operator<=(
S0 const& s0,
S1 const& s1) noexcept;
» more...
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator<=(
authority_view const& a0,
authority_view const& a1) noexcept;
» more...
Return the result of comparing two URLs
bool
operator<=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
» more...
template<
class S0,
class S1>
constexpr
bool
operator>(
S0 const& s0,
S1 const& s1) noexcept;
» more...
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator>(
authority_view const& a0,
authority_view const& a1) noexcept;
» more...
Return the result of comparing two URLs
bool
operator>(
url_view_base const& u0,
url_view_base const& u1) noexcept;
» more...
template<
class S0,
class S1>
constexpr
bool
operator>=(
S0 const& s0,
S1 const& s1) noexcept;
» more...
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator>=(
authority_view const& a0,
authority_view const& a1) noexcept;
» more...
Return the result of comparing two URLs
bool
operator>=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
» more...
Format the string with percent-decoding applied to the output stream
std::ostream&
operator<<(
std::ostream& os,
decode_view const& s);
» more...
Format the address to an output stream.
std::ostream&
operator<<(
std::ostream& os,
ipv4_address const& addr);
» more...
Format the address to an output stream
std::ostream&
operator<<(
std::ostream& os,
ipv6_address const& addr);
» more...
Format the encoded authority to the output stream
std::ostream&
operator<<(
std::ostream& os,
authority_view const& a);
» more...
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
segments_encoded_base const& ps);
» more...
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
segments_base const& ps);
» more...
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
params_encoded_base const& qp);
» more...
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
params_base const& qp);
» more...
Format the url to the output stream
std::ostream&
operator<<(
std::ostream& os,
url_view_base const& u);
» more...
The sub-delims character set
constexpr
grammar::lut_chars const sub_delim_chars = "!$&()*+,;=\x27";
Character sets are used with rules and the functions grammar::find_if and grammar::find_if_not .
system::result< decode_view > = grammar::parse( "Program%20Files", pct_encoded_rule( sub_delim_chars ) );
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
The unreserved character set
constexpr
grammar::lut_chars const unreserved_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
"-._~";
Character sets are used with rules and the functions grammar::find_if and grammar::find_if_not .
system::result< decode_view > rv = grammar::parse( "Program%20Files", pct_encoded_rule( unreserved_chars ) );
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
The path character set
constexpr
lut_chars const pchars = unreserved_chars + sub_delim_chars + ':' + '@';
Character sets are used with rules and the functions grammar::find_if and grammar::find_if_not .
system::result< decode_view > rv = grammar::parse( "Program%20Files", pchars );
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
Return the buffer size needed for percent-encoding
template
std::size_t
encoded_size(
core::string_view s,
CharSet const& unreserved,
encoding_opts opt = = {}) noexcept;
This function returns the exact number of bytes necessary to store the result of applying percent-encoding to the string using the given options and character set. No encoding is actually performed.
assert( encoded_size( "My Stuff", pchars ) == 10 );
Throws nothing.
Apply percent-encoding to a string
template
std::size_t
encode(
char* dest,
std::size_t size,
core::string_view s,
CharSet const& unreserved,
encoding_opts opt = = {});
» more...
Return a percent-encoded string
template<
class StringToken = string_token::return_string,
class CharSet>
StringToken::result_type
encode(
core::string_view s,
CharSet const& unreserved,
encoding_opts opt = = {},
StringToken&& token) noexcept;
» more...
template
std::size_t
encode_unsafe(
char* dest,
std::size_t size,
core::string_view s,
CharSet const& unreserved,
encoding_opts opt);
The type of no_value
struct no_value_t;
A query parameter
struct param_pct_view;
Objects of this type represent a single key and value pair in a query string where a key is always present and may be empty, while the presence of a value is indicated by has_value equal to true. An empty value is distinct from no value.
The strings may have percent escapes, and offer an additional invariant: they never contain an invalid percent-encoding.
For most usages, key comparisons are case-sensitive and duplicate keys in a query are possible. However, it is the authority that has final control over how the query is interpreted.
Keys and values in this object reference external character buffers. Ownership of the buffers is not transferred; the caller is responsible for ensuring that the assigned buffers remain valid until they are no longer referenced.
query-params = query-param *( "&" query-param )
query-param = key [ "=" value ]
key = *qpchar
value = *( qpchar / "=" )
The key
pct_string_view key;
For most usages, key comparisons are case-sensitive and duplicate keys in a query are possible. However, it is the authority that has final control over how the query is interpreted.
The value
pct_string_view value;
The presence of a value is indicated by has_value equal to true. An empty value is distinct from no value.
True if a value is present
bool has_value = false;
The presence of a value is indicated by `has_value == true`. An empty value is distinct from no value.
Constructor
constexpr
param_pct_view() = default;
» more...
Constructor
param_pct_view(
pct_string_view key,
pct_string_view value) noexcept;
» more...
Constructor
template
param_pct_view(
pct_string_view key,
OptionalString const& value);
» more...
Construction
param_pct_view(param_view const& p);
» more...
param_pct_view(
pct_string_view key,
pct_string_view value,
bool has_value) noexcept;
» more...
Conversion
operator param() const;
This function performs a conversion from a reference-like query parameter to one retaining ownership of the strings by making a copy.
Linear in `this->key.size() + this->value.size()`.
Calls to allocate may throw.
operator param_view() const noexcept;
param_pct_view const*
operator->() const noexcept;
A query parameter
struct param_view;
Objects of this type represent a single key and value pair in a query string where a key is always present and may be empty, while the presence of a value is indicated by has_value equal to true. An empty value is distinct from no value.
Depending on where the object was obtained, the strings may or may not contain percent escapes.
For most usages, key comparisons are case-sensitive and duplicate keys in a query are possible. However, it is the authority that has final control over how the query is interpreted.
Keys and values in this object reference external character buffers. Ownership of the buffers is not transferred; the caller is responsible for ensuring that the assigned buffers remain valid until they are no longer referenced.
query-params = query-param *( "&" query-param )
query-param = key [ "=" value ]
key = *qpchar
value = *( qpchar / "=" )
The key
core::string_view key;
For most usages, key comparisons are case-sensitive and duplicate keys in a query are possible. However, it is the authority that has final control over how the query is interpreted.
The value
core::string_view value;
The presence of a value is indicated by has_value equal to true. An empty value is distinct from no value.
True if a value is present
bool has_value = false;
The presence of a value is indicated by `has_value == true`. An empty value is distinct from no value.
Constructor
constexpr
param_view() = default;
» more...
Constructor
template
param_view(
core::string_view key,
OptionalString const& value) noexcept;
» more...
Constructor
param_view(param const& other) noexcept;
» more...
param_view(
core::string_view key_,
core::string_view value_,
bool has_value_) noexcept;
» more...
Conversion
operator param();
This function performs a conversion from a reference-like query parameter to one retaining ownership of the strings by making a copy. No validation is performed on the strings.
Linear in `this->key.size() + this->value.size()`.
Calls to allocate may throw.
param_view const*
operator->() const noexcept;
Constant indicating no value in a param
constexpr
no_value_t const no_value = {};
A query parameter
struct param;
Objects of this type represent a single key and value pair in a query string where a key is always present and may be empty, while the presence of a value is indicated by has_value equal to true. An empty value is distinct from no value.
Depending on where the object was obtained, the strings may or may not contain percent escapes.
For most usages, key comparisons are case-sensitive and duplicate keys in a query are possible. However, it is the authority that has final control over how the query is interpreted.
query-params = query-param *( "&" query-param )
query-param = key [ "=" value ]
key = *qpchar
value = *( qpchar / "=" )
The key
std::string key;
For most usages, key comparisons are case-sensitive and duplicate keys in a query are possible. However, it is the authority that has final control over how the query is interpreted.
The value
std::string value;
The presence of a value is indicated by has_value equal to true. An empty value is distinct from no value.
True if a value is present
bool has_value = false;
The presence of a value is indicated by `has_value == true`. An empty value is distinct from no value.
Constructor
param() = default;
» more...
Constructor
param(param&& other) noexcept;
» more...
Constructor
param(param const& other) = default;
» more...
Constructor
template
param(
core::string_view key,
OptionalString const& value);
» more...
param(
core::string_view key,
core::string_view value,
bool has_value) noexcept;
» more...
Assignment
param&
operator=(param&& other) noexcept;
» more...
Assignment
param&
operator=(param const&) = default;
» more...
Assignment
param&
operator=(param_view const& other);
» more...
Assignment
param&
operator=(param_pct_view const& other);
» more...
param const*
operator->() const noexcept;
Identifies the type of host in a URL.
enum host_type : int;
| Name | Description |
|---|---|
| none | No host is specified. |
| name | A host is specified by reg-name. |
| ipv4 | A host is specified by ipv4_address . |
| ipv6 | A host is specified by ipv6_address . |
| ipvfuture | A host is specified by IPvFuture. |
Values of this type are returned by URL views and containers to indicate the type of host present in a URL.
No host is specified.
none
A host is specified by reg-name.
name
A host is specified by ipv4_address .
ipv4
A host is specified by ipv6_address .
ipv6
A host is specified by IPvFuture.
ipvfuture
Error codes returned the library
enum error : int;
| Name | Description |
|---|---|
| success | The operation completed successfully. |
| illegal_null | Null encountered in pct-encoded. |
| illegal_reserved_char | Illegal reserved character in encoded string. |
| non_canonical | A grammar element was not in canonical form. |
| bad_pct_hexdig | Bad hexadecimal digit. |
| incomplete_encoding | The percent-encoded sequence is incomplete. |
| missing_pct_hexdig | Missing hexadecimal digit. |
| no_space | No space in output buffer |
| not_a_base | The URL is not a base URL |
The operation completed successfully.
success = 0
Null encountered in pct-encoded.
illegal_null
Illegal reserved character in encoded string.
illegal_reserved_char
A grammar element was not in canonical form.
non_canonical
Bad hexadecimal digit.
bad_pct_hexdig
This error condition is fatal.
The percent-encoded sequence is incomplete.
incomplete_encoding
This error condition is fatal.
Missing hexadecimal digit.
missing_pct_hexdig
This error condition is fatal.
No space in output buffer
no_space
This error is returned when a provided output buffer was too small to hold the complete result of an algorithm.
The URL is not a base URL
not_a_base
constexpr
system::error_code
make_error_code(error ev) noexcept;
An IP version 4 style address.
class ipv4_address;
Objects of this type are used to construct, parse, and manipulate IP version 6 addresses.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
The number of characters in the longest possible IPv4 string.
constexpr
static
std::size_t const max_str_len = 15;
The longest ipv4 address string is "255.255.255.255".
The type used to represent an address as an unsigned integer
using uint_type = std::uint_least32_t;
The type used to represent an address as an array of bytes
using bytes_type = std::array;
Constructor.
constexpr
ipv4_address() = default;
» more...
Constructor.
constexpr
ipv4_address(ipv4_address const&) = default;
» more...
Construct from an unsigned integer.
ipv4_address(uint_type u) noexcept;
» more...
Construct from an array of bytes.
ipv4_address(bytes_type const& bytes) noexcept;
» more...
Construct from a string.
ipv4_address(core::string_view s);
» more...
Copy Assignment.
constexpr
ipv4_address&
operator=(ipv4_address const&) = default;
Return the address as bytes, in network byte order.
bytes_type
to_bytes() const noexcept;
Return the address as an unsigned integer.
uint_type
to_uint() const noexcept;
Return the address as a string in dotted decimal format
template
StringToken::result_type
to_string(StringToken&& token) const;
When called with no arguments, the return type is `std::string`. Otherwise, the return type and style of output is determined by which string token is passed.
assert( ipv4_address(0x01020304).to_string() == "1.2.3.4" );
Constant.
Strong guarantee. Calls to allocate may throw. String tokens may throw exceptions.
Write a dotted decimal string representing the address to a buffer
core::string_view
to_buffer(
char* dest,
std::size_t dest_size) const;
The resulting buffer is not null-terminated.
Return true if the address is a loopback address
bool
is_loopback() const noexcept;
Return true if the address is unspecified
bool
is_unspecified() const noexcept;
Return true if the address is a multicast address
bool
is_multicast() const noexcept;
Return true if two addresses are equal
friend
bool
operator==(
ipv4_address const& a1,
ipv4_address const& a2) noexcept;
Return true if two addresses are not equal
friend
bool
operator!=(
ipv4_address const& a1,
ipv4_address const& a2) noexcept;
Return an address object that represents any address
static
ipv4_address
any() noexcept;
Return an address object that represents the loopback address
static
ipv4_address
loopback() noexcept;
Return an address object that represents the broadcast address
static
ipv4_address
broadcast() noexcept;
friend
std::ostream&
operator<<(
std::ostream& os,
ipv4_address const& addr);
Return an IPv4 address from an IP address string in dotted decimal form
system::result
parse_ipv4_address(core::string_view s) noexcept;
An IP version 6 style address.
class ipv6_address;
Objects of this type are used to construct, parse, and manipulate IP version 6 addresses.
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
The number of characters in the longest possible IPv6 string.
constexpr
static
std::size_t const max_str_len = 49;
The longest IPv6 address is:
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
The type used to represent an address as an array of bytes.
using bytes_type = std::array;
Octets are stored in network byte order.
Constructor.
constexpr
ipv6_address() = default;
» more...
Constructor.
constexpr
ipv6_address(ipv6_address const&) = default;
» more...
Construct from an array of bytes.
ipv6_address(bytes_type const& bytes) noexcept;
» more...
Construct from an IPv4 address.
ipv6_address(ipv4_address const& addr) noexcept;
» more...
Construct from a string.
ipv6_address(core::string_view s);
» more...
Copy Assignment
constexpr
ipv6_address&
operator=(ipv6_address const&) = default;
Return the address as bytes, in network byte order
bytes_type
to_bytes() const noexcept;
Return the address as a string.
template
StringToken::result_type
to_string(StringToken&& token) const;
The returned string does not contain surrounding square brackets.
When called with no arguments, the return type is `std::string`. Otherwise, the return type and style of output is determined by which string token is passed.
ipv6_address::bytes_type b = {{
0, 1, 0, 2, 0, 3, 0, 4,
0, 5, 0, 6, 0, 7, 0, 8 }};
ipv6_address a(b);
assert(a.to_string() == "1:2:3:4:5:6:7:8");
assert( ipv4_address(0x01020304).to_string() == "1.2.3.4" );
Constant.
Strong guarantee. Calls to allocate may throw. String tokens may throw exceptions.
Write a dotted decimal string representing the address to a buffer
core::string_view
to_buffer(
char* dest,
std::size_t dest_size) const;
The resulting buffer is not null-terminated.
Return true if the address is unspecified
bool
is_unspecified() const noexcept;
The address 0:0:0:0:0:0:0:0 is called the unspecified address. It indicates the absence of an address.
Return true if the address is a loopback address
bool
is_loopback() const noexcept;
The unicast address 0:0:0:0:0:0:0:1 is called the loopback address. It may be used by a node to send an IPv6 packet to itself.
Return true if the address is a mapped IPv4 address
bool
is_v4_mapped() const noexcept;
This address type is used to represent the addresses of IPv4 nodes as IPv6 addresses.
Return true if two addresses are equal
friend
bool
operator==(
ipv6_address const& a1,
ipv6_address const& a2) noexcept;
Return true if two addresses are not equal
friend
bool
operator!=(
ipv6_address const& a1,
ipv6_address const& a2) noexcept;
Return an address object that represents the loopback address
static
ipv6_address
loopback() noexcept;
The unicast address 0:0:0:0:0:0:0:1 is called the loopback address. It may be used by a node to send an IPv6 packet to itself.
friend
std::ostream&
operator<<(
std::ostream& os,
ipv6_address const& addr);
Parse a string containing an IPv6 address.
system::result
parse_ipv6_address(core::string_view s) noexcept;
This function attempts to parse the string as an IPv6 address and returns a result containing the address upon success, or an error code if the string does not contain a valid IPv6 address.
Throws nothing.
Identifies a known URL scheme
enum scheme : unsigned short;
| Name | Description |
|---|---|
| none | Indicates that no scheme is present |
| unknown | Indicates the scheme is not a well-known scheme |
| ftp | File Transfer Protocol (FTP) |
| file | File URI Scheme |
| http | The Hypertext Transfer Protocol URI Scheme |
| https | The Secure Hypertext Transfer Protocol URI Scheme |
| ws | The WebSocket URI Scheme |
| wss | The Secure WebSocket URI Scheme |
Indicates that no scheme is present
none = 0
Indicates the scheme is not a well-known scheme
unknown
File Transfer Protocol (FTP)
ftp
FTP is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network.
File URI Scheme
file
The File URI Scheme is typically used to retrieve files from within one's own computer.
The Hypertext Transfer Protocol URI Scheme
http
URLs of this type indicate a resource which is interacted with using the HTTP protocol.
The Secure Hypertext Transfer Protocol URI Scheme
https
URLs of this type indicate a resource which is interacted with using the Secure HTTP protocol.
The WebSocket URI Scheme
ws
URLs of this type indicate a resource which is interacted with using the WebSocket protocol.
The Secure WebSocket URI Scheme
wss
URLs of this type indicate a resource which is interacted with using the Secure WebSocket protocol.
Return the known scheme for a non-normalized string, if known
scheme
string_to_scheme(core::string_view s) noexcept;
If the string does not identify a known scheme, the value scheme::unknown is returned.
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Return the normalized string for a known scheme
core::string_view
to_string(scheme s) noexcept;
Return the default port for a known scheme
std::uint16_t
default_port(scheme s) noexcept;
This function returns the default port for the known schemes. If the value does not represent a known scheme or the scheme does not represent a protocol, the function returns zero.
The following ports are returned by the function:
A non-owning reference to a valid URL
class url_view
: public url_view_base;
Objects of this type represent valid URL strings constructed from a parsed, external character buffer whose storage is managed by the caller. That is, it acts like a `core::string_view` in terms of ownership. The caller is responsible for ensuring that the lifetime of the underlying character buffer extends until it is no longer referenced.
Construction from a string parses the input as a URI-reference and throws an exception on error. Upon success, the constructed object points to the passed character buffer; ownership is not transferred.
url_view u( "https://www.example.com/index.htm?text=none#a1" );
Parsing functions like parse_uri_reference return a result containing either a valid url_view upon succcess, otherwise they contain an error. The error can be converted to an exception by the caller if desired:
system::result< url_view > rv = parse_uri_reference( "https://www.example.com/index.htm?text=none#a1" );
URI-reference = URI / relative-ref
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Destructor
~url_view() = default;
Any params, segments, iterators, or other views which reference the same underlying character buffer remain valid.
Constructor
url_view() noexcept;
» more...
Constructor
url_view(core::string_view s);
» more...
template<
class String,
class = void>
url_view(String const& s);
» more...
Constructor
url_view(url_view const& other) noexcept;
» more...
Constructor
url_view(url_view_base const& other) noexcept;
» more...
Assignment
url_view&
operator=(url_view const& other) noexcept;
» more...
Assignment
url_view&
operator=(url_view_base const& other) noexcept;
» more...
Return the maximum number of characters possible
constexpr
static
std::size_t
max_size() noexcept;
This represents the largest number of characters that are possible in a url, not including any null terminator.
Constant.
Throws nothing.
A non-owning reference to a valid authority
class authority_view;
Objects of this type represent valid authority strings constructed from a parsed, external character buffer whose storage is managed by the caller. That is, it acts like a `core::string_view` in terms of ownership. The caller is responsible for ensuring that the lifetime of the underlying character buffer extends until it is no longer referenced.
Construction from a string parses the input as an authority and throws an exception on error. Upon success, the constructed object points to the passed character buffer; ownership is not transferred.
authority_view a( "user:pass@www.example.com:8080" );
The parsing function parse_authority returns a result containing either a valid authority_view upon succcess, otherwise it contain an error. The error can be converted to an exception by the caller if desired:
system::result< authority_view > rv = parse_authority( "user:pass@www.example.com:8080" );
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Destructor
virtual
~authority_view();
Constructor
authority_view() noexcept;
» more...
Construct from a string.
authority_view(core::string_view s);
» more...
Constructor
authority_view(authority_view const&) noexcept;
» more...
Assignment
authority_view&
operator=(authority_view const&) noexcept;
Return the number of characters in the authority
std::size_t
size() const noexcept;
This function returns the number of characters in the authority.
assert( authority_view( "user:pass@www.example.com:8080" ).size() == 30 );
Throws nothing.
Return true if the authority is empty
bool
empty() const noexcept;
An empty authority has an empty host, no userinfo, and no port.
assert( authority_view( "" ).empty() );
Throws nothing.
Return a pointer to the first character
char const*
data() const noexcept;
This function returns a pointer to the beginning of the view, which is not guaranteed to be null-terminated.
Throws nothing.
Return the complete authority
core::string_view
buffer() const noexcept;
This function returns the authority as a percent-encoded string.
assert( parse_authority( "www.example.com" ).value().buffer() == "www.example.com" );
authority = [ userinfo "@" ] host [ ":" port ]
Throws nothing.
Return true if a userinfo is present
bool
has_userinfo() const noexcept;
This function returns true if this contains a userinfo.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
authority = [ userinfo "@" ] host [ ":" port ]
Return the userinfo
template
StringToken::result_type
userinfo(StringToken&& token) const;
If present, this function returns a string representing the userinfo (which may be empty). Otherwise it returns an empty string. Any percent-escapes in the string are decoded first.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" );
Linear in `this->userinfo().size()`.
Calls to allocate may throw.
userinfo = user [ ":" [ password ] ]
authority = [ userinfo "@" ] host [ ":" port ]
Return the userinfo
pct_string_view
encoded_userinfo() const noexcept;
If present, this function returns a string representing the userinfo (which may be empty). Otherwise it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" );
Constant.
Throws nothing
userinfo = user [ ":" [ password ] ]
authority = [ userinfo "@" ] host [ ":" port ]
Return the user
template
StringToken::result_type
user(StringToken&& token) const;
If present, this function returns a string representing the user (which may be empty). Otherwise it returns an empty string. Any percent-escapes in the string are decoded first.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" );
Linear in `this->user().size()`.
Calls to allocate may throw.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the user
pct_string_view
encoded_user() const noexcept;
If present, this function returns a string representing the user (which may be empty). Otherwise it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return true if a password is present
bool
has_password() const noexcept;
This function returns true if the userinfo is present and contains a password.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the password
template
StringToken::result_type
password(StringToken&& token) const;
If present, this function returns a string representing the password (which may be an empty string). Otherwise it returns an empty string. Any percent-escapes in the string are decoded first.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" );
Linear in `this->password().size()`.
Calls to allocate may throw.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the password
pct_string_view
encoded_password() const noexcept;
This function returns the password portion of the userinfo as a percent-encoded string.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the host type
host_type
host_type() const noexcept;
This function returns one of the following constants representing the type of host present.
assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 );
Constant.
Throws nothing.
Return the host
template
StringToken::result_type
host(StringToken&& token) const;
This function returns the host portion of the authority as a string, or the empty string if there is no authority. Any percent-escapes in the string are decoded first.
assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" );
Linear in `this->host().size()`.
Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host
pct_string_view
encoded_host() const noexcept;
This function returns the host portion of the authority as a string, or the empty string if there is no authority. The returned string may contain percent escapes.
assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" );
Constant.
Throws nothing.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host
template
StringToken::result_type
host_address(StringToken&& token) const;
The value returned by this function depends on the type of host returned from the function host_type .
assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" );
Linear in `this->host_address().size()`.
Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host
pct_string_view
encoded_host_address() const noexcept;
The value returned by this function depends on the type of host returned from the function host_type .
assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" );
Constant.
Throws nothing.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host IPv4 address
ipv4_address
host_ipv4_address() const noexcept;
If the host type is host_type::ipv4 , this function returns the address as a value of type ipv4_address . Otherwise, if the host type is not an IPv4 address, it returns a default-constructed value which is equal to the unspecified address "0.0.0.0".
assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) );
Constant.
Throws nothing.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
Return the host IPv6 address
ipv6_address
host_ipv6_address() const noexcept;
If the host type is host_type::ipv6 , this function returns the address as a value of type ipv6_address . Otherwise, if the host type is not an IPv6 address, it returns a default-constructed value which is equal to the unspecified address "0:0:0:0:0:0:0:0".
assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) );
Constant.
Throws nothing.
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
Return the host IPvFuture address
core::string_view
host_ipvfuture() const noexcept;
If the host type is host_type::ipvfuture , this function returns the address as a string. Otherwise, if the host type is not an IPvFuture address, it returns an empty string.
assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" );
Constant.
Throws nothing.
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
Return the host name
template
StringToken::result_type
host_name(StringToken&& token) const;
If the host type is host_type::name , this function returns the name as a string. Otherwise, if the host type is not an name, it returns an empty string. Any percent-escapes in the string are decoded first.
assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" );
Linear in `this->host_name().size()`.
Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host name
pct_string_view
encoded_host_name() const noexcept;
If the host type is host_type::name , this function returns the name as a string. Otherwise, if the host type is not an name, it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" );
Constant.
Throws nothing.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return true if a port is present
bool
has_port() const noexcept;
This function returns true if an authority is present and contains a port.
assert( url_view( "wss://www.example.com:443" ).has_port() );
Constant.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Return the port
core::string_view
port() const noexcept;
If present, this function returns a string representing the port (which may be empty). Otherwise it returns an empty string.
assert( url_view( "http://localhost.com:8080" ).port() == "8080" );
Constant.
Throws nothing.
port = *DIGIT
Return the port
std::uint16_t
port_number() const noexcept;
If a port is present and the numerical value is representable, it is returned as an unsigned integer. Otherwise, the number zero is returned.
assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 );
Constant.
Throws nothing.
port = *DIGIT
Return the host and port
pct_string_view
encoded_host_and_port() const noexcept;
If an authority is present, this function returns the host and optional port as a string, which may be empty. Otherwise it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" );
Constant.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
Return the result of comparing this with another authority
int
compare(authority_view const& other) const noexcept;
This function compares two authorities according to Syntax-Based comparison algorithm.
Throws nothing.
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
friend
bool
operator==(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
friend
bool
operator!=(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
friend
bool
operator<(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
friend
bool
operator<=(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
friend
bool
operator>(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
friend
bool
operator>=(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
friend
std::ostream&
operator<<(
std::ostream& os,
authority_view const& a);
Parse an authority
system::result
parse_authority(core::string_view s) noexcept;
This function parses a string according to the authority grammar below, and returns an authority_view referencing the string. Ownership of the string is not transferred; the caller is responsible for ensuring that the lifetime of the string extends until the view is no longer being accessed.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Throws nothing.
struct ignore_case_t;
constexpr
ignore_case_t const ignore_case = {};
An optional parameter to determine case-sensitivity
class ignore_case_param;
Functions may use parameters of this type to allow the user to optionally indicate that comparisons should be case-insensitive when the value ignore_case is passed.
Constructor
constexpr
ignore_case_param() noexcept = default;
» more...
Constructor
constexpr
ignore_case_param(ignore_case_t) noexcept;
» more...
True if an algorithm should ignore case
operator bool() const noexcept;
Values of type `ignore_case_param` evaluate to true when constructed with the constant ignore_case . Otherwise, they are default-constructed and evaluate to `false`.
Common functionality for containers
class segments_encoded_base;
This base class is used by the library to provide common member functions for containers. This cannot be instantiated directly; Instead, use one of the containers or functions:
using value_type = value_type;
using reference = reference;
using pointer = reference;
using difference_type = std::ptrdiff_t;
using iterator_category = std::bidirectional_iterator_tag;
constexpr
iterator() = default;
» more...
constexpr
iterator(iterator const&) = default;
» more...
constexpr
iterator&
operator=(iterator const&) = default;
reference
operator*() const noexcept;
pointer
operator->() const noexcept;
iterator&
operator++() noexcept;
» more...
iterator
operator++(int) noexcept;
» more...
iterator&
operator--() noexcept;
» more...
iterator
operator--(int) noexcept;
» more...
bool
operator==(iterator const& other) const noexcept;
bool
operator!=(iterator const& other) const noexcept;
iterator
using const_iterator = iterator;
The value type
using value_type = std::string;
Values of this type represent a segment where unique ownership is retained by making a copy.
segments_encoded_base::value_type ps( url_view( "/path/to/file.txt" ).encoded_segments().back() );
The reference type
using reference = pct_string_view;
This is the type of value returned when iterators of the view are dereferenced.
The reference type
using const_reference = pct_string_view;
This is the type of value returned when iterators of the view are dereferenced.
An unsigned integer type used to represent size.
using size_type = std::size_t;
A signed integer type used to represent differences.
using difference_type = std::ptrdiff_t;
Return the maximum number of characters possible
constexpr
static
std::size_t
max_size() noexcept;
This represents the largest number of characters that are possible in a path, not including any null terminator.
Throws nothing.
Return the referenced character buffer.
pct_string_view
buffer() const noexcept;
This function returns the character buffer referenced by the view. The returned string may contain percent escapes.
assert( url_view( "/path/to/file.txt" ).encoded_segments().buffer() == "/path/to/file.txt" );
Constant.
Throws nothing.
Returns true if this references an absolute path.
bool
is_absolute() const noexcept;
Absolute paths always start with a forward slash ('/').
assert( url_view( "/path/to/file.txt" ).encoded_segments().is_absolute() == true );
Constant.
Throws nothing.
Return true if there are no segments
bool
empty() const noexcept;
assert( ! url_view( "/index.htm" ).encoded_segments().empty() );
Constant.
Throws nothing.
Return the number of segments
std::size_t
size() const noexcept;
assert( url_view( "/path/to/file.txt" ).encoded_segments().size() == 3 );
Constant.
Throws nothing.
Return the first segment
pct_string_view
front() const noexcept;
This function returns a string with the first segment of the path without any leading or trailing '/' separators. The returned string may contain percent escapes.
this->empty() == false
return *begin();
assert( url_view( "/path/to/file.txt" ).encoded_segments().front() == "path" );
Constant.
Throws nothing.
Return the last segment
pct_string_view
back() const noexcept;
This function returns a string with the last segment of the path without any leading or trailing '/' separators. The returned string may contain percent escapes.
this->empty() == false
assert( url_view( "/path/to/file.txt" ).encoded_segments().back() == "file.txt" );
this->empty() == false
return *--end();
Constant.
Throws nothing.
Return an iterator to the beginning
iterator
begin() const noexcept;
Linear in `this->front().size()` or constant if `this->empty()`.
Throws nothing.
Return an iterator to the end
iterator
end() const noexcept;
Constant.
Throws nothing.
Common functionality for containers
class segments_base;
This base class is used by the library to provide common member functions for containers. This cannot be instantiated directly; Instead, use one of the containers or functions:
using value_type = value_type;
using reference = reference;
using pointer = reference;
using difference_type = difference_type;
using iterator_category = std::bidirectional_iterator_tag;
constexpr
iterator() = default;
» more...
constexpr
iterator(iterator const&) = default;
» more...
constexpr
iterator&
operator=(iterator const&) noexcept = default;
reference
operator*() const;
pointer
operator->() const = delete;
iterator&
operator++() noexcept;
» more...
iterator
operator++(int) noexcept;
» more...
iterator&
operator--() noexcept;
» more...
iterator
operator--(int) noexcept;
» more...
bool
operator==(iterator const& other) const noexcept;
bool
operator!=(iterator const& other) const noexcept;
iterator
using const_iterator = iterator;
The value type
using value_type = std::string;
Values of this type represent a segment where unique ownership is retained by making a copy.
segments_base::value_type ps( url_view( "/path/to/file.txt" ).segments().back() );
The reference type
using reference = std::string;
This is the type of value returned when iterators of the view are dereferenced.
The reference type
using const_reference = std::string;
This is the type of value returned when iterators of the view are dereferenced.
An unsigned integer type used to represent size.
using size_type = std::size_t;
A signed integer type used to represent differences.
using difference_type = std::ptrdiff_t;
Return the maximum number of characters possible
constexpr
static
std::size_t
max_size() noexcept;
This represents the largest number of characters that are possible in a path, not including any null terminator.
Throws nothing.
Return the referenced character buffer.
pct_string_view
buffer() const noexcept;
This function returns the character buffer referenced by the view. The returned string may contain percent escapes.
assert( url_view( "/path/to/file.txt" ).segments().buffer() == "/path/to/file.txt" );
Constant.
Throws nothing.
Returns true if this references an absolute path.
bool
is_absolute() const noexcept;
Absolute paths always start with a forward slash ('/').
assert( url_view( "/path/to/file.txt" ).segments().is_absolute() == true );
Constant.
Throws nothing.
Return true if there are no segments
bool
empty() const noexcept;
assert( ! url_view( "/index.htm" ).segments().empty() );
Constant.
Throws nothing.
Return the number of segments
std::size_t
size() const noexcept;
assert( url_view( "/path/to/file.txt" ).segments().size() == 3 );
Constant.
Throws nothing.
Return the first segment
std::string
front() const noexcept;
This function returns a string with the first segment of the path without any leading or trailing '/' separators. Any percent-escapes in the string are decoded first.
this->empty() == false
return *begin();
assert( url_view( "/path/to/file.txt" ).segments().front() == "path" );
Linear in `this->front().size()`.
Calls to allocate may throw.
Return the last segment
std::string
back() const noexcept;
this->empty() == false
assert( url_view( "/path/to/file.txt" ).segments().back() == "file.txt" );
this->empty() == false
return *--end();
Linear in `this->back().size()`.
Calls to allocate may throw.
Return an iterator to the beginning
iterator
begin() const noexcept;
Linear in `this->front().size()` or constant if `this->empty()`.
Throws nothing.
Return an iterator to the end
iterator
end() const noexcept;
Constant.
Throws nothing.
A view representing path segments in a URL
class segments_view
: public segments_base;
Objects of this type are used to interpret the path as a bidirectional view of segment strings.
The view does not retain ownership of the elements and instead references the original character buffer. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
url_view u( "/path/to/file.txt" );
segments_view ps = u.segments();
assert( ps.buffer().data() == u.buffer().data() );
Percent escapes in strings returned when dereferencing iterators are automatically decoded.
Changes to the underlying character buffer can invalidate iterators which reference it.
Constructor
constexpr
segments_view() = default;
» more...
Constructor
constexpr
segments_view(segments_view const& other) = default;
» more...
Constructor
segments_view(core::string_view s);
» more...
Assignment
constexpr
segments_view&
operator=(segments_view const& other) = default;
After assignment, both views reference the same underlying character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant
Throws nothing
A view representing path segments in a URL
class segments_encoded_view
: public segments_encoded_base;
Objects of this type are used to interpret the path as a bidirectional view of segment strings.
The view does not retain ownership of the elements and instead references the original character buffer. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
url_view u( "/path/to/file.txt" );
segments_encoded_view ps = u.encoded_segments();
assert( ps.buffer().data() == u.buffer().data() );
Strings produced when elements are returned have type param_pct_view and represent encoded strings. Strings passed to member functions may contain percent escapes, and throw exceptions on invalid inputs.
Changes to the underlying character buffer can invalidate iterators which reference it.
Constructor
constexpr
segments_encoded_view() = default;
» more...
Constructor
constexpr
segments_encoded_view(segments_encoded_view const&) noexcept = default;
» more...
Constructor
segments_encoded_view(core::string_view s);
» more...
Assignment
constexpr
segments_encoded_view&
operator=(segments_encoded_view const&) = default;
After assignment, both views reference the same underlying character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant
Throws nothing
Conversion
operator segments_view() const noexcept;
This conversion returns a new view which references the same underlying character buffer, and whose iterators and members return ordinary strings with decoding applied to any percent escapes.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
segments_view ps = parse_path( "/path/to/file.txt" ).value();
segments_view( *this ).buffer().data() == this->buffer().data()
Constant
Throws nothing
friend
system::result
parse_path(core::string_view s) noexcept;
Parse a string and return an encoded segment view
system::result
parse_path(core::string_view s) noexcept;
This function parses the string and returns the corresponding path object if the string is valid, otherwise returns an error.
path = [ "/" ] segment *( "/" segment )
No-throw guarantee.
struct authority_rule_t;
using value_type = authority_view;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
authority_rule_t const authority_rule = {};
template
struct pct_encoded_rule_t;
using value_type = pct_string_view;
template
friend
constexpr
pct_encoded_rule_t
pct_encoded_rule(CharSet_ const& cs) noexcept;
system::result
parse(
char const*& it,
char const* end) const noexcept;
template
constexpr
pct_encoded_rule_t
pct_encoded_rule(CharSet_ const& cs) noexcept;
» more...
template
constexpr
pct_encoded_rule_t
pct_encoded_rule(CharSet const& cs) noexcept;
» more...
The type of variant used by the library
template
using variant = variant2::variant;
This alias is no longer supported and should not be used in new code. Please use `boost::variant2::variant` instead.
This alias is included for backwards compatibility with earlier versions of the library.
However, it will be removed in future releases, and using it in new code is not recommended.
Please use the updated version instead to ensure compatibility with future versions of the library.
template
using optional = optional;
Common functionality for containers
class params_encoded_base;
This base class is used by the library to provide common member functions for containers. This cannot be instantiated directly; Instead, use one of the containers or functions:
using value_type = value_type;
using reference = reference;
using pointer = reference;
using difference_type = std::ptrdiff_t;
using iterator_category = std::bidirectional_iterator_tag;
iterator() = default;
» more...
constexpr
iterator(iterator const&) = default;
» more...
iterator&
operator=(iterator const&) = default;
iterator&
operator++() noexcept;
» more...
iterator
operator++(int) noexcept;
» more...
iterator&
operator--() noexcept;
» more...
iterator
operator--(int) noexcept;
» more...
reference
operator*() const;
pointer
operator->() const;
friend
bool
operator==(
iterator const& it0,
iterator const& it1) noexcept;
friend
bool
operator!=(
iterator const& it0,
iterator const& it1) noexcept;
iterator
using const_iterator = iterator;
The value type
using value_type = param;
Values of this type represent parameters whose strings retain unique ownership by making a copy.
params_encoded_view::value_type qp( *url_view( "?first=John&last=Doe" ).params().find( "first" ) );
The reference type
using reference = param_pct_view;
This is the type of value returned when iterators of the view are dereferenced.
The reference type
using const_reference = param_pct_view;
This is the type of value returned when iterators of the view are dereferenced.
An unsigned integer type to represent sizes.
using size_type = std::size_t;
A signed integer type used to represent differences.
using difference_type = std::ptrdiff_t;
Return the maximum number of characters possible
constexpr
static
std::size_t
max_size() noexcept;
This represents the largest number of characters that are possible in a path, not including any null terminator.
Throws nothing.
Return the query corresponding to these params
pct_string_view
buffer() const noexcept;
This function returns the query string referenced by the container. The returned string may contain percent escapes.
assert( url_view( "?first=John&last=Doe" ).encoded_params().buffer() == "first=John&last=Doe" );
Constant.
Throws nothing.
query-params = query-param *( "&" query-param )
query-param = key [ "=" value ]
key = *qpchar
value = *( qpchar / "=" )
Return true if there are no params
bool
empty() const noexcept;
assert( ! url_view( "?key=value" ).encoded_params().empty() );
Constant.
Throws nothing.
Return the number of params
std::size_t
size() const noexcept;
assert( url_view( "?key=value").encoded_params().size() == 1 );
Constant.
Throws nothing.
Return an iterator to the beginning
iterator
begin() const noexcept;
Linear in the size of the first param.
Throws nothing.
Return an iterator to the end
iterator
end() const noexcept;
Constant.
Throws nothing.
Return true if a matching key exists
bool
contains(
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key, which may contain percent escapes. The comparison is performed as if all escaped characters were decoded first.
assert( url_view( "?first=John&last=Doe" ).encoded_params().contains( "first" ) );
Linear in `this->buffer().size()`.
Exceptions thrown on invalid input.
Return the number of matching keys
std::size_t
count(
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find the number of matches for the specified key, which may contain percent escapes. The comparison is performed as if all escaped characters were decoded first.
assert( url_view( "?first=John&last=Doe" ).encoded_params().count( "first" ) == 1 );
Linear in `this->buffer().size()`.
Exceptions thrown on invalid input.
Find a matching key
iterator
find(
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
Find a matching key
iterator
find(
iterator from,
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
Find a matching key
iterator
find_last(
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
Find a matching key
iterator
find_last(
iterator before,
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
A view representing query parameters in a URL
class params_ref
: public params_base;
Objects of this type are used to interpret the query parameters as a bidirectional view of key/value pairs. The view does not retain ownership of the elements and instead references the original url. The caller is responsible for ensuring that the lifetime of the referenced url extends until it is no longer referenced. The view is modifiable; calling non-const members causes changes to the referenced url.
Percent escapes in strings returned when dereferencing iterators are automatically decoded. Reserved characters in strings supplied to modifier functions are automatically percent-escaped.
url u( "?first=John&last=Doe" );
params_ref p = u.params();
Changes to the underlying character buffer can invalidate iterators which reference it. Modifications made through the container invalidate some or all iterators:
Constructor
constexpr
params_ref(params_ref const& other) = default;
» more...
Constructor
params_ref(
params_ref const& other,
encoding_opts opt) noexcept;
» more...
Assignment
params_ref&
operator=(params_ref const& other);
» more...
Assignment
params_ref&
operator=(std::initializer_list init);
» more...
Conversion
operator params_view() const noexcept;
Return the referenced url
url_base&
url() const noexcept;
This function returns the url referenced by the view.
url u( "?key=value" );
assert( &u.segments().url() == &u );
Throws nothing.
Clear the contents of the container
void
clear() noexcept;
All iterators are invalidated.
this->url().remove_query();
this->empty() == true && this->url().has_query() == false
Constant.
Throws nothing.
Assign elements
void
assign(std::initializer_list init);
» more...
Assign elements
template
void
assign(
FwdIt first,
FwdIt last);
» more...
Append elements
iterator
append(param_view const& p);
» more...
Append elements
iterator
append(std::initializer_list init);
» more...
Append elements
template
iterator
append(
FwdIt first,
FwdIt last);
» more...
Insert elements
iterator
insert(
iterator before,
param_view const& p);
» more...
Insert elements
iterator
insert(
iterator before,
std::initializer_list init);
» more...
Insert elements
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
» more...
Erase elements
iterator
erase(iterator pos) noexcept;
» more...
Erase elements
iterator
erase(
iterator first,
iterator last) noexcept;
» more...
Erase elements
std::size_t
erase(
core::string_view key,
ignore_case_param ic = = {}) noexcept;
» more...
Replace elements
iterator
replace(
iterator pos,
param_view const& p);
» more...
Replace elements
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
» more...
Replace elements
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
» more...
Remove the value on an element
iterator
unset(iterator pos) noexcept;
This function removes the value of an element at the specified position. After the call returns, `has_value` for the element is false.
All iterators that are equal to `pos` or come after are invalidated.
url u( "?first=John&last=Doe" );
u.params().unset( u.params().begin() );
assert( u.encoded_query() == "first&last=Doe" );
Linear in `this->url().encoded_query().size()`.
Throws nothing.
Set a value
iterator
set(
iterator pos,
core::string_view value);
» more...
Set a value
iterator
set(
core::string_view key,
core::string_view value,
ignore_case_param ic = = {});
» more...
Common functionality for containers
class params_base;
This base class is used by the library to provide common member functions for containers. This cannot be instantiated directly; Instead, use one of the containers or functions:
using value_type = value_type;
using reference = reference;
using pointer = reference;
using difference_type = difference_type;
using iterator_category = std::bidirectional_iterator_tag;
iterator() = default;
» more...
constexpr
iterator(iterator const&) = default;
» more...
iterator&
operator=(iterator const&) noexcept = default;
iterator&
operator++() noexcept;
» more...
iterator
operator++(int) noexcept;
» more...
iterator&
operator--() noexcept;
» more...
iterator
operator--(int) noexcept;
» more...
reference
operator*() const;
pointer
operator->() const = delete;
bool
operator==(iterator const& other) const noexcept;
bool
operator!=(iterator const& other) const noexcept;
iterator
using const_iterator = iterator;
The value type
using value_type = param;
Values of this type represent parameters whose strings retain unique ownership by making a copy.
params_view::value_type qp( *url_view( "?first=John&last=Doe" ).params().find( "first" ) );
The reference type
using reference = param;
This is the type of value returned when iterators of the view are dereferenced.
The reference type
using const_reference = param;
This is the type of value returned when iterators of the view are dereferenced.
An unsigned integer type to represent sizes.
using size_type = std::size_t;
A signed integer type used to represent differences.
using difference_type = std::ptrdiff_t;
Return the maximum number of characters possible
constexpr
static
std::size_t
max_size() noexcept;
This represents the largest number of characters that are possible in a path, not including any null terminator.
Throws nothing.
Return the referenced character buffer.
pct_string_view
buffer() const noexcept;
This function returns the character buffer referenced by the view. The returned string may contain percent escapes.
assert( url_view( "?first=John&last=Doe" ).params().buffer() == "?first=John&last=Doe" );
Constant.
Throws nothing.
Return true if there are no params
bool
empty() const noexcept;
assert( ! url_view( "?key=value" ).params().empty() );
Constant.
Throws nothing.
Return the number of params
std::size_t
size() const noexcept;
assert( url_view( "?key=value").params().size() == 1 );
Constant.
Throws nothing.
Return an iterator to the beginning
iterator
begin() const noexcept;
Linear in the size of the first param.
Throws nothing.
Return an iterator to the end
iterator
end() const noexcept;
Constant.
Throws nothing.
Return true if a matching key exists
bool
contains(
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key. The comparison is performed as if all escaped characters were decoded first.
assert( url_view( "?first=John&last=Doe" ).params().contains( "first" ) );
Linear in `this->buffer().size()`.
Throws nothing.
Return the number of matching keys
std::size_t
count(
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find the number of matches for the specified key. The comparison is performed as if all escaped characters were decoded first.
assert( url_view( "?first=John&last=Doe" ).params().count( "first" ) == 1 );
Linear in `this->buffer().size()`.
Throws nothing.
Find a matching key
iterator
find(
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
Find a matching key
iterator
find(
iterator from,
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
Find a matching key
iterator
find_last(
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
Find a matching key
iterator
find_last(
iterator before,
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
» more...
A view representing query parameters in a URL
class params_view
: public params_base;
Objects of this type are used to interpret the query parameters as a bidirectional view of key/value pairs.
The view does not retain ownership of the elements and instead references the original character buffer. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
url_view u( "?first=John&last=Doe" );
params_view p = u.params();
Percent escapes in strings returned when dereferencing iterators are automatically decoded.
Changes to the underlying character buffer can invalidate iterators which reference it.
Constructor
params_view() = default;
» more...
Constructor
constexpr
params_view(params_view const& other) = default;
» more...
Constructor
params_view(
params_view const& other,
encoding_opts opt) noexcept;
» more...
Constructor
params_view(core::string_view s);
» more...
Constructor
params_view(
core::string_view s,
encoding_opts opt);
» more...
Assignment
params_view&
operator=(params_view const&) = default;
After assignment, both views reference the same underlying character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant
Throws nothing
A view representing query parameters in a URL
class params_encoded_view
: public params_encoded_base;
Objects of this type are used to interpret the query parameters as a bidirectional view of key/value pairs.
The view does not retain ownership of the elements and instead references the original character buffer. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
url_view u( "?first=John&last=Doe" );
params_encoded_view p = u.encoded_params();
Strings produced when elements are returned have type param_pct_view and represent encoded strings. Strings passed to member functions may contain percent escapes, and throw exceptions on invalid inputs.
Changes to the underlying character buffer can invalidate iterators which reference it.
Constructor
constexpr
params_encoded_view() = default;
» more...
Constructor
constexpr
params_encoded_view(params_encoded_view const& other) = default;
» more...
Constructor
params_encoded_view(core::string_view s);
» more...
Assignment
constexpr
params_encoded_view&
operator=(params_encoded_view const&) = default;
After assignment, both views reference the same underlying character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant
Throws nothing
Conversion
operator params_view() const noexcept;
This conversion returns a new view which references the same underlying character buffer, and whose iterators and members return ordinary strings with decoding applied to any percent escapes.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
params_view qp = parse_path( "/path/to/file.txt" ).value();
params_view( *this ).buffer().data() == this->buffer().data()
Constant
Throws nothing
friend
system::result
parse_query(core::string_view s) noexcept;
Parse a string and return an encoded params view
system::result
parse_query(core::string_view s) noexcept;
This function parses the string and returns the corresponding params object if the string is valid, otherwise returns an error.
No-throw guarantee.
Common functionality for containers
class url_base
: public url_view_base;
This base class is used by the library to provide common member functions for containers. This cannot be instantiated directly; Instead, use one of the containers or functions:
Return the url as a null-terminated string
char const*
c_str() const noexcept;
This function returns a pointer to a null terminated string representing the url, which may contain percent escapes.
assert( std::strlen( url( "http://www.example.com" ).c_str() ) == 22 );
Constant.
Throws nothing.
Return the number of characters that can be stored without reallocating
std::size_t
capacity() const noexcept;
This does not include the null terminator, which is always present.
Constant.
Throws nothing.
Clear the contents while preserving the capacity
void
clear() noexcept;
this->empty() == true
Constant.
No-throw guarantee.
Adjust the capacity without changing the size
void
reserve(std::size_t n);
This function adjusts the capacity of the container in characters, without affecting the current contents. Has no effect if `n<= this->capacity()`.
Strong guarantee. Calls to allocate may throw.
Set the scheme
url_base&
set_scheme(core::string_view s);
The scheme is set to the specified string, which must contain a valid scheme without any trailing colon (':'). Note that schemes are case-insensitive, and the canonical form is lowercased.
assert( url( "http://www.example.com" ).set_scheme( "https" ).scheme_id() == scheme::https );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
url_base&
set_scheme_id(scheme id);
Remove the scheme
url_base&
remove_scheme();
This function removes the scheme if it is present.
assert( url("http://www.example.com/index.htm" ).remove_scheme().buffer() == "//www.example.com/index.htm" );
this->has_scheme() == false && this->scheme_id() == scheme::none
Linear in `this->size()`.
Throws nothing.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Set the authority
url_base&
set_encoded_authority(pct_string_view s);
This function sets the authority to the specified string. The string may contain percent-escapes.
assert( url().set_encoded_authority( "My%20Computer" ).has_authority() );
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Remove the authority
url_base&
remove_authority();
This function removes the authority, which includes the userinfo, host, and a port if present.
assert( url( "http://example.com/echo.cgi" ).remove_authority().buffer() == "http:/echo.cgi" );
this->has_authority() == false && this->has_userinfo() == false && this->has_port() == false
Linear in `this->size()`.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Set the userinfo
url_base&
set_userinfo(core::string_view s);
The userinfo is set to the given string, which may contain percent-escapes. Any special or reserved characters in the string are automatically percent-encoded. The effects on the user and password depend on the presence of a colon (':') in the string:
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://example.com" ).set_userinfo( "user:pass" ).encoded_user() == "user" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the userinfo.
url_base&
set_encoded_userinfo(pct_string_view s);
The userinfo is set to the given string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result. The effects on the user and password depend on the presence of a colon (':') in the string:
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://example.com" ).set_encoded_userinfo( "john%20doe" ).user() == "john doe" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Remove the userinfo
url_base&
remove_userinfo() noexcept;
This function removes the userinfo if present, without removing any authority.
assert( url( "http://user@example.com" ).remove_userinfo().has_userinfo() == false );
this->has_userinfo() == false && this->encoded_userinfo().empty == true
Linear in `this->size()`.
Throws nothing.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the user
url_base&
set_user(core::string_view s);
This function sets the user part of the userinfo to the string. Any special or reserved characters in the string are automatically percent-encoded.
assert( url().set_user("john doe").encoded_userinfo() == "john%20doe" );
this->has_authority() == true && this->has_userinfo() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the user
url_base&
set_encoded_user(pct_string_view s);
This function sets the user part of the userinfo the the string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url().set_encoded_user("john%20doe").userinfo() == "john doe" );
this->has_authority() == true && this->has_userinfo() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the password.
url_base&
set_password(core::string_view s);
This function sets the password in the userinfo to the string. Reserved characters in the string are percent-escaped in the result.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url("http://user@example.com").set_password( "pass" ).encoded_userinfo() == "user:pass" );
this->has_password() == true && this->password() == s
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the password.
url_base&
set_encoded_password(pct_string_view s);
This function sets the password in the userinfo to the string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url("http://user@example.com").set_encoded_password( "pass" ).encoded_userinfo() == "user:pass" );
this->has_password() == true
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Remove the password
url_base&
remove_password() noexcept;
This function removes the password from the userinfo if a password exists. If there is no userinfo or no authority, the call has no effect.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://user:pass@example.com" ).remove_password().authority().buffer() == "user@example.com" );
this->has_password() == false && this->encoded_password().empty() == true
Linear in `this->size()`.
Throws nothing.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the host
url_base&
set_host(core::string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host
url_base&
set_encoded_host(pct_string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
url_base&
set_host_address(core::string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host_address( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `s.size()`.
Strong guarantee. Calls to allocate may throw.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
url_base&
set_encoded_host_address(pct_string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
url_base&
set_host_ipv4(ipv4_address const& addr);
The host is set to the specified IPv4 address. The host type is host_type::ipv4 .
assert( url("http://www.example.com").set_host_ipv4( ipv4_address( "127.0.0.1" ) ).buffer() == "http://127.0.0.1" );
Linear in `this->size()`.
this->has_authority() == true && this->host_ipv4_address() == addr && this->host_type() == host_type::ipv4
Strong guarantee. Calls to allocate may throw.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
Set the host to an address
url_base&
set_host_ipv6(ipv6_address const& addr);
The host is set to the specified IPv6 address. The host type is host_type::ipv6 .
assert( url().set_host_ipv6( ipv6_address( "1::6:c0a8:1" ) ).authority().buffer() == "[1::6:c0a8:1]" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::ipv6
Linear in `this->size()`.
Strong guarantee. Calls to allocate may throw.
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
Set the host to an address
url_base&
set_host_ipvfuture(core::string_view s);
The host is set to the specified IPvFuture string. The host type is host_type::ipvfuture .
assert( url().set_host_ipvfuture( "v42.bis" ).buffer() == "//[v42.bis]" );
Linear in `this->size() + s.size()`.
this->has_authority() == true && this->host_ipvfuture) == s && this->host_type() == host_type::ipvfuture
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
Set the host to a name
url_base&
set_host_name(core::string_view s);
The host is set to the specified string, which may be empty. Reserved characters in the string are percent-escaped in the result. The host type is host_type::name .
assert( url( "http://www.example.com/index.htm").set_host_name( "localhost" ).host_address() == "localhost" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
Strong guarantee. Calls to allocate may throw.
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to a name
url_base&
set_encoded_host_name(pct_string_view s);
The host is set to the specified string, which may contain percent-escapes and can be empty. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result. The host type is host_type::name .
assert( url( "http://www.example.com/index.htm").set_encoded_host_name( "localhost" ).host_address() == "localhost" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the port
url_base&
set_port_number(std::uint16_t n);
The port is set to the specified integer.
assert( url( "http://www.example.com" ).set_port_number( 8080 ).authority().buffer() == "www.example.com:8080" );
this->has_authority() == true && this->has_port() == true && this->port_number() == n
Linear in `this->size()`.
Strong guarantee. Calls to allocate may throw.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Set the port
url_base&
set_port(core::string_view s);
This port is set to the string, which must contain only digits or be empty. An empty port string is distinct from having no port.
assert( url( "http://www.example.com" ).set_port( "8080" ).authority().buffer() == "www.example.com:8080" );
this->has_port() == true && this->port_number() == n && this->port() == std::to_string(n)
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
port = *DIGIT
Remove the port
url_base&
remove_port() noexcept;
If a port exists, it is removed. The rest of the authority is unchanged.
assert( url( "http://www.example.com:80" ).remove_port().authority().buffer() == "www.example.com" );
this->has_port() == false && this->port_number() == 0 && this->port() == ""
Linear in `this->size()`.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Set if the path is absolute
bool
set_path_absolute(bool absolute);
This function adjusts the path to make it absolute or not, depending on the parameter.
If an authority is present, the path is always absolute. In this case, the function has no effect.
url u( "path/to/file.txt" );
assert( u.set_path_absolute( true ) );
assert( u.buffer() == "/path/to/file.txt" );
this->is_path_absolute() == true && this->encoded_path().front() == '/'
Linear in `this->size()`.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Set the path.
url_base&
set_path(core::string_view s);
This function sets the path to the string, which may be empty. Reserved characters in the string are percent-escaped in the result.
The library may adjust the final result to ensure that no other parts of the url is semantically affected.
This function does not encode '/' chars, which are unreserved for paths but reserved for path segments. If a path segment should include encoded '/'s to differentiate it from path separators, the functions set_encoded_path or segments should be used instead.
url u( "http://www.example.com" );
u.set_path( "path/to/file.txt" );
assert( u.path() == "/path/to/file.txt" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Set the path.
url_base&
set_encoded_path(pct_string_view s);
This function sets the path to the string, which may contain percent-escapes and can be empty. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
The library may adjust the final result to ensure that no other parts of the url is semantically affected.
url u( "http://www.example.com" );
u.set_encoded_path( "path/to/file.txt" );
assert( u.encoded_path() == "/path/to/file.txt" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return the path as a container of segments
segments_ref
segments() noexcept;
» more...
Return the path as a container of segments
segments_view
segments() const noexcept;
» more...
Return the path as a container of segments
segments_encoded_ref
encoded_segments() noexcept;
» more...
Return the path as a container of segments
segments_encoded_view
encoded_segments() const noexcept;
» more...
Set the query
url_base&
set_query(core::string_view s);
This sets the query to the string, which can be empty. An empty query is distinct from having no query. Reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_query( "id=42" ).query() == "id=42" );
this->has_query() == true && this->query() == s
Strong guarantee. Calls to allocate may throw.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Set the query
url_base&
set_encoded_query(pct_string_view s);
This sets the query to the string, which may contain percent-escapes and can be empty. An empty query is distinct from having no query. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_encoded_query( "id=42" ).encoded_query() == "id=42" );
this->has_query() == true && this->query() == decode_view( s );
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Return the query as a container of parameters
params_ref
params() noexcept;
» more...
url_view_base::params
params_view
params() const noexcept;
» more...
Return the query as a container of parameters
params_ref
params(encoding_opts opt) noexcept;
» more...
Return the query as a container of parameters
params_encoded_view
encoded_params() const noexcept;
» more...
Return the query as a container of parameters
params_encoded_ref
encoded_params() noexcept;
» more...
Set the query params
url_base&
set_params(std::initializer_list ps) noexcept;
This sets the query params to the list of param_view, which can be empty.
An empty list of params is distinct from having no params.
Reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_params( {"id", "42"} ).query() == "id=42" );
this->has_query() == true
Strong guarantee. Calls to allocate may throw.
Linear.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Set the query params
url_base&
set_encoded_params(std::initializer_list ps) noexcept;
This sets the query params to the elements in the list, which may contain percent-escapes and can be empty.
An empty list of params is distinct from having no query.
Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_encoded_params( {"id", "42"} ).encoded_query() == "id=42" );
this->has_query() == true
Linear.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Remove the query
url_base&
remove_query() noexcept;
If a query is present, it is removed. An empty query is distinct from having no query.
assert( url( "http://www.example.com?id=42" ).remove_query().buffer() == "http://www.example.com" );
this->has_query() == false && this->params().empty()
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Remove the fragment
url_base&
remove_fragment() noexcept;
This function removes the fragment. An empty fragment is distinct from having no fragment.
assert( url( "?first=john&last=doe#anchor" ).remove_fragment().buffer() == "?first=john&last=doe" );
this->has_fragment() == false && this->encoded_fragment() == ""
Constant.
Throws nothing.
fragment = *( pchar / "/" / "?" )
Set the fragment.
url_base&
set_fragment(core::string_view s);
This function sets the fragment to the specified string, which may be empty. An empty fragment is distinct from having no fragment. Reserved characters in the string are percent-escaped in the result.
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john doe" ).encoded_fragment() == "john%20doe" );
this->has_fragment() == true && this->fragment() == s
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
fragment = *( pchar / "/" / "?" )
Set the fragment.
url_base&
set_encoded_fragment(pct_string_view s);
This function sets the fragment to the specified string, which may contain percent-escapes and which may be empty. An empty fragment is distinct from having no fragment. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john%2Ddoe" ).fragment() == "john-doe" );
this->has_fragment() == true && this->fragment() == decode_view( s )
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
fragment = *( pchar / "/" / "?" )
Remove the origin component
url_base&
remove_origin();
This function removes the origin, which consists of the scheme and authority.
assert( url( "http://www.example.com/index.htm" ).remove_origin().buffer() == "/index.htm" );
this->scheme_id() == scheme::none && this->has_authority() == false
Linear in `this->size()`.
Throws nothing.
Normalize the URL components
url_base&
normalize();
Applies Syntax-based normalization to all components of the URL.
Strong guarantee. Calls to allocate may throw.
Normalize the URL scheme
url_base&
normalize_scheme();
Applies Syntax-based normalization to the URL scheme.
The scheme is normalized to lowercase.
Strong guarantee. Calls to allocate may throw.
Normalize the URL authority
url_base&
normalize_authority();
Applies Syntax-based normalization to the URL authority.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Normalize the URL path
url_base&
normalize_path();
Applies Syntax-based normalization to the URL path.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded. Redundant path-segments are removed.
Strong guarantee. Calls to allocate may throw.
Normalize the URL query
url_base&
normalize_query();
Applies Syntax-based normalization to the URL query.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Normalize the URL fragment
url_base&
normalize_fragment();
Applies Syntax-based normalization to the URL fragment.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Resolve a URL reference against this base URL
system::result
resolve(url_view_base const& ref);
This function attempts to resolve a URL reference `ref` against this base URL in a manner similar to that of a web browser resolving an anchor tag.
This URL must satisfy the URI grammar. In other words, it must contain a scheme.
Relative references are only usable when in the context of a base absolute URI. This process of resolving a relative reference within the context of a base URI is defined in detail in rfc3986 (see below).
The resolution process works as if the relative reference is appended to the base URI and the result is normalized.
Given the input base URL, this function resolves the relative reference as if performing the following steps:
This function places the result of the resolution into this URL in place.
If an error occurs, the contents of this URL are unspecified and a result with an `system::error_code` is returned.
Abnormal hrefs where the number of ".." segments exceeds the number of segments in the base path are handled by including the unmatched ".." segments in the result, as described in Errata 4547 .
url base1( "/one/two/three" );
base1.resolve("four");
assert( base1.buffer() == "/one/two/four" );
url base2( "http://example.com/" )
base2.resolve("/one");
assert( base2.buffer() == "http://example.com/one" );
url base3( "http://example.com/one" );
base3.resolve("/two");
assert( base3.buffer() == "http://example.com/two" );
url base4( "http://a/b/c/d;p?q" );
base4.resolve("g#s");
assert( base4.buffer() == "http://a/b/c/g#s" );
absolute-URI = scheme ":" hier-part [ "?" query ]
Basic guarantee. Calls to allocate may throw.
friend
system::result
resolve(
url_view_base const& base,
url_view_base const& ref,
url_base& dest);
A view representing query parameters in a URL
class params_encoded_ref
: public params_encoded_base;
Objects of this type are used to interpret the query parameters as a bidirectional view of key value pairs.
The view does not retain ownership of the elements and instead references the original url. The caller is responsible for ensuring that the lifetime of the referenced url extends until it is no longer referenced.
The view is modifiable; calling non-const members causes changes to the referenced url.
url u( "?first=John&last=Doe" );
params_encoded_ref p = u.encoded_params();
Strings produced when elements are returned have type param_pct_view and represent encoded strings. Strings passed to member functions may contain percent escapes, and throw exceptions on invalid inputs.
Changes to the underlying character buffer can invalidate iterators which reference it. Modifications made through the container invalidate some iterators to the underlying character buffer:
Constructor
constexpr
params_encoded_ref(params_encoded_ref const& other) = default;
After construction, both views reference the same url. Ownership is not transferred; the caller is responsible for ensuring the lifetime of the url extends until it is no longer referenced.
&this->url() == &other.url();
Constant.
Throws nothing.
Assignment
params_encoded_ref&
operator=(params_encoded_ref const& other);
» more...
Assignment
params_encoded_ref&
operator=(std::initializer_list init);
» more...
Conversion
operator params_encoded_view() const noexcept;
Constant.
Throws nothing.
Return the referenced url
url_base&
url() const noexcept;
This function returns the url referenced by the view.
url u( "?key=value" );
assert( &u.encoded_params().url() == &u );
Throws nothing.
Clear the contents of the container
void
clear() noexcept;
All iterators are invalidated.
this->url().remove_query();
this->empty() == true && this->url().has_query() == false
Constant.
Throws nothing.
Assign params
void
assign(std::initializer_list init);
» more...
Assign params
template
void
assign(
FwdIt first,
FwdIt last);
» more...
Append params
iterator
append(param_pct_view const& p);
» more...
Append params
iterator
append(std::initializer_list init);
» more...
Append params
template
iterator
append(
FwdIt first,
FwdIt last);
» more...
Insert params
iterator
insert(
iterator before,
param_pct_view const& p);
» more...
Insert params
iterator
insert(
iterator before,
std::initializer_list init);
» more...
Insert params
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
» more...
Erase params
iterator
erase(iterator pos) noexcept;
» more...
Erase params
iterator
erase(
iterator first,
iterator last) noexcept;
» more...
Erase params
std::size_t
erase(
pct_string_view key,
ignore_case_param ic = = {}) noexcept;
» more...
Replace params
iterator
replace(
iterator pos,
param_pct_view const& p);
» more...
Replace params
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
» more...
Replace params
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
» more...
Remove the value on an element
iterator
unset(iterator pos) noexcept;
This function removes the value of an element at the specified position. After the call returns, `has_value` for the element is false.
All iterators that are equal to `pos` or come after are invalidated.
url u( "?first=John&last=Doe" );
u.encoded_params().unset( u.encoded_params().begin() );
assert( u.encoded_query() == "first&last=Doe" );
Linear in `this->url().encoded_query().size()`.
Throws nothing.
Set a value
iterator
set(
iterator pos,
pct_string_view value);
» more...
Set a value
iterator
set(
pct_string_view key,
pct_string_view value,
ignore_case_param ic = = {});
» more...
A view representing path segments in a URL
class segments_encoded_ref
: public segments_encoded_base;
Objects of this type are used to interpret the path as a bidirectional view of segments, where each segment is a string which may contain percent-escapes.
The view does not retain ownership of the elements and instead references the original character buffer. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
The view is modifiable; calling non-const members causes changes to the referenced url.
url u( "/path/to/file.txt" );
segments_encoded_ref ps = u.encoded_segments();
The strings returned when iterators are dereferenced have type pct_string_view and may contain percent-escapes.
Reserved characters in inputs are automatically escaped. Escapes in inputs are preserved.
Exceptions are thrown on invalid inputs.
Changes to the underlying character buffer can invalidate iterators which reference it. Modifications made through the container invalidate some or all iterators:
Constructor
constexpr
segments_encoded_ref(segments_encoded_ref const& other) = default;
After construction, both views reference the same url. Ownership is not transferred; the caller is responsible for ensuring the lifetime of the url extends until it is no longer referenced.
&this->url() == &other.url();
Constant.
Throws nothing.
Assignment
segments_encoded_ref&
operator=(segments_encoded_ref const& other);
» more...
segments_encoded_ref&
operator=(segments_encoded_view const& other);
» more...
Assignment
segments_encoded_ref&
operator=(std::initializer_list init);
» more...
Conversion
operator segments_encoded_view() const noexcept;
Return the referenced url
url_base&
url() const noexcept;
This function returns the url referenced by the view.
url u( "/path/to/file.txt" );
assert( &u.encoded_segments().url() == &u );
Throws nothing.
Clear the contents of the container
void
clear() noexcept;
All iterators are invalidated.
this->url().set_encoded_path( "" );
this->empty() == true
Linear in `this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Throws nothing.
Assign segments
void
assign(std::initializer_list init);
» more...
Assign segments
template
void
assign(
FwdIt first,
FwdIt last);
» more...
Insert segments
iterator
insert(
iterator before,
pct_string_view s);
» more...
Insert segments
iterator
insert(
iterator before,
std::initializer_list init);
» more...
Insert segments
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
» more...
Erase segments
iterator
erase(iterator pos) noexcept;
» more...
Erase segments
iterator
erase(
iterator first,
iterator last) noexcept;
» more...
Replace segments
iterator
replace(
iterator pos,
pct_string_view s);
» more...
Replace segments
iterator
replace(
iterator from,
iterator to,
pct_string_view s);
» more...
Replace segments
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
» more...
Replace segments
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
» more...
Append a segment
void
push_back(pct_string_view s);
This function appends a segment to the end of the path. Reserved characters in the string are automatically escaped. Escapes in the string are preserved.
All end iterators are invalidated.
this->back() == s
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Remove the last segment
void
pop_back() noexcept;
This function removes the last segment from the container.
Iterators to the last segment as well as all end iterators are invalidated.
not this->empty()
Throws nothing.
A view representing path segments in a URL
class segments_ref
: public segments_base;
Objects of this type are used to interpret the path as a bidirectional view of segments, where each segment is a string with percent escapes automatically decoded.
The view does not retain ownership of the elements and instead references the original character buffer. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
The view is modifiable; calling non-const members causes changes to the referenced url.
url u( "/path/to/file.txt" );
segments_ref ps = u.segments();
Percent escapes in strings returned when dereferencing iterators are automatically decoded. Reserved characters in strings supplied to modifier functions are automatically percent-escaped.
Changes to the underlying character buffer can invalidate iterators which reference it. Modifications made through the container invalidate some or all iterators:
Constructor
constexpr
segments_ref(segments_ref const& other) = default;
After construction, both views reference the same url. Ownership is not transferred; the caller is responsible for ensuring the lifetime of the url extends until it is no longer referenced.
&this->url() == &other.url();
Constant.
Throws nothing.
Assignment
segments_ref&
operator=(segments_ref const& other);
» more...
segments_ref&
operator=(segments_view const& other);
» more...
Assignment
segments_ref&
operator=(std::initializer_list init);
» more...
Conversion
operator segments_view() const noexcept;
Return the referenced url
url_base&
url() const noexcept;
This function returns the url referenced by the view.
url u( "/path/to/file.txt" );
assert( &u.segments().url() == &u );
Throws nothing.
Clear the contents of the container
void
clear() noexcept;
All iterators are invalidated.
this->url().set_encoded_path( "" );
this->empty() == true
Linear in `this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Throws nothing.
Assign segments
void
assign(std::initializer_list init);
» more...
Assign segments
template
void
assign(
FwdIt first,
FwdIt last);
» more...
Insert segments
iterator
insert(
iterator before,
core::string_view s);
» more...
Insert segments
iterator
insert(
iterator before,
std::initializer_list init);
» more...
Insert segments
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
» more...
Erase segments
iterator
erase(iterator pos) noexcept;
» more...
Erase segments
iterator
erase(
iterator first,
iterator last) noexcept;
» more...
Replace segments
iterator
replace(
iterator pos,
core::string_view s);
» more...
Replace segments
iterator
replace(
iterator from,
iterator to,
core::string_view s);
» more...
Replace segments
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
» more...
Replace segments
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
» more...
Append a segment
void
push_back(core::string_view s);
This function appends a segment to the end of the path. Reserved characters in the string are automatically escaped.
All end iterators are invalidated.
this->back() == s
Strong guarantee. Calls to allocate may throw.
Remove the last segment
void
pop_back() noexcept;
This function removes the last segment from the container.
Iterators to the last segment as well as all end iterators are invalidated.
not this->empty()
Throws nothing.
Common functionality for containers
class url_view_base;
This base class is used by the library to provide common member functions for containers. This cannot be instantiated directly; Instead, use one of the containers or functions:
std::size_t
digest(std::size_t = 0) const noexcept;
Return the maximum number of characters possible
constexpr
static
std::size_t
max_size() noexcept;
This represents the largest number of characters that are theoretically possible to represent in a url, not including any null terminator. In practice the actual possible size may be lower than this number.
Constant.
Throws nothing.
Return the number of characters in the url
std::size_t
size() const noexcept;
This function returns the number of characters in the url's encoded string, not including any null terminator, if present.
assert( url_view( "file:///Program%20Files" ).size() == 23 );
Constant.
Throws nothing.
Return true if the url is empty
bool
empty() const noexcept;
The empty string matches the relative-ref grammar.
assert( url_view( "" ).empty() );
Constant.
Throws nothing.
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-empty
Return a pointer to the url's character buffer
char const*
data() const noexcept;
This function returns a pointer to the first character of the url, which is not guaranteed to be null-terminated.
Constant.
Throws nothing.
Return the url string
core::string_view
buffer() const noexcept;
This function returns the entire url, which may contain percent escapes.
assert( url_view( "http://www.example.com" ).buffer() == "http://www.example.com" );
Constant.
Throws nothing.
Return the URL as a core::string_view
operator core::string_view() const noexcept;
Constant.
Throws nothing.
Return a shared, persistent copy of the url
std::shared_ptr
persist() const;
This function returns a read-only copy of the url, with shared lifetime. The returned value owns (persists) the underlying string. The algorithm used to create the value minimizes the number of individual memory allocations, making it more efficient than when using direct standard library functions.
std::shared_ptr< url_view const > sp;
{
std::string s( "http://example.com" );
url_view u( s ); // u references characters in s
assert( u.data() == s.data() ); // same buffer
sp = u.persist();
assert( sp->data() != s.data() ); // different buffer
assert( sp->buffer() == s); // same contents
// s is destroyed and thus u
// becomes invalid, but sp remains valid.
}
Linear in `this->size()`.
Calls to allocate may throw.
Return true a scheme is present
bool
has_scheme() const noexcept;
This function returns true if this contains a scheme.
assert( url_view( "http://www.example.com" ).has_scheme() );
Constant.
Throws nothing.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
absolute-URI = scheme ":" hier-part [ "?" query ]
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Return the scheme
core::string_view
scheme() const noexcept;
This function returns the scheme if it exists, without a trailing colon (':'). Otherwise it returns an empty string. Note that schemes are case-insensitive, and the canonical form is lowercased.
assert( url_view( "http://www.example.com" ).scheme() == "http" );
Throws nothing.
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
absolute-URI = scheme ":" hier-part [ "?" query ]
Return the scheme
scheme
scheme_id() const noexcept;
This function returns a value which depends on the scheme in the url:
assert( url_view( "wss://www.example.com/crypto.cgi" ).scheme_id() == scheme::wss );
Constant.
Throws nothing.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
absolute-URI = scheme ":" hier-part [ "?" query ]
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Return true if an authority is present
bool
has_authority() const noexcept;
This function returns true if the url contains an authority. The presence of an authority is denoted by a double slash ("//") at the beginning or after the scheme.
assert( url_view( "http://www.example.com/index.htm" ).has_authority() );
Constant.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
absolute-URI = scheme ":" hier-part [ "?" query ]
URI-reference = URI / relative-ref
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
hier-part = "//" authority path-abempty
; (more...)
relative-part = "//" authority path-abempty
; (more...)
Return the authority
authority_view
authority() const noexcept;
This function returns the authority as an authority_view .
authority_view a = url_view( "https://www.example.com:8080/index.htm" ).authority();
Constant.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
Return the authority.
pct_string_view
encoded_authority() const noexcept;
If present, this function returns a string representing the authority (which may be empty). Otherwise it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "file://Network%20Drive/My%2DFiles" ).encoded_authority() == "Network%20Drive" );
Constant.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
Return true if a userinfo is present
bool
has_userinfo() const noexcept;
This function returns true if this contains a userinfo.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
authority = [ userinfo "@" ] host [ ":" port ]
Return true if a password is present
bool
has_password() const noexcept;
This function returns true if the userinfo is present and contains a password.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the userinfo
template
StringToken::result_type
userinfo(StringToken&& token) const;
If present, this function returns a string representing the userinfo (which may be empty). Otherwise it returns an empty string. Any percent-escapes in the string are decoded first.
This function uses the string token return type customization. Depending on the token passed, the return type and behavior of the function can be different. See string_token::return_string for more information.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" );
Linear in `this->userinfo().size()`.
Calls to allocate may throw.
userinfo = user [ ":" [ password ] ]
authority = [ userinfo "@" ] host [ ":" port ]
Return the userinfo
pct_string_view
encoded_userinfo() const noexcept;
If present, this function returns a string representing the userinfo (which may be empty). Otherwise it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" );
Constant.
Throws nothing
userinfo = user [ ":" [ password ] ]
authority = [ userinfo "@" ] host [ ":" port ]
Return the user
template
StringToken::result_type
user(StringToken&& token) const;
If present, this function returns a string representing the user (which may be empty). Otherwise it returns an empty string. Any percent-escapes in the string are decoded first.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" );
Linear in `this->user().size()`.
Calls to allocate may throw.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the user
pct_string_view
encoded_user() const noexcept;
If present, this function returns a string representing the user (which may be empty). Otherwise it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the password
template
StringToken::result_type
password(StringToken&& token) const;
If present, this function returns a string representing the password (which may be an empty string). Otherwise it returns an empty string. Any percent-escapes in the string are decoded first.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" );
Linear in `this->password().size()`.
Calls to allocate may throw.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the password
pct_string_view
encoded_password() const noexcept;
This function returns the password portion of the userinfo as a percent-encoded string.
assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" );
Constant.
Throws nothing.
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Return the host type
host_type
host_type() const noexcept;
This function returns one of the following constants representing the type of host present.
When has_authority is false, the host type is host_type::none .
assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 );
Constant.
Throws nothing.
Return the host
template
StringToken::result_type
host(StringToken&& token) const;
This function returns the host portion of the authority as a string, or the empty string if there is no authority. Any percent-escapes in the string are decoded first.
assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" );
Linear in `this->host().size()`.
Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host
pct_string_view
encoded_host() const noexcept;
This function returns the host portion of the authority as a string, or the empty string if there is no authority. The returned string may contain percent escapes.
assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" );
Constant.
Throws nothing.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host
template
StringToken::result_type
host_address(StringToken&& token) const;
The value returned by this function depends on the type of host returned from the function host_type .
assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" );
Linear in `this->host_address().size()`.
Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host
pct_string_view
encoded_host_address() const noexcept;
The value returned by this function depends on the type of host returned from the function host_type .
assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" );
Constant.
Throws nothing.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host IPv4 address
ipv4_address
host_ipv4_address() const noexcept;
If the host type is host_type::ipv4 , this function returns the address as a value of type ipv4_address . Otherwise, if the host type is not an IPv4 address, it returns a default-constructed value which is equal to the unspecified address "0.0.0.0".
assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) );
Constant.
Throws nothing.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
Return the host IPv6 address
ipv6_address
host_ipv6_address() const noexcept;
If the host type is host_type::ipv6 , this function returns the address as a value of type ipv6_address . Otherwise, if the host type is not an IPv6 address, it returns a default-constructed value which is equal to the unspecified address "0:0:0:0:0:0:0:0".
assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) );
Constant.
Throws nothing.
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
Return the host IPvFuture address
core::string_view
host_ipvfuture() const noexcept;
If the host type is host_type::ipvfuture , this function returns the address as a string. Otherwise, if the host type is not an IPvFuture address, it returns an empty string.
assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" );
Constant.
Throws nothing.
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
Return the host name
template
StringToken::result_type
host_name(StringToken&& token) const;
If the host type is host_type::name , this function returns the name as a string. Otherwise an empty string is returned. Any percent-escapes in the string are decoded first.
assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" );
Linear in `this->host_name().size()`.
Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the host name
pct_string_view
encoded_host_name() const noexcept;
If the host type is host_type::name , this function returns the name as a string. Otherwise, if the host type is not an name, it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" );
Constant.
Throws nothing.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Return the IPv6 Zone ID
template
StringToken::result_type
zone_id(StringToken&& token) const;
If the host type is host_type::ipv6 , this function returns the Zone ID as a string. Otherwise an empty string is returned. Any percent-escapes in the string are decoded first.
assert( url_view( "http://[fe80::1%25eth0]/" ).zone_id() == "eth0" );
Linear in `this->encoded_zone_id().size()`.
Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPv6addrz / IPvFuture ) "]"
ZoneID = 1*( unreserved / pct-encoded )
IPv6addrz = IPv6address "%25" ZoneID
Return the IPv6 Zone ID
pct_string_view
encoded_zone_id() const noexcept;
If the host type is host_type::ipv6 , this function returns the Zone ID as a string. Otherwise an empty string is returned. The returned string may contain percent escapes.
assert( url_view( "http://[fe80::1%25eth0]/" ).encoded_zone_id() == "eth0" );
Constant.
Throws nothing.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPv6addrz / IPvFuture ) "]"
ZoneID = 1*( unreserved / pct-encoded )
IPv6addrz = IPv6address "%25" ZoneID
Return true if a port is present
bool
has_port() const noexcept;
This function returns true if an authority is present and contains a port.
assert( url_view( "wss://www.example.com:443" ).has_port() );
Constant.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Return the port
core::string_view
port() const noexcept;
If present, this function returns a string representing the port (which may be empty). Otherwise it returns an empty string.
assert( url_view( "http://localhost.com:8080" ).port() == "8080" );
Constant.
Throws nothing.
port = *DIGIT
Return the port
std::uint16_t
port_number() const noexcept;
If a port is present and the numerical value is representable, it is returned as an unsigned integer. Otherwise, the number zero is returned.
assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 );
Constant.
Throws nothing.
port = *DIGIT
Return true if the path is absolute
bool
is_path_absolute() const noexcept;
This function returns true if the path begins with a forward slash ('/').
assert( url_view( "/path/to/file.txt" ).is_path_absolute() );
Constant.
Throws nothing.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return the path
template
StringToken::result_type
path(StringToken&& token) const;
This function returns the path as a string. The path may be empty. Any percent-escapes in the string are decoded first.
assert( url_view( "file:///Program%20Files/Games/config.ini" ).path() == "/Program Files/Games/config.ini" );
Linear in `this->path().size()`.
Calls to allocate may throw.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return the path
pct_string_view
encoded_path() const noexcept;
This function returns the path as a string. The path may be empty. Any percent-escapes in the string are decoded first.
assert( url_view( "file:///Program%20Files/Games/config.ini" ).encoded_path() == "/Program%20Files/Games/config.ini" );
Constant.
Throws nothing.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return the path as a container of segments
segments_view
segments() const noexcept;
This function returns a bidirectional view of strings over the path. The returned view references the same underlying character buffer; ownership is not transferred. Any percent-escapes in strings returned when iterating the view are decoded first.
segments_view sv = url_view( "/path/to/file.txt" ).segments();
Constant.
Throws nothing.
path = [ "/" ] segment *( "/" segment )
Return the path as a container of segments
segments_encoded_view
encoded_segments() const noexcept;
This function returns a bidirectional view of strings over the path. The returned view references the same underlying character buffer; ownership is not transferred. Strings returned when iterating the range may contain percent escapes.
segments_encoded_view sv = url_view( "/path/to/file.txt" ).encoded_segments();
Constant.
Throws nothing.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return true if a query is present
bool
has_query() const noexcept;
This function returns true if this contains a query. An empty query is distinct from having no query.
assert( url_view( "/sql?id=42&col=name&page-size=20" ).has_query() );
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Return the query
template
StringToken::result_type
query(StringToken&& token) const;
If this contains a query, it is returned as a string (which may be empty). Otherwise, an empty string is returned. Any percent-escapes in the string are decoded first. When plus signs appear in the query portion of the url, they are converted to spaces automatically upon decoding. This behavior can be changed by setting decode options.
assert( url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).query() == "id=42&name=jane-doe&page size=20" );
Linear in `this->query().size()`.
Calls to allocate may throw.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Return the query
pct_string_view
encoded_query() const noexcept;
If this contains a query, it is returned as a string (which may be empty). Otherwise, an empty string is returned. The returned string may contain percent escapes.
assert( url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_query() == "id=42&name=jane%2Ddoe&page+size=20" );
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Return the query as a container of parameters
params_view
params() const noexcept;
» more...
params_view
params(encoding_opts opt) const noexcept;
» more...
Return the query as a container of parameters
params_encoded_view
encoded_params() const noexcept;
This function returns a bidirectional view of key/value pairs over the query. The returned view references the same underlying character buffer; ownership is not transferred. Strings returned when iterating the range may contain percent escapes.
params_encoded_view pv = url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_params();
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Return true if a fragment is present
bool
has_fragment() const noexcept;
This function returns true if the url contains a fragment. An empty fragment is distinct from no fragment.
assert( url_view( "http://www.example.com/index.htm#anchor" ).has_fragment() );
Constant.
Throws nothing.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Return the fragment
template
StringToken::result_type
fragment(StringToken&& token) const;
This function calculates the fragment of the url, with percent escapes decoded and without the leading pound sign ('#') whose presence indicates that the url contains a fragment.
This function accepts an optional StringToken parameter which controls the return type and behavior of the function:
assert( url_view( "http://www.example.com/index.htm#a%2D1" ).fragment() == "a-1" );
Linear in `this->fragment().size()`.
Calls to allocate may throw. String tokens may throw exceptions.
fragment = *( pchar / "/" / "?" )
fragment-part = [ "#" fragment ]
Return the fragment
pct_string_view
encoded_fragment() const noexcept;
This function returns the fragment as a string with percent-escapes. Ownership is not transferred; the string returned references the underlying character buffer, which must remain valid or else undefined behavior occurs.
assert( url_view( "http://www.example.com/index.htm#a%2D1" ).encoded_fragment() == "a%2D1" );
Constant.
Throws nothing.
fragment = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
Return the host and port
pct_string_view
encoded_host_and_port() const noexcept;
If an authority is present, this function returns the host and optional port as a string, which may be empty. Otherwise it returns an empty string. The returned string may contain percent escapes.
assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" );
Constant.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
Return the origin
pct_string_view
encoded_origin() const noexcept;
If an authority is present, this function returns the scheme and authority portion of the url. Otherwise, an empty string is returned. The returned string may contain percent escapes.
assert( url_view( "http://www.example.com:8080/index.htm?text=none#h1" ).encoded_origin() == "http://www.example.com:8080" );
Constant.
Throws nothing.
Return the resource
pct_string_view
encoded_resource() const noexcept;
This function returns the resource, which is the portion of the url that includes only the path, query, and fragment. The returned string may contain percent escapes.
assert( url_view( "http://www.example.com/index.html?query#frag" ).encoded_resource() == "/index.html?query#frag" );
Constant.
Throws nothing.
Return the target
pct_string_view
encoded_target() const noexcept;
This function returns the target, which is the portion of the url that includes only the path and query. The returned string may contain percent escapes.
assert( url_view( "http://www.example.com/index.html?query#frag" ).encoded_target() == "/index.html?query" );
Constant.
Throws nothing.
Return the result of comparing this with another url
int
compare(url_view_base const& other) const noexcept;
This function compares two URLs according to Syntax-Based comparison algorithm.
Linear in `min( u0.size(), u1.size() )`
Throws nothing.
Return the result of comparing two URLs
friend
bool
operator==(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.a.com/index.htm" );
assert( u0 == u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) ==
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
Return the result of comparing two URLs
friend
bool
operator!=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.b.com/index.htm" );
assert( u0 != u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) !=
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
Return the result of comparing two URLs
friend
bool
operator<(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.b.com/index.htm" );
assert( u0 < u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) <
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
Return the result of comparing two URLs
friend
bool
operator<=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.b.com/index.htm" );
url_view u1( "http://www.b.com/index.htm" );
assert( u0 <= u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) <=
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
Return the result of comparing two URLs
friend
bool
operator>(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.b.com/index.htm" );
url_view u1( "http://www.a.com/index.htm" );
assert( u0 > u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) >
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
Return the result of comparing two URLs
friend
bool
operator>=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.a.com/index.htm" );
assert( u0 >= u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) >=
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
friend
std::ostream&
operator<<(
std::ostream& os,
url_view_base const& u);
Resolve a URL reference against a base URL
system::result
resolve(
url_view_base const& base,
url_view_base const& ref,
url_base& dest);
This function attempts to resolve a URL reference `ref` against the base URL `base` in a manner similar to that of a web browser resolving an anchor tag.
The base URL must satisfy the URI grammar. In other words, it must contain a scheme.
Relative references are only usable when in the context of a base absolute URI. This process of resolving a relative reference within the context of a base URI is defined in detail in rfc3986 (see below).
The resolution process works as if the relative reference is appended to the base URI and the result is normalized.
Given the input base URL, this function resolves the relative reference as if performing the following steps:
This function places the result of the resolution into `dest`, which can be any of the url containers that inherit from url_base .
If an error occurs, the contents of `dest` is unspecified and `ec` is set.
Abnormal hrefs where the number of ".." segments exceeds the number of segments in the base path are handled by including the unmatched ".." segments in the result, as described in Errata 4547 .
url dest;
system::error_code ec;
resolve("/one/two/three", "four", dest, ec);
assert( dest.str() == "/one/two/four" );
resolve("http://example.com/", "/one", dest, ec);
assert( dest.str() == "http://example.com/one" );
resolve("http://example.com/one", "/two", dest, ec);
assert( dest.str() == "http://example.com/two" );
resolve("http://a/b/c/d;p?q", "g#s", dest, ec);
assert( dest.str() == "http://a/b/c/g#s" );
absolute-URI = scheme ":" hier-part [ "?" query ]
Basic guarantee. Calls to allocate may throw.
A modifiable container for a URL.
class url
: public url_base;
This container owns a url, represented by a null-terminated character buffer which is managed by performing dymamic memory allocations as needed. The contents may be inspected and modified, and the implementation maintains a useful invariant: changes to the url always leave it in a valid state.
URI-reference = URI / relative-ref
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
absolute-URI = scheme ":" hier-part [ "?" query ]
Destructor
virtual
~url();
Any params, segments, iterators, or views which reference this object are invalidated. The underlying character buffer is destroyed, invalidating all references to it.
Constructor
url() noexcept;
» more...
Constructor
url(core::string_view s);
» more...
Constructor
url(url&& u) noexcept;
» more...
Constructor
url(url_view_base const& u);
» more...
Constructor
url(url const& u);
» more...
Assignment
url&
operator=(url&& u) noexcept;
» more...
Assignment
url&
operator=(url_view_base const& u);
» more...
Assignment
url&
operator=(url const& u);
» more...
Swap the contents.
void
swap(url& other) noexcept;
Exchanges the contents of this url with another url. All views, iterators and references remain valid.
If `this == &other`, this function call has no effect.
url u1( "https://www.example.com" );
url u2( "https://www.boost.org" );
u1.swap(u2);
assert(u1 == "https://www.boost.org" );
assert(u2 == "https://www.example.com" );
Constant
Throws nothing.
Swap
friend
void
swap(
url& v0,
url& v1) noexcept;
Exchanges the contents of `v0` with another `v1`. All views, iterators and references remain valid.
If `&v0 ==&v1`, this function call has no effect.
url u1( "https://www.example.com" );
url u2( "https://www.boost.org" );
std::swap(u1, u2);
assert(u1 == "https://www.boost.org" );
assert(u2 == "https://www.example.com" );
v0.swap( v1 );
Constant
Throws nothing
Set the scheme
url&
set_scheme(core::string_view s);
The scheme is set to the specified string, which must contain a valid scheme without any trailing colon (':'). Note that schemes are case-insensitive, and the canonical form is lowercased.
assert( url( "http://www.example.com" ).set_scheme( "https" ).scheme_id() == scheme::https );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
url_base::set_scheme_id
url&
set_scheme_id(scheme id);
Remove the scheme
url&
remove_scheme();
This function removes the scheme if it is present.
assert( url("http://www.example.com/index.htm" ).remove_scheme().buffer() == "//www.example.com/index.htm" );
this->has_scheme() == false && this->scheme_id() == scheme::none
Linear in `this->size()`.
Throws nothing.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Set the authority
url&
set_encoded_authority(pct_string_view s);
This function sets the authority to the specified string. The string may contain percent-escapes.
assert( url().set_encoded_authority( "My%20Computer" ).has_authority() );
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Remove the authority
url&
remove_authority();
This function removes the authority, which includes the userinfo, host, and a port if present.
assert( url( "http://example.com/echo.cgi" ).remove_authority().buffer() == "http:/echo.cgi" );
this->has_authority() == false && this->has_userinfo() == false && this->has_port() == false
Linear in `this->size()`.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Set the userinfo
url&
set_userinfo(core::string_view s);
The userinfo is set to the given string, which may contain percent-escapes. Any special or reserved characters in the string are automatically percent-encoded. The effects on the user and password depend on the presence of a colon (':') in the string:
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://example.com" ).set_userinfo( "user:pass" ).encoded_user() == "user" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the userinfo.
url&
set_encoded_userinfo(pct_string_view s);
The userinfo is set to the given string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result. The effects on the user and password depend on the presence of a colon (':') in the string:
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://example.com" ).set_encoded_userinfo( "john%20doe" ).user() == "john doe" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Remove the userinfo
url&
remove_userinfo() noexcept;
This function removes the userinfo if present, without removing any authority.
assert( url( "http://user@example.com" ).remove_userinfo().has_userinfo() == false );
this->has_userinfo() == false && this->encoded_userinfo().empty == true
Linear in `this->size()`.
Throws nothing.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the user
url&
set_user(core::string_view s);
This function sets the user part of the userinfo to the string. Any special or reserved characters in the string are automatically percent-encoded.
assert( url().set_user("john doe").encoded_userinfo() == "john%20doe" );
this->has_authority() == true && this->has_userinfo() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the user
url&
set_encoded_user(pct_string_view s);
This function sets the user part of the userinfo the the string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url().set_encoded_user("john%20doe").userinfo() == "john doe" );
this->has_authority() == true && this->has_userinfo() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the password.
url&
set_password(core::string_view s);
This function sets the password in the userinfo to the string. Reserved characters in the string are percent-escaped in the result.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url("http://user@example.com").set_password( "pass" ).encoded_userinfo() == "user:pass" );
this->has_password() == true && this->password() == s
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the password.
url&
set_encoded_password(pct_string_view s);
This function sets the password in the userinfo to the string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url("http://user@example.com").set_encoded_password( "pass" ).encoded_userinfo() == "user:pass" );
this->has_password() == true
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Remove the password
url&
remove_password() noexcept;
This function removes the password from the userinfo if a password exists. If there is no userinfo or no authority, the call has no effect.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://user:pass@example.com" ).remove_password().authority().buffer() == "user@example.com" );
this->has_password() == false && this->encoded_password().empty() == true
Linear in `this->size()`.
Throws nothing.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the host
url&
set_host(core::string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host
url&
set_encoded_host(pct_string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
url&
set_host_address(core::string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host_address( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `s.size()`.
Strong guarantee. Calls to allocate may throw.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
url&
set_encoded_host_address(pct_string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
url&
set_host_ipv4(ipv4_address const& addr);
The host is set to the specified IPv4 address. The host type is host_type::ipv4 .
assert( url("http://www.example.com").set_host_ipv4( ipv4_address( "127.0.0.1" ) ).buffer() == "http://127.0.0.1" );
Linear in `this->size()`.
this->has_authority() == true && this->host_ipv4_address() == addr && this->host_type() == host_type::ipv4
Strong guarantee. Calls to allocate may throw.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
Set the host to an address
url&
set_host_ipv6(ipv6_address const& addr);
The host is set to the specified IPv6 address. The host type is host_type::ipv6 .
assert( url().set_host_ipv6( ipv6_address( "1::6:c0a8:1" ) ).authority().buffer() == "[1::6:c0a8:1]" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::ipv6
Linear in `this->size()`.
Strong guarantee. Calls to allocate may throw.
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
Set the host to an address
url&
set_host_ipvfuture(core::string_view s);
The host is set to the specified IPvFuture string. The host type is host_type::ipvfuture .
assert( url().set_host_ipvfuture( "v42.bis" ).buffer() == "//[v42.bis]" );
Linear in `this->size() + s.size()`.
this->has_authority() == true && this->host_ipvfuture) == s && this->host_type() == host_type::ipvfuture
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
Set the host to a name
url&
set_host_name(core::string_view s);
The host is set to the specified string, which may be empty. Reserved characters in the string are percent-escaped in the result. The host type is host_type::name .
assert( url( "http://www.example.com/index.htm").set_host_name( "localhost" ).host_address() == "localhost" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
Strong guarantee. Calls to allocate may throw.
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to a name
url&
set_encoded_host_name(pct_string_view s);
The host is set to the specified string, which may contain percent-escapes and can be empty. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result. The host type is host_type::name .
assert( url( "http://www.example.com/index.htm").set_encoded_host_name( "localhost" ).host_address() == "localhost" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the port
url&
set_port_number(std::uint16_t n);
The port is set to the specified integer.
assert( url( "http://www.example.com" ).set_port_number( 8080 ).authority().buffer() == "www.example.com:8080" );
this->has_authority() == true && this->has_port() == true && this->port_number() == n
Linear in `this->size()`.
Strong guarantee. Calls to allocate may throw.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Set the port
url&
set_port(core::string_view s);
This port is set to the string, which must contain only digits or be empty. An empty port string is distinct from having no port.
assert( url( "http://www.example.com" ).set_port( "8080" ).authority().buffer() == "www.example.com:8080" );
this->has_port() == true && this->port_number() == n && this->port() == std::to_string(n)
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
port = *DIGIT
Remove the port
url&
remove_port() noexcept;
If a port exists, it is removed. The rest of the authority is unchanged.
assert( url( "http://www.example.com:80" ).remove_port().authority().buffer() == "www.example.com" );
this->has_port() == false && this->port_number() == 0 && this->port() == ""
Linear in `this->size()`.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Set the path.
url&
set_path(core::string_view s);
This function sets the path to the string, which may be empty. Reserved characters in the string are percent-escaped in the result.
The library may adjust the final result to ensure that no other parts of the url is semantically affected.
This function does not encode '/' chars, which are unreserved for paths but reserved for path segments. If a path segment should include encoded '/'s to differentiate it from path separators, the functions set_encoded_path or segments should be used instead.
url u( "http://www.example.com" );
u.set_path( "path/to/file.txt" );
assert( u.path() == "/path/to/file.txt" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Set the path.
url&
set_encoded_path(pct_string_view s);
This function sets the path to the string, which may contain percent-escapes and can be empty. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
The library may adjust the final result to ensure that no other parts of the url is semantically affected.
url u( "http://www.example.com" );
u.set_encoded_path( "path/to/file.txt" );
assert( u.encoded_path() == "/path/to/file.txt" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Set the query
url&
set_query(core::string_view s);
This sets the query to the string, which can be empty. An empty query is distinct from having no query. Reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_query( "id=42" ).query() == "id=42" );
this->has_query() == true && this->query() == s
Strong guarantee. Calls to allocate may throw.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Set the query
url&
set_encoded_query(pct_string_view s);
This sets the query to the string, which may contain percent-escapes and can be empty. An empty query is distinct from having no query. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_encoded_query( "id=42" ).encoded_query() == "id=42" );
this->has_query() == true && this->query() == decode_view( s );
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Set the query params
url&
set_params(std::initializer_list ps);
This sets the query params to the list of param_view, which can be empty.
An empty list of params is distinct from having no params.
Reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_params( {"id", "42"} ).query() == "id=42" );
this->has_query() == true
Strong guarantee. Calls to allocate may throw.
Linear.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Set the query params
url&
set_encoded_params(std::initializer_list ps);
This sets the query params to the elements in the list, which may contain percent-escapes and can be empty.
An empty list of params is distinct from having no query.
Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_encoded_params( {"id", "42"} ).encoded_query() == "id=42" );
this->has_query() == true
Linear.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Remove the query
url&
remove_query() noexcept;
If a query is present, it is removed. An empty query is distinct from having no query.
assert( url( "http://www.example.com?id=42" ).remove_query().buffer() == "http://www.example.com" );
this->has_query() == false && this->params().empty()
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Remove the fragment
url&
remove_fragment() noexcept;
This function removes the fragment. An empty fragment is distinct from having no fragment.
assert( url( "?first=john&last=doe#anchor" ).remove_fragment().buffer() == "?first=john&last=doe" );
this->has_fragment() == false && this->encoded_fragment() == ""
Constant.
Throws nothing.
fragment = *( pchar / "/" / "?" )
Set the fragment.
url&
set_fragment(core::string_view s);
This function sets the fragment to the specified string, which may be empty. An empty fragment is distinct from having no fragment. Reserved characters in the string are percent-escaped in the result.
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john doe" ).encoded_fragment() == "john%20doe" );
this->has_fragment() == true && this->fragment() == s
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
fragment = *( pchar / "/" / "?" )
Set the fragment.
url&
set_encoded_fragment(pct_string_view s);
This function sets the fragment to the specified string, which may contain percent-escapes and which may be empty. An empty fragment is distinct from having no fragment. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john%2Ddoe" ).fragment() == "john-doe" );
this->has_fragment() == true && this->fragment() == decode_view( s )
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
fragment = *( pchar / "/" / "?" )
Remove the origin component
url&
remove_origin();
This function removes the origin, which consists of the scheme and authority.
assert( url( "http://www.example.com/index.htm" ).remove_origin().buffer() == "/index.htm" );
this->scheme_id() == scheme::none && this->has_authority() == false
Linear in `this->size()`.
Throws nothing.
Normalize the URL components
url&
normalize();
Applies Syntax-based normalization to all components of the URL.
Strong guarantee. Calls to allocate may throw.
Normalize the URL scheme
url&
normalize_scheme();
Applies Syntax-based normalization to the URL scheme.
The scheme is normalized to lowercase.
Strong guarantee. Calls to allocate may throw.
Normalize the URL authority
url&
normalize_authority();
Applies Syntax-based normalization to the URL authority.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Normalize the URL path
url&
normalize_path();
Applies Syntax-based normalization to the URL path.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded. Redundant path-segments are removed.
Strong guarantee. Calls to allocate may throw.
Normalize the URL query
url&
normalize_query();
Applies Syntax-based normalization to the URL query.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Normalize the URL fragment
url&
normalize_fragment();
Applies Syntax-based normalization to the URL fragment.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Swap
void
swap(
url& v0,
url& v1) noexcept;
Exchanges the contents of `v0` with another `v1`. All views, iterators and references remain valid.
If `&v0 ==&v1`, this function call has no effect.
url u1( "https://www.example.com" );
url u2( "https://www.boost.org" );
std::swap(u1, u2);
assert(u1 == "https://www.boost.org" );
assert(u2 == "https://www.example.com" );
v0.swap( v1 );
Constant
Throws nothing
struct ipv4_address_rule_t;
using value_type = ipv4_address;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
ipv4_address_rule_t const ipv4_address_rule = {};
struct ipv6_address_rule_t;
using value_type = ipv6_address;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
ipv6_address_rule_t const ipv6_address_rule = {};
Return a reference to a parsed URL string
system::result
parse_absolute_uri(core::string_view s);
This function parses a string according to the grammar below and returns a view referencing the passed string upon success, else returns an error. Ownership of the string is not transferred; the caller is responsible for ensuring that the lifetime of the character buffer extends until the view is no longer being accessed.
system::result< url_view > rv = parse_absolute_uri( "http://example.com/index.htm?id=1" );
absolute-URI = scheme ":" hier-part [ "?" query ]
hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty
Return a reference to a parsed URL string
system::result
parse_origin_form(core::string_view s);
This function parses a string according to the grammar below and returns a view referencing the passed string upon success, else returns an error. Ownership of the string is not transferred; the caller is responsible for ensuring that the lifetime of the character buffer extends until the view is no longer being accessed.
system::result< url_view > = parse_origin_form( "/index.htm?layout=mobile" );
origin-form = absolute-path [ "?" query ]
absolute-path = 1*( "/" segment )
Return a reference to a parsed URL string
system::result
parse_relative_ref(core::string_view s);
This function parses a string according to the grammar below and returns a view referencing the passed string upon success, else returns an error. Ownership of the string is not transferred; the caller is responsible for ensuring that the lifetime of the character buffer extends until the view is no longer being accessed.
system::result< url_view > = parse_relative_ref( "images/dot.gif?v=hide#a" );
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-abempty
/ path-empty
Return a reference to a parsed URL string
system::result
parse_uri(core::string_view s);
This function parses a string according to the grammar below and returns a view referencing the passed string upon success, else returns an error. Ownership of the string is not transferred; the caller is responsible for ensuring that the lifetime of the character buffer extends until the view is no longer being accessed.
system::result< url_view > = parse_uri( "https://www.example.com/index.htm?id=guest#s1" );
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty
Return a reference to a parsed URL string
system::result
parse_uri_reference(core::string_view s);
This function parses a string according to the grammar below and returns a view referencing the passed string upon success, else returns an error. Ownership of the string is not transferred; the caller is responsible for ensuring that the lifetime of the character buffer extends until the view is no longer being accessed.
system::result< url_view > = parse_uri_reference( "ws://echo.example.com/?name=boost#demo" );
URI-reference = URI / relative-ref
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-abempty
/ path-empty
struct absolute_uri_rule_t;
using value_type = url_view;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
absolute_uri_rule_t const absolute_uri_rule = {};
struct relative_ref_rule_t;
using value_type = url_view;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
relative_ref_rule_t const relative_ref_rule = {};
struct uri_rule_t;
using value_type = url_view;
system::result
parse(
char const*& it,
char const const* end) const noexcept;
constexpr
uri_rule_t const uri_rule = {};
struct uri_reference_rule_t;
using value_type = url_view;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
uri_reference_rule_t const uri_reference_rule = {};
struct origin_form_rule_t;
using value_type = url_view;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
origin_form_rule_t const origin_form_rule = {};
struct query_rule_t;
using value_type = params_encoded_view;
system::result
parse(
char const*& it,
char const* end) const noexcept;
constexpr
query_rule_t const query_rule = {};
A modifiable container for a URL.
template
class static_url
: public static_url_base;
This container owns a url, represented by an inline, null-terminated character buffer with fixed capacity. The contents may be inspected and modified, and the implementation maintains a useful invariant: changes to the url always leave it in a valid state.
static_url< 1024 > u( "https://www.example.com" );
this->capacity() == Capacity + 1
Destructor
virtual
~static_url() = default;
Any params, segments, iterators, or views which reference this object are invalidated. The underlying character buffer is destroyed, invalidating all references to it.
Constructor
static_url() noexcept;
» more...
Constructor
static_url(core::string_view s);
» more...
Constructor
static_url(static_url const& u) noexcept;
» more...
Constructor
static_url(url_view_base const& u);
» more...
Assignment
static_url&
operator=(static_url const& u) noexcept;
» more...
Assignment
static_url&
operator=(url_view_base const& u);
» more...
Set the scheme
static_url&
set_scheme(core::string_view s);
The scheme is set to the specified string, which must contain a valid scheme without any trailing colon (':'). Note that schemes are case-insensitive, and the canonical form is lowercased.
assert( url( "http://www.example.com" ).set_scheme( "https" ).scheme_id() == scheme::https );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
url_base::set_scheme_id
static_url&
set_scheme_id(scheme id);
Remove the scheme
static_url&
remove_scheme();
This function removes the scheme if it is present.
assert( url("http://www.example.com/index.htm" ).remove_scheme().buffer() == "//www.example.com/index.htm" );
this->has_scheme() == false && this->scheme_id() == scheme::none
Linear in `this->size()`.
Throws nothing.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Set the authority
static_url&
set_encoded_authority(pct_string_view s);
This function sets the authority to the specified string. The string may contain percent-escapes.
assert( url().set_encoded_authority( "My%20Computer" ).has_authority() );
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Remove the authority
static_url&
remove_authority();
This function removes the authority, which includes the userinfo, host, and a port if present.
assert( url( "http://example.com/echo.cgi" ).remove_authority().buffer() == "http:/echo.cgi" );
this->has_authority() == false && this->has_userinfo() == false && this->has_port() == false
Linear in `this->size()`.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Set the userinfo
static_url&
set_userinfo(core::string_view s);
The userinfo is set to the given string, which may contain percent-escapes. Any special or reserved characters in the string are automatically percent-encoded. The effects on the user and password depend on the presence of a colon (':') in the string:
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://example.com" ).set_userinfo( "user:pass" ).encoded_user() == "user" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the userinfo.
static_url&
set_encoded_userinfo(pct_string_view s);
The userinfo is set to the given string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result. The effects on the user and password depend on the presence of a colon (':') in the string:
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://example.com" ).set_encoded_userinfo( "john%20doe" ).user() == "john doe" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Remove the userinfo
static_url&
remove_userinfo() noexcept;
This function removes the userinfo if present, without removing any authority.
assert( url( "http://user@example.com" ).remove_userinfo().has_userinfo() == false );
this->has_userinfo() == false && this->encoded_userinfo().empty == true
Linear in `this->size()`.
Throws nothing.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the user
static_url&
set_user(core::string_view s);
This function sets the user part of the userinfo to the string. Any special or reserved characters in the string are automatically percent-encoded.
assert( url().set_user("john doe").encoded_userinfo() == "john%20doe" );
this->has_authority() == true && this->has_userinfo() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the user
static_url&
set_encoded_user(pct_string_view s);
This function sets the user part of the userinfo the the string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url().set_encoded_user("john%20doe").userinfo() == "john doe" );
this->has_authority() == true && this->has_userinfo() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the password.
static_url&
set_password(core::string_view s);
This function sets the password in the userinfo to the string. Reserved characters in the string are percent-escaped in the result.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url("http://user@example.com").set_password( "pass" ).encoded_userinfo() == "user:pass" );
this->has_password() == true && this->password() == s
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the password.
static_url&
set_encoded_password(pct_string_view s);
This function sets the password in the userinfo to the string, which may contain percent-escapes. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url("http://user@example.com").set_encoded_password( "pass" ).encoded_userinfo() == "user:pass" );
this->has_password() == true
Strong guarantee. Calls to allocate may throw.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Remove the password
static_url&
remove_password() noexcept;
This function removes the password from the userinfo if a password exists. If there is no userinfo or no authority, the call has no effect.
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
assert( url( "http://user:pass@example.com" ).remove_password().authority().buffer() == "user@example.com" );
this->has_password() == false && this->encoded_password().empty() == true
Linear in `this->size()`.
Throws nothing.
userinfo = [ [ user ] [ ':' password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
Set the host
static_url&
set_host(core::string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host
static_url&
set_encoded_host(pct_string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
static_url&
set_host_address(core::string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host_address( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `s.size()`.
Strong guarantee. Calls to allocate may throw.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
static_url&
set_encoded_host_address(pct_string_view s);
Depending on the contents of the passed string, this function sets the host:
In all cases, when this function returns, the URL contains an authority.
assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
this->has_authority() == true
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to an address
static_url&
set_host_ipv4(ipv4_address const& addr);
The host is set to the specified IPv4 address. The host type is host_type::ipv4 .
assert( url("http://www.example.com").set_host_ipv4( ipv4_address( "127.0.0.1" ) ).buffer() == "http://127.0.0.1" );
Linear in `this->size()`.
this->has_authority() == true && this->host_ipv4_address() == addr && this->host_type() == host_type::ipv4
Strong guarantee. Calls to allocate may throw.
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
Set the host to an address
static_url&
set_host_ipv6(ipv6_address const& addr);
The host is set to the specified IPv6 address. The host type is host_type::ipv6 .
assert( url().set_host_ipv6( ipv6_address( "1::6:c0a8:1" ) ).authority().buffer() == "[1::6:c0a8:1]" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::ipv6
Linear in `this->size()`.
Strong guarantee. Calls to allocate may throw.
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
Set the host to an address
static_url&
set_host_ipvfuture(core::string_view s);
The host is set to the specified IPvFuture string. The host type is host_type::ipvfuture .
assert( url().set_host_ipvfuture( "v42.bis" ).buffer() == "//[v42.bis]" );
Linear in `this->size() + s.size()`.
this->has_authority() == true && this->host_ipvfuture) == s && this->host_type() == host_type::ipvfuture
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
Set the host to a name
static_url&
set_host_name(core::string_view s);
The host is set to the specified string, which may be empty. Reserved characters in the string are percent-escaped in the result. The host type is host_type::name .
assert( url( "http://www.example.com/index.htm").set_host_name( "localhost" ).host_address() == "localhost" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
Strong guarantee. Calls to allocate may throw.
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the host to a name
static_url&
set_encoded_host_name(pct_string_view s);
The host is set to the specified string, which may contain percent-escapes and can be empty. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result. The host type is host_type::name .
assert( url( "http://www.example.com/index.htm").set_encoded_host_name( "localhost" ).host_address() == "localhost" );
this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
reg-name = *( unreserved / pct-encoded / "-" / ".")
Set the port
static_url&
set_port_number(std::uint16_t n);
The port is set to the specified integer.
assert( url( "http://www.example.com" ).set_port_number( 8080 ).authority().buffer() == "www.example.com:8080" );
this->has_authority() == true && this->has_port() == true && this->port_number() == n
Linear in `this->size()`.
Strong guarantee. Calls to allocate may throw.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Set the port
static_url&
set_port(core::string_view s);
This port is set to the string, which must contain only digits or be empty. An empty port string is distinct from having no port.
assert( url( "http://www.example.com" ).set_port( "8080" ).authority().buffer() == "www.example.com:8080" );
this->has_port() == true && this->port_number() == n && this->port() == std::to_string(n)
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
port = *DIGIT
Remove the port
static_url&
remove_port() noexcept;
If a port exists, it is removed. The rest of the authority is unchanged.
assert( url( "http://www.example.com:80" ).remove_port().authority().buffer() == "www.example.com" );
this->has_port() == false && this->port_number() == 0 && this->port() == ""
Linear in `this->size()`.
Throws nothing.
authority = [ userinfo "@" ] host [ ":" port ]
port = *DIGIT
Set the path.
static_url&
set_path(core::string_view s);
This function sets the path to the string, which may be empty. Reserved characters in the string are percent-escaped in the result.
The library may adjust the final result to ensure that no other parts of the url is semantically affected.
This function does not encode '/' chars, which are unreserved for paths but reserved for path segments. If a path segment should include encoded '/'s to differentiate it from path separators, the functions set_encoded_path or segments should be used instead.
url u( "http://www.example.com" );
u.set_path( "path/to/file.txt" );
assert( u.path() == "/path/to/file.txt" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Set the path.
static_url&
set_encoded_path(pct_string_view s);
This function sets the path to the string, which may contain percent-escapes and can be empty. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
The library may adjust the final result to ensure that no other parts of the url is semantically affected.
url u( "http://www.example.com" );
u.set_encoded_path( "path/to/file.txt" );
assert( u.encoded_path() == "/path/to/file.txt" );
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Set the query
static_url&
set_query(core::string_view s);
This sets the query to the string, which can be empty. An empty query is distinct from having no query. Reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_query( "id=42" ).query() == "id=42" );
this->has_query() == true && this->query() == s
Strong guarantee. Calls to allocate may throw.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Set the query
static_url&
set_encoded_query(pct_string_view s);
This sets the query to the string, which may contain percent-escapes and can be empty. An empty query is distinct from having no query. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url( "http://example.com" ).set_encoded_query( "id=42" ).encoded_query() == "id=42" );
this->has_query() == true && this->query() == decode_view( s );
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Remove the query
static_url&
remove_query() noexcept;
If a query is present, it is removed. An empty query is distinct from having no query.
assert( url( "http://www.example.com?id=42" ).remove_query().buffer() == "http://www.example.com" );
this->has_query() == false && this->params().empty()
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Remove the fragment
static_url&
remove_fragment() noexcept;
This function removes the fragment. An empty fragment is distinct from having no fragment.
assert( url( "?first=john&last=doe#anchor" ).remove_fragment().buffer() == "?first=john&last=doe" );
this->has_fragment() == false && this->encoded_fragment() == ""
Constant.
Throws nothing.
fragment = *( pchar / "/" / "?" )
Set the fragment.
static_url&
set_fragment(core::string_view s);
This function sets the fragment to the specified string, which may be empty. An empty fragment is distinct from having no fragment. Reserved characters in the string are percent-escaped in the result.
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john doe" ).encoded_fragment() == "john%20doe" );
this->has_fragment() == true && this->fragment() == s
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw.
fragment = *( pchar / "/" / "?" )
Set the fragment.
static_url&
set_encoded_fragment(pct_string_view s);
This function sets the fragment to the specified string, which may contain percent-escapes and which may be empty. An empty fragment is distinct from having no fragment. Escapes in the string are preserved, and reserved characters in the string are percent-escaped in the result.
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john%2Ddoe" ).fragment() == "john-doe" );
this->has_fragment() == true && this->fragment() == decode_view( s )
Linear in `this->size() + s.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
fragment = *( pchar / "/" / "?" )
Remove the origin component
static_url&
remove_origin();
This function removes the origin, which consists of the scheme and authority.
assert( url( "http://www.example.com/index.htm" ).remove_origin().buffer() == "/index.htm" );
this->scheme_id() == scheme::none && this->has_authority() == false
Linear in `this->size()`.
Throws nothing.
Normalize the URL components
static_url&
normalize();
Applies Syntax-based normalization to all components of the URL.
Strong guarantee. Calls to allocate may throw.
Normalize the URL scheme
static_url&
normalize_scheme();
Applies Syntax-based normalization to the URL scheme.
The scheme is normalized to lowercase.
Strong guarantee. Calls to allocate may throw.
Normalize the URL authority
static_url&
normalize_authority();
Applies Syntax-based normalization to the URL authority.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Normalize the URL path
static_url&
normalize_path();
Applies Syntax-based normalization to the URL path.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded. Redundant path-segments are removed.
Strong guarantee. Calls to allocate may throw.
Normalize the URL query
static_url&
normalize_query();
Applies Syntax-based normalization to the URL query.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Normalize the URL fragment
static_url&
normalize_fragment();
Applies Syntax-based normalization to the URL fragment.
Percent-encoding triplets are normalized to uppercase letters. Percent-encoded octets that correspond to unreserved characters are decoded.
Strong guarantee. Calls to allocate may throw.
Common implementation for all static URLs
class static_url_base
: public url_base;
This base class is used by the library to provide common functionality for static URLs. Users should not use this class directly. Instead, construct an instance of one of the containers or call a parsing function.
The type of string_view used by the library
using string_view = core::string_view;
String views are used to pass character buffers into or out of functions. Ownership of the underlying character buffer is not transferred; the caller is responsible for ensuring that the lifetime of character buffer extends until it is no longer referenced.
This alias is no longer supported and should not be used in new code. Please use `core::string_view` instead.
This alias is included for backwards compatibility with earlier versions of the library.
However, it will be removed in future releases, and using it in new code is not recommended.
Please use the updated version instead to ensure compatibility with future versions of the library.
Format arguments into a URL
template
url
format(
core::string_view fmt,
Args&&... args);
» more...
Format arguments into a URL
url
format(
core::string_view fmt,
std::initializer_list args);
» more...
Format arguments into a URL
template
void
format_to(
url_base& u,
core::string_view fmt,
Args&&... args);
» more...
Format arguments into a URL
void
format_to(
url_base& u,
core::string_view fmt,
std::initializer_list args);
» more...
template
detail::named_arg
arg(
core::string_view name,
T const& arg);
The gen-delims character set
constexpr
grammar::lut_chars const gen_delim_chars = ":/?#[]@";
Character sets are used with rules and the functions grammar::find_if and grammar::find_if_not .
system::result< decode_view > rv = grammar::parse( "Program%20Files", pct_encoded_rule( gen_delim_chars ) );
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
The reserved character set
constexpr
lut_chars const reserved_chars = ~unreserved_chars;
Character sets are used with rules and the functions grammar::find_if and grammar::find_if_not .
system::result< decode_view > rv = grammar::parse( "Program%20Files", pct_encoded_rule( reserved_chars ) );
template<>
struct is_error_code_enum;
static
bool const value = true;
template<>
struct is_error_code_enum;
static
bool const value = true;
template<>
struct is_error_condition_enum;
static
bool const value = true;
using urls::url
;
| Name |
|---|
using urls::url_view
;
| Name |
|---|
template<>
struct hash;
constexpr
hash() = default;
» more...
constexpr
hash(hash const&) = default;
» more...
hash(size_t salt) noexcept;
» more...
constexpr
hash&
operator=(hash const&) = default;
size_t
operator()(boost::urls::url const& u) const noexcept;
template<>
struct hash;
constexpr
hash() = default;
» more...
constexpr
hash(hash const&) = default;
» more...
hash(size_t salt) noexcept;
» more...
constexpr
hash&
operator=(hash const&) = default;
size_t
operator()(boost::urls::url_view const& u) const noexcept;
template
struct hash>;
hash() = default;
» more...
hash(hash const&) = default;
» more...
hash(size_t salt) noexcept;
» more...
hash&
operator=(hash const&) = default;
size_t
operator()(boost::urls::static_url const& u) const noexcept;
constexpr
arg() = default;
constexpr
arg(arg&&) = default;
arg(arg const&) = delete;
arg&
operator=(arg&&) = delete;
arg&
operator=(arg const&) = delete;
Return true if a matching prefix exists
constexpr
bool
starts_with(core::string_view x) const noexcept;
See `core::string_view::starts_with`
Return true if a matching prefix exists
constexpr
bool
starts_with(char x) const noexcept;
See `core::string_view::starts_with`
Return true if a matching prefix exists
constexpr
bool
starts_with(char const* x) const noexcept;
See `core::string_view::starts_with`
Return true if a matching suffix exists
constexpr
bool
ends_with(core::string_view x) const noexcept;
See `core::string_view::ends_with`
Return true if a matching suffix exists
constexpr
bool
ends_with(char x) const noexcept;
See `core::string_view::ends_with`
Return true if a matching suffix exists
constexpr
bool
ends_with(char const* x) const noexcept;
See `core::string_view::ends_with`
Return the position of matching characters
constexpr
size_type
find(
core::string_view str,
size_type pos = 0) const noexcept;
See `core::string_view::find`
Return the position of matching characters
constexpr
size_type
find(
char c,
size_type pos = 0) const noexcept;
See `core::string_view::find`
Return the position of matching characters
constexpr
size_type
find(
char const* s,
size_type pos,
size_type n) const noexcept;
See `core::string_view::find`
Return the position of matching characters
constexpr
size_type
find(
char const* s,
size_type pos = 0) const noexcept;
See `core::string_view::find`
Return the position of matching characters
constexpr
size_type
rfind(
core::string_view str,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::rfind`
Return the position of matching characters
constexpr
size_type
rfind(
char c,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::rfind`
Return the position of matching characters
constexpr
size_type
rfind(
char const* s,
size_type pos,
size_type n) const noexcept;
See `core::string_view::rfind`
Return the position of matching characters
constexpr
size_type
rfind(
char const* s,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::rfind`
Return the result of comparing to another string
constexpr
int
compare(core::string_view str) const noexcept;
See `core::string_view::compare`
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
core::string_view str) const;
See `core::string_view::compare`
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
core::string_view str,
size_type pos2,
size_type n2) const;
See `core::string_view::compare`
Return the result of comparing to another string
constexpr
int
compare(char const* s) const noexcept;
See `core::string_view::compare`
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
char const* s) const;
See `core::string_view::compare`
Return the result of comparing to another string
constexpr
int
compare(
size_type pos1,
size_type n1,
char const* s,
size_type n2) const;
See `core::string_view::compare`
Return the position of the first match
constexpr
size_type
find_first_of(
core::string_view str,
size_type pos = 0) const noexcept;
See `core::string_view::find_first_of`
Return the position of the first match
constexpr
size_type
find_first_of(
char c,
size_type pos = 0) const noexcept;
See `core::string_view::find_first_of`
Return the position of the first match
constexpr
size_type
find_first_of(
char const* s,
size_type pos,
size_type n) const noexcept;
See `core::string_view::find_first_of`
Return the position of the first match
constexpr
size_type
find_first_of(
char const* s,
size_type pos = 0) const noexcept;
See `core::string_view::find_first_of`
Return the position of the last match
constexpr
size_type
find_last_of(
core::string_view str,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::find_last_of`
Return the position of the last match
constexpr
size_type
find_last_of(
char c,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::find_last_of`
Return the position of the last match
constexpr
size_type
find_last_of(
char const* s,
size_type pos,
size_type n) const noexcept;
See `core::string_view::find_last_of`
Return the position of the last match
constexpr
size_type
find_last_of(
char const* s,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::find_last_of`
Return true if matching characters are found
constexpr
bool
contains(core::string_view sv) const noexcept;
See `core::string_view::contains`
Return true if matching characters are found
constexpr
bool
contains(char c) const noexcept;
See `core::string_view::contains`
Return true if matching characters are found
constexpr
bool
contains(char const* s) const noexcept;
See `core::string_view::contains`
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
core::string_view str,
size_type pos = 0) const noexcept;
See `core::string_view::find_first_not_of`
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
char c,
size_type pos = 0) const noexcept;
See `core::string_view::find_first_not_of`
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
char const* s,
size_type pos,
size_type n) const noexcept;
See `core::string_view::find_first_not_of`
Return the position of the first non-match
constexpr
size_type
find_first_not_of(
char const* s,
size_type pos = 0) const noexcept;
See `core::string_view::find_first_not_of`
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
core::string_view str,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::find_last_not_of`
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
char c,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::find_last_not_of`
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
char const* s,
size_type pos,
size_type n) const noexcept;
See `core::string_view::find_last_not_of`
Return the position of the last non-match
constexpr
size_type
find_last_not_of(
char const* s,
size_type pos = core::string_view::npos) const noexcept;
See `core::string_view::find_last_not_of`
Return true if ch is in the character set.
constexpr
bool
operator()(unsigned char ch) const noexcept;
This function returns true if the character `ch` is in the set, otherwise it returns false.
Constant.
Throws nothing.
Return true if ch is in the character set.
constexpr
bool
operator()(char ch) const noexcept;
This function returns true if the character `ch` is in the set, otherwise it returns false.
Constant.
Throws nothing.
Constructor
constexpr
lut_chars(char ch) noexcept;
This function constructs a character set which has as a single member, the character `ch`.
constexpr lut_chars asterisk( '*' );
Constant.
Throws nothing.
Constructor
constexpr
lut_chars(char const* s) noexcept;
This function constructs a character set which has as members, all of the characters present in the null-terminated string `s`.
constexpr lut_chars digits = "0123456789";
Linear in `::strlen(s)`, or constant if `s` is a constant expression.
Throws nothing.
template<
class Pred,
class = void>
constexpr
lut_chars(Pred const& pred) noexcept;
template
constexpr
detail::charset_ref
ref(CharSet const& cs) noexcept;
template
constexpr
detail::rule_ref
ref(Rule const& r) noexcept;
constexpr
void
ref() = delete;
Parse a character buffer using a rule
template
system::result
parse(
char const*& it,
char const* end,
Rule const& r);
Parse a character buffer using a rule
template
system::result
parse(
core::string_view s,
Rule const& r);
This function parses a complete string into the specified sequence of rules. If the string is not completely consumed, an error is returned instead.
template<
class String0,
class String1>
bool
ci_is_equal(
String0 const& s0,
String1 const& s1);
bool
ci_is_equal(
core::string_view s0,
core::string_view s1) noexcept;
template<
class R0_,
class... Rn_>
constexpr
variant_rule_t
variant_rule(
R0_ const& r0,
Rn_ const&... rn) noexcept;
template<
class R0,
class... Rn>
constexpr
variant_rule_t
variant_rule(
R0 const& r0,
Rn const&... rn) noexcept;
constexpr
ch_delim_rule
delim_rule(char ch) noexcept;
template
constexpr
cs_delim_rule
delim_rule(CharSet const& cs) noexcept;
template
constexpr
optional_rule_t
optional_rule(R_ const& r);
template
constexpr
optional_rule_t
optional_rule(Rule const& r);
template<
class R0_,
class... Rn_>
constexpr
tuple_rule_t
tuple_rule(
R0_ const& r0,
Rn_ const&... rn) noexcept;
template<
class R0,
class... Rn>
constexpr
tuple_rule_t
tuple_rule(
R0 const& r0,
Rn const&... rn) noexcept;
Assignment
recycled_ptr&
operator=(recycled_ptr&& other) noexcept;
If `other` references an object, ownership is transferred including a reference to the recycle bin. After the move, the moved-from object is empty.
this->release()
&this->bin() == &other->bin()
Throws nothing.
Assignment
recycled_ptr&
operator=(recycled_ptr const& other) noexcept;
If `other` references an object, this acquires shared ownership and references the same recycle bin as `other`. The previous object if any is released.
this->release()
&this->bin() == &other->bin() && this->get() == other.get()
Throws nothing.
Constructor
recycled_ptr(recycled& bin);
Upon construction, this acquires exclusive access to an object of type `T` which is either recycled from the specified bin, or newly allocated. The object is in an unknown but valid state.
static recycled< std::string > bin;
recycled_ptr< std::string > ps( bin );
// Put the string into a known state
ps->clear();
&this->bin() == &bin && ! this->empty()
Constructor
recycled_ptr(
recycled& bin,
std::nullptr_t) noexcept;
After construction, this is empty and refers to the specified recycle bin.
static recycled< std::string > bin;
recycled_ptr< std::string > ps( bin, nullptr );
// Acquire a string and put it into a known state
ps->acquire();
ps->clear();
&this->bin() == &bin && this->empty()
Throws nothing.
Constructor
recycled_ptr();
Upon construction, this acquires exclusive access to an object of type `T` which is either recycled from a global recycle bin, or newly allocated. The object is in an unknown but valid state.
recycled_ptr< std::string > ps;
// Put the string into a known state
ps->clear();
&this->bin() != nullptr && ! this->empty()
Constructor
recycled_ptr(std::nullptr_t) noexcept;
After construction, this is empty and refers to a global recycle bin.
recycled_ptr< std::string > ps( nullptr );
// Acquire a string and put it into a known state
ps->acquire();
ps->clear();
&this->bin() != nullptr && this->empty()
Throws nothing.
Constructor
recycled_ptr(recycled_ptr const& other) noexcept;
If `other` references an object, the newly constructed pointer acquires shared ownership. Otherwise this is empty. The new pointer references the same recycle bin as `other`.
&this->bin() == &other->bin() && this->get() == other.get()
Throws nothing.
Constructor
recycled_ptr(recycled_ptr&& other) noexcept;
If `other` references an object, ownership is transferred including a reference to the recycle bin. After the move, the moved-from object is empty.
&this->bin() == &other->bin() && ! this->empty() && other.empty()
Throws nothing.
Constructor
range() noexcept;
Default-constructed ranges have zero elements.
Throws nothing.
Constructor
range(range&& other) noexcept;
The new range references the same underlying character buffer. Ownership is not transferred; the caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced. The moved-from object becomes as if default-constructed.
Throws nothing.
Constructor
range(range const& other) noexcept;
The copy references the same underlying character buffer. Ownership is not transferred; the caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
Throws nothing.
Assignment
range&
operator=(range&& other) noexcept;
After the move, this references the same underlying character buffer. Ownership is not transferred; the caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced. The moved-from object becomes as if default-constructed.
Throws nothing.
Assignment
range&
operator=(range const& other) noexcept;
The copy references the same underlying character buffer. Ownership is not transferred; the caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
Throws nothing.
template
constexpr
range_rule_t
range_rule(
Rule const& next,
std::size_t N = 0,
std::size_t M = std::size_t(-1)) noexcept;
template<
class Rule1,
class Rule2>
constexpr
range_rule_t
range_rule(
Rule1 const& first,
Rule2 const& next,
std::size_t N = 0,
std::size_t M = std::size_t(-1)) noexcept;
template
constexpr
not_empty_rule_t
not_empty_rule(R_ const& r);
template
constexpr
not_empty_rule_t
not_empty_rule(Rule const& r);
constexpr
iterator() = default;
constexpr
iterator(iterator const&) = default;
iterator&
operator++() noexcept;
iterator
operator++(int) noexcept;
iterator&
operator--() noexcept;
iterator
operator--(int) noexcept;
Constructor
constexpr
decode_view() noexcept = default;
Default-constructed views represent empty strings.
decode_view ds;
this->empty() == true
Constant.
Throws nothing.
Constructor
decode_view(
pct_string_view s,
encoding_opts opt = = {}) noexcept;
This constructs a view from the character buffer `s`, which must remain valid and unmodified until the view is no longer accessed.
decode_view ds( "Program%20Files" );
this->encoded() == s
Linear in `s.size()`.
Exceptions thrown on invalid input.
Checks if the string ends with the given prefix
bool
ends_with(core::string_view s) const noexcept;
assert( decode_view( "Program%20Files" ).ends_with("Files") );
Linear.
Throws nothing.
Checks if the string ends with the given prefix
bool
ends_with(char ch) const noexcept;
assert( decode_view( "Program%20Files" ).ends_with('s') );
Constant.
Throws nothing.
Checks if the string begins with the given prefix
bool
starts_with(core::string_view s) const noexcept;
assert( decode_view( "Program%20Files" ).starts_with("Program") );
Linear.
Throws nothing.
Checks if the string begins with the given prefix
bool
starts_with(char ch) const noexcept;
assert( decode_view( "Program%20Files" ).starts_with('P') );
Constant.
Throws nothing.
Return the result of comparing to another string
int
compare(core::string_view other) const noexcept;
The length of the sequences to compare is the smaller of `size()` and `other.size()`.
The function compares the two strings as if by calling
`char_traits
Return the result of comparing to another string
int
compare(decode_view other) const noexcept;
The length of the sequences to compare is the smaller of `size()` and `other.size()`.
The function compares the two strings as if by calling
`char_traits
Constructor
constexpr
pct_string_view() = default;
Default constructed string are empty.
Constant.
Throws nothing.
Constructor
constexpr
pct_string_view(pct_string_view const& other) = default;
The copy references the same underlying character buffer. Ownership is not transferred.
this->data() == other.data()
Constant.
Throws nothing.
template<
class String,
class = void>
pct_string_view(String const& s);
Constructor (deleted)
pct_string_view(std::nullptr_t) = delete;
Constructor
pct_string_view(
char const* s,
std::size_t len);
The newly constructed string references the specified character buffer. Ownership is not transferred.
this->data() == s && this->size() == len
Linear in `len`.
Exceptions thrown on invalid input.
Constructor
pct_string_view(core::string_view s);
The newly constructed string references the specified character buffer. Ownership is not transferred.
this->data() == s.data() && this->size() == s.size()
Linear in `s.size()`.
Exceptions thrown on invalid input.
template<
class S0,
class S1>
constexpr
bool
operator<(
S0 const& s0,
S1 const& s1) noexcept;
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator<(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two URLs
bool
operator<(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.b.com/index.htm" );
assert( u0 < u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) <
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
template<
class S0,
class S1>
constexpr
bool
operator<=(
S0 const& s0,
S1 const& s1) noexcept;
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator<=(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two URLs
bool
operator<=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.b.com/index.htm" );
url_view u1( "http://www.b.com/index.htm" );
assert( u0 <= u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) <=
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
template<
class S0,
class S1>
constexpr
bool
operator==(
S0 const& s0,
S1 const& s1) noexcept;
Return true if two addresses are equal
bool
operator==(
ipv4_address const& a1,
ipv4_address const& a2) noexcept;
Return true if two addresses are equal
bool
operator==(
ipv6_address const& a1,
ipv6_address const& a2) noexcept;
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator==(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
bool
operator==(
iterator const& it0,
iterator const& it1) noexcept;
Return the result of comparing two URLs
bool
operator==(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.a.com/index.htm" );
assert( u0 == u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) ==
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
template<
class S0,
class S1>
constexpr
bool
operator!=(
S0 const& s0,
S1 const& s1) noexcept;
Return true if two addresses are not equal
bool
operator!=(
ipv4_address const& a1,
ipv4_address const& a2) noexcept;
Return true if two addresses are not equal
bool
operator!=(
ipv6_address const& a1,
ipv6_address const& a2) noexcept;
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator!=(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
bool
operator!=(
iterator const& it0,
iterator const& it1) noexcept;
Return the result of comparing two URLs
bool
operator!=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.b.com/index.htm" );
assert( u0 != u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) !=
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
template<
class S0,
class S1>
constexpr
bool
operator>(
S0 const& s0,
S1 const& s1) noexcept;
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator>(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two URLs
bool
operator>(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.b.com/index.htm" );
url_view u1( "http://www.a.com/index.htm" );
assert( u0 > u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) >
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
template<
class S0,
class S1>
constexpr
bool
operator>=(
S0 const& s0,
S1 const& s1) noexcept;
Return the result of comparing two authorities The authorities are compared component by component as if they were first normalized.
bool
operator>=(
authority_view const& a0,
authority_view const& a1) noexcept;
Linear in `min( a0.size(), a1.size() )`
Throws nothing
Return the result of comparing two URLs
bool
operator>=(
url_view_base const& u0,
url_view_base const& u1) noexcept;
The URLs are compared component by component as if they were first normalized.
url_view u0( "http://www.a.com/index.htm" );
url_view u1( "http://www.a.com/index.htm" );
assert( u0 >= u1 );
url a(u0);
a.normalize();
url b(u1);
b.normalize();
return std::make_tuple(
a.scheme(),
a.user(),
a.password(),
a.host(),
a.port(),
a.path(),
a.query(),
a.fragment()) >=
std::make_tuple(
b.scheme(),
b.user(),
b.password(),
b.host(),
b.port(),
b.path(),
b.query(),
b.fragment());
Linear in `min( u0.size(), u1.size() )`
Throws nothing
Apply percent-encoding to a string
template
std::size_t
encode(
char* dest,
std::size_t size,
core::string_view s,
CharSet const& unreserved,
encoding_opts opt = = {});
This function applies percent-encoding to the string using the given options and character set. The destination buffer provided by the caller is used to store the result, which may be truncated if there is insufficient space.
char buf[100];
assert( encode( buf, sizeof(buf), "Program Files", pchars ) == 15 );
Throws nothing.
Return a percent-encoded string
template<
class StringToken = string_token::return_string,
class CharSet>
StringToken::result_type
encode(
core::string_view s,
CharSet const& unreserved,
encoding_opts opt = = {},
StringToken&& token) noexcept;
This function applies percent-encoding to the string using the given options and character set, and returns the result as a string when called with default arguments.
encoding_opts opt;
opt.space_as_plus = true;
std::string s = encode( "My Stuff", opt, pchars );
assert( s == "My+Stuff" );
Calls to allocate may throw.
Constructor
constexpr
param_pct_view() = default;
Default constructed query parameters have an empty key and no value.
param_pct_view qp;
this->key == "" && this->value == "" && this->has_value == false
Constant.
Throws nothing.
Constructor
param_pct_view(
pct_string_view key,
pct_string_view value) noexcept;
This constructs a parameter with a key and value, which may both contain percent escapes. The new key and value reference the same corresponding underlying character buffers. Ownership of the buffers is not transferred; the caller is responsible for ensuring that the assigned buffers remain valid until they are no longer referenced.
param_pct_view qp( "key", "value" );
this->key.data() == key.data() && this->value.data() == value.data() && this->has_value == true
Linear in `key.size() + value.size()`.
Exceptions thrown on invalid input.
Constructor
template
param_pct_view(
pct_string_view key,
OptionalString const& value);
This constructs a parameter with a key and optional value, which may both contain percent escapes.
The new key and value reference the same corresponding underlying character buffers.
Ownership of the buffers is not transferred; the caller is responsible for ensuring that the assigned buffers remain valid until they are no longer referenced.
param_pct_view qp( "key", optional("value") );
this->key.data() == key.data() && this->value->data() == value->data() && this->has_value == true
Linear in `key.size() + value->size()`.
Exceptions thrown on invalid input.
Construction
param_pct_view(param_view const& p);
This converts a param which may contain unvalidated percent-escapes into a param whose key and value are guaranteed to contain strings with no invalid percent-escapes, otherwise an exception is thrown.
The new key and value reference the same corresponding underlying character buffers. Ownership of the buffers is not transferred; the caller is responsible for ensuring that the assigned buffers remain valid until they are no longer referenced.
param_pct_view qp( param_view( "key", "value" ) );
Linear in `key.size() + value.size()`.
Exceptions thrown on invalid input.
param_pct_view(
pct_string_view key,
pct_string_view value,
bool has_value) noexcept;
Constructor
constexpr
param_view() = default;
Default constructed query parameters have an empty key and no value.
param_view qp;
this->key == "" && this->value == "" && this->has_value == false
Constant.
Throws nothing.
Constructor
template
param_view(
core::string_view key,
OptionalString const& value) noexcept;
This constructs a parameter with a key and value. No validation is performed on the strings. The new key and value reference the same corresponding underlying character buffers. Ownership of the buffers is not transferred; the caller is responsible for ensuring that the assigned buffers remain valid until they are no longer referenced.
param_view qp( "key", "value" );
this->key.data() == key.data() && this->value.data() == value.data() && this->has_value == true
Constant.
Throws nothing.
Constructor
param_view(param const& other) noexcept;
This function constructs a param which references the character buffers representing the key and value in another container. Ownership of the buffers is not transferred; the caller is responsible for ensuring that the assigned buffers remain valid until they are no longer referenced.
param qp( "key", "value" );
param_view qpv( qp );
this->key == key && this->value == value && this->has_value == other.has_value
Constant.
Throws nothing.
param_view(
core::string_view key_,
core::string_view value_,
bool has_value_) noexcept;
Format the string with percent-decoding applied to the output stream
std::ostream&
operator<<(
std::ostream& os,
decode_view const& s);
This function serializes the decoded view to the output stream.
Format the address to an output stream.
std::ostream&
operator<<(
std::ostream& os,
ipv4_address const& addr);
IPv4 addresses written to output streams are written in their dotted decimal format.
Format the address to an output stream
std::ostream&
operator<<(
std::ostream& os,
ipv6_address const& addr);
This function writes the address to an output stream using standard notation.
Format the encoded authority to the output stream
std::ostream&
operator<<(
std::ostream& os,
authority_view const& a);
This function serializes the encoded URL to the output stream.
authority_view a( "www.example.com" );
std::cout << a << std::endl;
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
segments_encoded_base const& ps);
Any percent-escapes are emitted as-is; no decoding is performed.
Linear in `ps.buffer().size()`.
return os << ps.buffer();
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
segments_base const& ps);
Any percent-escapes are emitted as-is; no decoding is performed.
Linear in `ps.buffer().size()`.
return os << ps.buffer();
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
params_encoded_base const& qp);
Any percent-escapes are emitted as-is; no decoding is performed.
Linear in `ps.buffer().size()`.
return os << ps.buffer();
Format to an output stream
std::ostream&
operator<<(
std::ostream& os,
params_base const& qp);
Any percent-escapes are emitted as-is; no decoding is performed.
Linear in `ps.buffer().size()`.
return os << ps.buffer();
Format the url to the output stream
std::ostream&
operator<<(
std::ostream& os,
url_view_base const& u);
This function serializes the url to the specified output stream. Any percent-escapes are emitted as-is; no decoding is performed.
url_view u( "http://www.example.com/index.htm" );
std::stringstream ss;
ss << u;
assert( ss.str() == "http://www.example.com/index.htm" );
return os << u.buffer();
Linear in `u.buffer().size()`
Basic guarantee.
Constructor
param() = default;
Default constructed query parameters have an empty key and no value.
param qp;
this->key == "" && this->value == "" && this->has_value == false
Constant.
Throws nothing.
Constructor
param(param&& other) noexcept;
Upon construction, this acquires ownership of the members of other via move construction. The moved from object is as if default constructed.
Constant.
Throws nothing.
Constructor
param(param const& other) = default;
Upon construction, this becomes a copy of `other`.
this->key == other.key && this->value == other.value && this->has_value == other.has_value
Linear in `other.key.size() + other.value.size()`.
Calls to allocate may throw.
Constructor
template
param(
core::string_view key,
OptionalString const& value);
This constructs a parameter with a key and value.
No validation is performed on the strings. Ownership of the key and value is acquired by making copies.
param qp( "key", "value" );
param qp( "key", optional("value") );
param qp( "key", boost::none );
param qp( "key", nullptr );
param qp( "key", no_value );
this->key == key && this->value == value && this->has_value == true
Linear in `key.size() + value.size()`.
Calls to allocate may throw.
param(
core::string_view key,
core::string_view value,
bool has_value) noexcept;
Assignment
param&
operator=(param&& other) noexcept;
Upon assignment, this acquires ownership of the members of other via move assignment. The moved from object is as if default constructed.
Constant.
Throws nothing.
Assignment
param&
operator=(param const&) = default;
Upon assignment, this becomes a copy of `other`.
this->key == other.key && this->value == other.value && this->has_value == other.has_value
Linear in `other.key.size() + other.value.size()`.
Calls to allocate may throw.
Assignment
param&
operator=(param_view const& other);
The members of `other` are copied, re-using already existing string capacity.
this->key == other.key && this->value == other.value && this->has_value == other.has_value
Linear in `other.key.size() + other.value.size()`.
Calls to allocate may throw.
Assignment
param&
operator=(param_pct_view const& other);
The members of `other` are copied, re-using already existing string capacity.
this->key == other.key && this->value == other.value && this->has_value == other.has_value
Linear in `other.key.size() + other.value.size()`.
Calls to allocate may throw.
Constructor.
constexpr
ipv4_address() = default;
Constructor.
constexpr
ipv4_address(ipv4_address const&) = default;
Construct from an unsigned integer.
ipv4_address(uint_type u) noexcept;
This function constructs an address from the unsigned integer `u`, where the most significant byte forms the first octet of the resulting address.
Construct from an array of bytes.
ipv4_address(bytes_type const& bytes) noexcept;
This function constructs an address from the array in `bytes`, which is interpreted in big-endian.
Construct from a string.
ipv4_address(core::string_view s);
This function constructs an address from the string `s`, which must contain a valid IPv4 address string or else an exception is thrown.
For a non-throwing parse function, use parse_ipv4_address .
Exceptions thrown on invalid input.
Constructor.
constexpr
ipv6_address() = default;
Default constructed objects represent the unspecified address.
Constructor.
constexpr
ipv6_address(ipv6_address const&) = default;
Construct from an array of bytes.
ipv6_address(bytes_type const& bytes) noexcept;
This function constructs an address from the array in `bytes`, which is interpreted in big-endian.
Construct from an IPv4 address.
ipv6_address(ipv4_address const& addr) noexcept;
This function constructs an IPv6 address from the IPv4 address `addr`. The resulting address is an IPv4-Mapped IPv6 Address.
Construct from a string.
ipv6_address(core::string_view s);
This function constructs an address from the string `s`, which must contain a valid IPv6 address string or else an exception is thrown.
For a non-throwing parse function, use parse_ipv6_address .
Exceptions thrown on invalid input.
Assignment
url_view&
operator=(url_view const& other) noexcept;
After assignment, both views reference the same underlying character buffer. Ownership is not transferred.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing.
Assignment
url_view&
operator=(url_view_base const& other) noexcept;
After assignment, both views reference the same underlying character buffer. Ownership is not transferred.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing.
Constructor
authority_view() noexcept;
Default constructed authorities refer to a string with zero length, which is always valid. This matches the grammar for a zero-length host.
Throws nothing.
Construct from a string.
authority_view(core::string_view s);
This function attempts to construct an authority from the string `s`, which must be a valid ['authority] or else an exception is thrown. Upon successful construction, the view refers to the characters in the buffer pointed to by `s`. Ownership is not transferred; The caller is responsible for ensuring that the lifetime of the buffer extends until the view is destroyed.
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = user [ ":" [ password ] ]
user = *( unreserved / pct-encoded / sub-delims )
password = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
Constructor
authority_view(authority_view const&) noexcept;
Constructor
url_view() noexcept;
Default constructed views refer to a string with zero length, which always remains valid. This matches the grammar for a relative-ref with an empty path and no query or fragment.
url_view u;
this->empty() == true
Constant.
Throws nothing.
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Constructor
url_view(core::string_view s);
This function constructs a URL from the string `s`, which must contain a valid URI or relative-ref or else an exception is thrown. Upon successful construction, the view refers to the characters in the buffer pointed to by `s`. Ownership is not transferred; The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
url_view u( "http://www.example.com/index.htm" );
return parse_uri_reference( s ).value();
Linear in `s.size()`.
Exceptions thrown on invalid input.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
template<
class String,
class = void>
url_view(String const& s);
Constructor
url_view(url_view const& other) noexcept;
After construction, both views reference the same underlying character buffer. Ownership is not transferred.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing.
Constructor
url_view(url_view_base const& other) noexcept;
After construction, both views reference the same underlying character buffer. Ownership is not transferred.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing.
Constructor
constexpr
ignore_case_param() noexcept = default;
By default, comparisons are case-sensitive.
This function performs case-sensitive comparisons when called with no arguments:
void f( ignore_case_param = {} );
Constructor
constexpr
ignore_case_param(ignore_case_t) noexcept;
Construction from ignore_case indicates that comparisons should be case-insensitive.
When ignore_case is passed as an argument, this function ignores case when performing comparisons:
void f( ignore_case_param = {} );
constexpr
iterator() = default;
constexpr
iterator(iterator const&) = default;
iterator&
operator++() noexcept;
iterator
operator++(int) noexcept;
iterator&
operator--() noexcept;
iterator
operator--(int) noexcept;
constexpr
iterator() = default;
constexpr
iterator(iterator const&) = default;
iterator&
operator++() noexcept;
iterator
operator++(int) noexcept;
iterator&
operator--() noexcept;
iterator
operator--(int) noexcept;
Constructor
constexpr
segments_view() = default;
Default-constructed segments have zero elements.
segments_view ps;
return segments_view( "" );
Constant.
Throws nothing.
Constructor
constexpr
segments_view(segments_view const& other) = default;
After construction, viewss reference the same underlying character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant
Throws nothing
Constructor
segments_view(core::string_view s);
This function constructs segments from a valid path string, which can contain percent escapes. Upon construction, the view references the character buffer pointed to by `s`. caller is responsible for ensuring that the lifetime of the buffer extends until the view is destroyed.
segments_view ps( "/path/to/file.txt" );
return parse_path( s ).value();
this->buffer().data() == s.data()
Linear in `s`.
Exceptions thrown on invalid input.
path = [ "/" ] [ segment *( "/" segment ) ]
segment = *pchar
Constructor
constexpr
segments_encoded_view() = default;
Default-constructed segments have zero elements.
segments_encoded_view ps;
return segments_encoded_view( "" );
Constant.
Throws nothing.
Constructor
constexpr
segments_encoded_view(segments_encoded_view const&) noexcept = default;
After construction, both views reference the same character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing
Constructor
segments_encoded_view(core::string_view s);
This function constructs segments from a valid path string, which can contain percent escapes. Upon construction, the view references the character buffer pointed to by `s`. caller is responsible for ensuring that the lifetime of the buffer extends until the view is destroyed.
segments_encoded_view ps( "/path/to/file.txt" );
return parse_path( s ).value();
this->buffer().data() == s.data()
Linear in `s`.
Exceptions thrown on invalid input.
path = [ "/" ] [ segment *( "/" segment ) ]
segment = *pchar
template
constexpr
pct_encoded_rule_t
pct_encoded_rule(CharSet_ const& cs) noexcept;
template
constexpr
pct_encoded_rule_t
pct_encoded_rule(CharSet const& cs) noexcept;
iterator() = default;
constexpr
iterator(iterator const&) = default;
iterator&
operator++() noexcept;
iterator
operator++(int) noexcept;
iterator&
operator--() noexcept;
iterator
operator--(int) noexcept;
Find a matching key
iterator
find(
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key, which may contain percent escapes. The comparison is performed as if all escaped characters were decoded first.
The search starts from the first param and proceeds forward until either the key is found or the end of the range is reached, in which case `end()` is returned.
assert( url_view( "?first=John&last=Doe" ).encoded_params().find( "First", ignore_case )->value == "John" );
return this->find( this->begin(), key, ic );
Linear in `this->buffer().size()`.
Exceptions thrown on invalid input.
Find a matching key
iterator
find(
iterator from,
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key, which may contain percent escapes. The comparison is performed as if all escaped characters were decoded first.
The search starts at `from` and proceeds forward until either the key is found or the end of the range is reached, in which case `end()` is returned.
url_view u( "?First=John&Last=Doe" );
assert( u.encoded_params().find( "first" ) != u.encoded_params().find( "first", ignore_case ) );
Linear in `this->buffer().size()`.
Exceptions thrown on invalid input.
Find a matching key
iterator
find_last(
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key, which may contain percent escapes. The comparison is performed as if all escaped characters were decoded first.
The search starts from the last param and proceeds backwards until either the key is found or the beginning of the range is reached, in which case `end()` is returned.
assert( url_view( "?first=John&last=Doe" ).encoded_params().find_last( "last" )->value == "Doe" );
Linear in `this->buffer().size()`.
Exceptions thrown on invalid input.
Find a matching key
iterator
find_last(
iterator before,
pct_string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key, which may contain percent escapes. The comparison is performed as if all escaped characters were decoded first.
The search starts prior to `before` and proceeds backwards until either the key is found or the beginning of the range is reached, in which case `end()` is returned.
url_view u( "?First=John&Last=Doe" );
assert( u.encoded_params().find_last( "last" ) != u.encoded_params().find_last( "last", ignore_case ) );
Linear in `this->buffer().size()`.
Constructor
constexpr
params_ref(params_ref const& other) = default;
After construction, both views reference the same url. Ownership is not transferred; the caller is responsible for ensuring the lifetime of the url extends until it is no longer referenced.
&this->url() == &other.url()
Constant.
Throws nothing.
Constructor
params_ref(
params_ref const& other,
encoding_opts opt) noexcept;
After construction, both views will reference the same url but this instance will use the specified encoding_opts when the values are decoded.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the url extends until it is no longer referenced.
&this->url() == &other.url()
Constant.
Throws nothing.
Assignment
params_ref&
operator=(params_ref const& other);
The previous contents of this are replaced by the contents of `other.
All iterators are invalidated.
The strings referenced by `other` must not come from the underlying url, or else the behavior is undefined.
this->assign( other.begin(), other.end() );
Linear in `other.buffer().size()`.
Strong guarantee. Calls to allocate may throw.
Assignment
params_ref&
operator=(std::initializer_list init);
After assignment, the previous contents of the query parameters are replaced by the contents of the initializer-list.
None of character buffers referenced by `init` may overlap the character buffer of the underlying url, or else the behavior is undefined.
this->assign( init );
Linear in `init.size()`.
Strong guarantee. Calls to allocate may throw.
Assign elements
void
assign(std::initializer_list init);
This function replaces the entire contents of the view with the params in the initializer-list .
All iterators are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
url u;
u.params().assign( {{ "first", "John" }, { "last", "Doe" }} );
Linear in `init.size()`.
Strong guarantee. Calls to allocate may throw.
Assign elements
template
void
assign(
FwdIt first,
FwdIt last);
This function replaces the entire contents of the view with the params in the range.
All iterators are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_view >::value == true
Linear in the size of the range.
Strong guarantee. Calls to allocate may throw.
Append elements
iterator
append(param_view const& p);
This function appends a param to the view.
The `end()` iterator is invalidated.
url u;
u.params().append( { "first", "John" } );
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Append elements
iterator
append(std::initializer_list init);
This function appends the params in an initializer-list to the view.
The `end()` iterator is invalidated.
url u;
u.params().append({ { "first", "John" }, { "last", "Doe" } });
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Append elements
template
iterator
append(
FwdIt first,
FwdIt last);
This function appends a range of params to the view.
The `end()` iterator is invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_view >::value == true
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Erase elements
iterator
erase(iterator pos) noexcept;
This function removes an element from the container.
All iterators that are equal to `pos` or come after are invalidated.
url u( "?first=John&last=Doe" );
params_ref::iterator it = u.params().erase( u.params().begin() );
assert( u.encoded_query() == "last=Doe" );
Linear in `this->url().encoded_query().size()`.
Throws nothing.
Erase elements
iterator
erase(
iterator first,
iterator last) noexcept;
This function removes a range of elements from the container.
All iterators that are equal to `first` or come after are invalidated.
Linear in `this->url().encoded_query().size()`.
Throws nothing.
Erase elements
std::size_t
erase(
core::string_view key,
ignore_case_param ic = = {}) noexcept;
All iterators are invalidated.
this->count( key, ic ) == 0
Linear in `this->url().encoded_query().size()`.
Throws nothing.
Insert elements
iterator
insert(
iterator before,
param_view const& p);
This function inserts a param before the specified position.
All iterators that are equal to `before` or come after are invalidated.
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Insert elements
iterator
insert(
iterator before,
std::initializer_list init);
This function inserts the params in an initializer-list before the specified position.
All iterators that are equal to `before` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Insert elements
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
This function inserts a range of params before the specified position.
All iterators that are equal to `before` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_view >::value == true
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Replace elements
iterator
replace(
iterator pos,
param_view const& p);
This function replaces the contents of the element at `pos` with the specified param.
All iterators that are equal to `pos` or come after are invalidated.
url u( "?first=John&last=Doe" );
u.params().replace( u.params().begin(), { "title", "Mr" });
assert( u.encoded_query() == "title=Mr&last=Doe" );
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Replace elements
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
This function replaces a range of elements with the params in an initializer-list .
All iterators that are equal to `from` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Replace elements
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
This function replaces a range of elements with a range of params.
All iterators that are equal to `from` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_view >::value == true
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Set a value
iterator
set(
iterator pos,
core::string_view value);
This function replaces the value of an element at the specified position.
All iterators that are equal to `pos` or come after are invalidated.
url u( "?id=42&id=69" );
u.params().set( u.params().begin(), "none" );
assert( u.encoded_query() == "id=none&id=69" );
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
Set a value
iterator
set(
core::string_view key,
core::string_view value,
ignore_case_param ic = = {});
This function performs one of two actions depending on the value of `this->contains( key, ic )`.
All iterators are invalidated.
url u( "?id=42&id=69" );
u.params().set( "id", "none" );
assert( u.params().count( "id" ) == 1 );
this->count( key, ic ) == 1 && this->find( key, ic )->value == value
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw.
iterator() = default;
constexpr
iterator(iterator const&) = default;
iterator&
operator++() noexcept;
iterator
operator++(int) noexcept;
iterator&
operator--() noexcept;
iterator
operator--(int) noexcept;
Find a matching key
iterator
find(
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key. The comparison is performed as if all escaped characters were decoded first.
The search starts from the first param and proceeds forward until either the key is found or the end of the range is reached, in which case `end()` is returned.
assert( (*url_view( "?first=John&last=Doe" ).params().find( "First", ignore_case )).value == "John" );
return this->find( this->begin(), key, ic );
Linear in `this->buffer().size()`.
Find a matching key
iterator
find(
iterator from,
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key. The comparison is performed as if all escaped characters were decoded first.
The search starts at `from` and proceeds forward until either the key is found or the end of the range is reached, in which case `end()` is returned.
url_view u( "?First=John&Last=Doe" );
assert( u.params().find( "first" ) != u.params().find( "first", ignore_case ) );
Linear in `this->buffer().size()`.
Find a matching key
iterator
find_last(
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key. The comparison is performed as if all escaped characters were decoded first.
The search starts from the last param and proceeds backwards until either the key is found or the beginning of the range is reached, in which case `end()` is returned.
assert( (*url_view( "?first=John&last=Doe" ).params().find_last( "last" )).value == "Doe" );
Linear in `this->buffer().size()`.
Find a matching key
iterator
find_last(
iterator before,
core::string_view key,
ignore_case_param ic = = {}) const noexcept;
This function examines the parameters in the container to find a match for the specified key. The comparison is performed as if all escaped characters were decoded first.
The search starts prior to `before` and proceeds backwards until either the key is found or the beginning of the range is reached, in which case `end()` is returned.
url_view u( "?First=John&Last=Doe" );
assert( u.params().find_last( "last" ) != u.params().find_last( "last", ignore_case ) );
Linear in `this->buffer().size()`.
Constructor
constexpr
params_encoded_view() = default;
Default-constructed params have zero elements.
params_encoded_view qp;
return params_encoded_view( "" );
Constant.
Throws nothing.
Constructor
constexpr
params_encoded_view(params_encoded_view const& other) = default;
After construction both views reference the same character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing
Constructor
params_encoded_view(core::string_view s);
This function constructs params from a valid query parameter string, which can contain percent escapes. Unlike the parameters in URLs, the string passed here should not start with "?". Upon construction, the view references the character buffer pointed to by `s`. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
params_encoded_view qp( "first=John&last=Doe" );
return parse_query( s ).value();
this->buffer().data() == s.data()
Linear in `s`.
Exceptions thrown on invalid input.
query-params = [ query-param ] *( "&" query-param )
query-param = key [ "=" value ]
Constructor
params_view() = default;
Default-constructed params have zero elements.
params_view qp;
return params_view( "" );
Constant.
Throws nothing.
Constructor
constexpr
params_view(params_view const& other) = default;
After construction both views reference the same character buffer.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing
Constructor
params_view(
params_view const& other,
encoding_opts opt) noexcept;
After construction both views will reference the same character buffer but this instance will use the specified encoding_opts when the values are decoded.
Ownership is not transferred; the caller is responsible for ensuring the lifetime of the buffer extends until it is no longer referenced.
this->buffer().data() == other.buffer().data()
Constant.
Throws nothing
Constructor
params_view(core::string_view s);
This function constructs params from a valid query parameter string, which can contain percent escapes. Unlike the parameters in URLs, the string passed here should not start with "?". Upon construction, the view references the character buffer pointed to by `s`. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
params_view qp( "first=John&last=Doe" );
return parse_query( s ).value();
this->buffer().data() == s.data()
Linear in `s`.
Exceptions thrown on invalid input.
query-params = [ query-param ] *( "&" query-param )
query-param = key [ "=" value ]
Constructor
params_view(
core::string_view s,
encoding_opts opt);
This function constructs params from a valid query parameter string, which can contain percent escapes.
This instance will use the specified encoding_opts when the values are decoded.
Unlike the parameters in URLs, the string passed here should not start with "?". Upon construction, the view will reference the character buffer pointed to by `s`. The caller is responsible for ensuring that the lifetime of the buffer extends until it is no longer referenced.
encoding_opts opt;
opt.space_as_plus = true;
params_view qp( "name=John+Doe", opt );
return params_view(parse_query( s ).value(), opt);
this->buffer().data() == s.data()
Linear in `s`.
Exceptions thrown on invalid input.
query-params = [ query-param ] *( "&" query-param )
query-param = key [ "=" value ]
Return the path as a container of segments
segments_ref
segments() noexcept;
This function returns a bidirectional view of segments over the path. The returned view references the same underlying character buffer; ownership is not transferred. Any percent-escapes in strings returned when iterating the view are decoded first. The container is modifiable; changes to the container are reflected in the underlying URL.
url u( "http://example.com/path/to/file.txt" );
segments sv = u.segments();
Constant.
Throws nothing.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return the path as a container of segments
segments_view
segments() const noexcept;
This function returns a bidirectional view of strings over the path. The returned view references the same underlying character buffer; ownership is not transferred. Any percent-escapes in strings returned when iterating the view are decoded first.
segments_view sv = url_view( "/path/to/file.txt" ).segments();
Constant.
Throws nothing.
path = [ "/" ] segment *( "/" segment )
Return the path as a container of segments
segments_encoded_ref
encoded_segments() noexcept;
This function returns a bidirectional view of segments over the path. The returned view references the same underlying character buffer; ownership is not transferred. Strings returned when iterating the range may contain percent escapes. The container is modifiable; changes to the container are reflected in the underlying URL.
url u( "http://example.com/path/to/file.txt" );
segments_encoded_ref sv = u.encoded_segments();
Constant.
Throws nothing.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return the path as a container of segments
segments_encoded_view
encoded_segments() const noexcept;
This function returns a bidirectional view of strings over the path. The returned view references the same underlying character buffer; ownership is not transferred. Strings returned when iterating the range may contain percent escapes.
segments_encoded_view sv = url_view( "/path/to/file.txt" ).encoded_segments();
Constant.
Throws nothing.
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0
Return the query as a container of parameters
params_encoded_view
encoded_params() const noexcept;
This function returns a bidirectional view of key/value pairs over the query. The returned view references the same underlying character buffer; ownership is not transferred. Strings returned when iterating the range may contain percent escapes.
params_encoded_view pv = url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_params();
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Return the query as a container of parameters
params_encoded_ref
encoded_params() noexcept;
This function returns a bidirectional view of key/value pairs over the query. The returned view references the same underlying character buffer; ownership is not transferred. Strings returned when iterating the range may contain percent escapes. The container is modifiable; changes to the container are reflected in the underlying URL.
params_encoded_ref pv = url( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_params();
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Return the query as a container of parameters
params_ref
params() noexcept;
This function returns a bidirectional view of key/value pairs over the query. The returned view references the same underlying character buffer; ownership is not transferred. Any percent-escapes in strings returned when iterating the view are decoded first. The container is modifiable; changes to the container are reflected in the underlying URL.
params_ref pv = url( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).params();
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
url_view_base::params
params_view
params() const noexcept;
Return the query as a container of parameters
params_ref
params(encoding_opts opt) noexcept;
This function returns a bidirectional view of key/value pairs over the query. The returned view references the same underlying character buffer; ownership is not transferred. Any percent-escapes in strings returned when iterating the view are decoded first. The container is modifiable; changes to the container are reflected in the underlying URL.
encoding_opts opt;
opt.space_as_plus = true;
params_ref pv = url( "/sql?id=42&name=jane+doe&page+size=20" ).params(opt);
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
Assignment
params_encoded_ref&
operator=(params_encoded_ref const& other);
The previous contents of this are replaced by the contents of `other.
All iterators are invalidated.
The strings referenced by `other` must not come from the underlying url, or else the behavior is undefined.
this->assign( other.begin(), other.end() );
Linear in `other.buffer().size()`.
Strong guarantee. Calls to allocate may throw.
Assignment
params_encoded_ref&
operator=(std::initializer_list init);
After assignment, the previous contents of the query parameters are replaced by the contents of the initializer-list.
All iterators are invalidated.
None of character buffers referenced by `init` may overlap the character buffer of the underlying url, or else the behavior is undefined.
this->assign( init.begin(), init.end() );
Linear in `init.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Assign params
void
assign(std::initializer_list init);
This function replaces the entire contents of the view with the params in the initializer-list .
All iterators are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
url u;
u.encoded_params().assign({ { "first", "John" }, { "last", "Doe" } });
Linear in `init.size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Assign params
template
void
assign(
FwdIt first,
FwdIt last);
This function replaces the entire contents of the view with the params in the range.
All iterators are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_pct_view >::value == true
Linear in the size of the range.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Append params
iterator
append(param_pct_view const& p);
This function appends a param to the view.
The `end()` iterator is invalidated.
url u;
u.encoded_params().append( { "first", "John" } );
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Append params
iterator
append(std::initializer_list init);
This function appends the params in an initializer-list to the view.
The `end()` iterator is invalidated.
url u;
u.encoded_params().append({ {"first", "John"}, {"last", "Doe"} });
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Append params
template
iterator
append(
FwdIt first,
FwdIt last);
This function appends a range of params to the view.
The `end()` iterator is invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_pct_view >::value == true
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Insert params
iterator
insert(
iterator before,
param_pct_view const& p);
This function inserts a param before the specified position.
All iterators that are equal to `before` or come after are invalidated.
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Insert params
iterator
insert(
iterator before,
std::initializer_list init);
This function inserts the params in an initializer-list before the specified position.
All iterators that are equal to `before` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Insert params
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
This function inserts a range of params before the specified position.
All iterators that are equal to `before` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_pct_view >::value == true
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Erase params
iterator
erase(iterator pos) noexcept;
This function removes an element from the container.
All iterators that are equal to `pos` or come after are invalidated.
url u( "?first=John&last=Doe" );
params_encoded_ref::iterator it = u.encoded_params().erase( u.encoded_params().begin() );
assert( u.encoded_query() == "last=Doe" );
Linear in `this->url().encoded_query().size()`.
Throws nothing.
Erase params
iterator
erase(
iterator first,
iterator last) noexcept;
This function removes a range of params from the container.
All iterators that are equal to `first` or come after are invalidated.
Linear in `this->url().encoded_query().size()`.
Throws nothing.
Erase params
std::size_t
erase(
pct_string_view key,
ignore_case_param ic = = {}) noexcept;
All iterators are invalidated.
this->count( key, ic ) == 0
Linear in `this->url().encoded_query().size()`.
Exceptions thrown on invalid input.
Replace params
iterator
replace(
iterator pos,
param_pct_view const& p);
This function replaces the contents of the element at `pos` with the specified param.
All iterators that are equal to `pos` or come after are invalidated.
The strings passed in must not come from the element being replaced, or else the behavior is undefined.
url u( "?first=John&last=Doe" );
u.encoded_params().replace( u.encoded_params().begin(), { "title", "Mr" });
assert( u.encoded_query() == "title=Mr&last=Doe" );
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Replace params
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
This function replaces a range of params with the params in an initializer-list .
All iterators that are equal to `from` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Replace params
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
This function replaces a range of params with a range of params.
All iterators that are equal to `from` or come after are invalidated.
The strings referenced by the inputs must not come from the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, param_pct_view >::value == true
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Set a value
iterator
set(
iterator pos,
pct_string_view value);
This function replaces the value of an element at the specified position.
All iterators that are equal to `pos` or come after are invalidated.
The string passed in must not come from the element being replaced, or else the behavior is undefined.
url u( "?id=42&id=69" );
u.encoded_params().set( u.encoded_params().begin(), "none" );
assert( u.encoded_query() == "id=none&id=69" );
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Set a value
iterator
set(
pct_string_view key,
pct_string_view value,
ignore_case_param ic = = {});
This function performs one of two actions depending on the value of `this->contains( key, ic )`.
All iterators are invalidated.
The strings passed in must not come from the element being replaced, or else the behavior is undefined.
url u( "?id=42&id=69" );
u.encoded_params().set( "id", "none" );
assert( u.encoded_params().count( "id" ) == 1 );
this->count( key, ic ) == 1 && this->find( key, ic )->value == value
Linear in `this->url().encoded_query().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Assign segments
void
assign(std::initializer_list init);
The existing contents are replaced by a copy of the contents of the initializer list. Reserved characters in the list are automatically escaped. Escapes in the list are preserved.
All iterators are invalidated.
None of the character buffers referenced by the list may overlap the character buffer of the underlying url, or else the behavior is undefined.
url u;
u.segments().assign( {"path", "to", "file.txt"} );
Linear in `init.size() + this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Assign segments
template
void
assign(
FwdIt first,
FwdIt last);
The existing contents are replaced by a copy of the contents of the range. Reserved characters in the range are automatically escaped. Escapes in the range are preserved.
All iterators are invalidated.
None of the character buffers referenced by the range may overlap the character buffer of the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, pct_string_view >::value == true
Linear in `std::distance( first, last ) + this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Assignment
segments_encoded_ref&
operator=(segments_encoded_ref const& other);
The existing contents are replaced by a copy of the other segments.
All iterators are invalidated.
None of the character buffers referenced by `other` may overlap the buffer of the underlying url, or else the behavior is undefined.
this->assign( other.begin(), other.end() );
Linear in `other.buffer().size()`.
Strong guarantee. Calls to allocate may throw.
@{
segments_encoded_ref&
operator=(segments_encoded_view const& other);
Assignment
segments_encoded_ref&
operator=(std::initializer_list init);
The existing contents are replaced by a copy of the contents of the initializer list. Reserved characters in the list are automatically escaped. Escapes in the list are preserved.
All iterators are invalidated.
url u;
u.encoded_segments() = {"path", "to", "file.txt"};
None of the character buffers referenced by the list may overlap the character buffer of the underlying url, or else the behavior is undefined.
this->assign( init.begin(), init.end() );
Linear in `init.size() + this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Erase segments
iterator
erase(iterator pos) noexcept;
This function removes a segment.
All iterators that are equal to `pos` or come after are invalidated.
Linear in `this->url().encoded_resource().size()`.
Throws nothing.
Erase segments
iterator
erase(
iterator first,
iterator last) noexcept;
This function removes a range of segments from the container.
All iterators that are equal to `first` or come after are invalidated.
Linear in `this->url().encoded_resource().size()`.
Throws nothing.
Insert segments
iterator
insert(
iterator before,
pct_string_view s);
This function inserts a segment before the specified position. Reserved characters in the segment are automatically escaped. Escapes in the segment are preserved.
All iterators that are equal to `before` or come after are invalidated.
Linear in `s.size() + this->url().encoded_resource().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Insert segments
iterator
insert(
iterator before,
std::initializer_list init);
This function inserts the segments in an initializer list before the specified position. Reserved characters in the list are automatically escaped. Escapes in the list are preserved.
All iterators that are equal to `before` or come after are invalidated.
None of the character buffers referenced by the list may overlap the character buffer of the underlying url, or else the behavior is undefined.
url u( "/file.txt" );
u.encoded_segments().insert( u.encoded_segments().begin(), { "path", "to" } );
Linear in `init.size() + this->url().encoded_resource().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Insert segments
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
This function inserts the segments in a range before the specified position. Reserved characters in the range are automatically escaped. Escapes in the range are preserved.
All iterators that are equal to `before` or come after are invalidated.
None of the character buffers referenced by the range may overlap the character buffer of the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, pct_string_view >::value == true
Linear in `std::distance( first, last ) + this->url().encoded_resource().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Assign segments
void
assign(std::initializer_list init);
The existing contents are replaced by a copy of the contents of the initializer list. Reserved characters in the list are automatically escaped.
All iterators are invalidated.
None of the character buffers referenced by `init` may overlap the character buffer of the underlying url, or else the behavior is undefined.
url u;
u.segments().assign( { "path", "to", "file.txt" } );
Linear in `init.size() + this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Strong guarantee. Calls to allocate may throw.
Assign segments
template
void
assign(
FwdIt first,
FwdIt last);
The existing contents are replaced by a copy of the contents of the range. Reserved characters in the range are automatically escaped.
All iterators are invalidated.
None of the character buffers referenced by the range may overlap the character buffer of the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, core::string_view >::value == true
Linear in `std::distance( first, last ) + this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Strong guarantee. Calls to allocate may throw.
Assignment
segments_ref&
operator=(segments_ref const& other);
The existing contents are replaced by a copy of the other segments.
All iterators are invalidated.
None of the character buffers referenced by `other` may overlap the buffer of the underlying url, or else the behavior is undefined.
this->assign( other.begin(), other.end() );
Linear in `other.buffer().size()`.
Strong guarantee. Calls to allocate may throw.
@{
segments_ref&
operator=(segments_view const& other);
Assignment
segments_ref&
operator=(std::initializer_list init);
The existing contents are replaced by a copy of the contents of the initializer list. Reserved characters in the list are automatically escaped.
All iterators are invalidated.
url u;
u.segments() = { "path", "to", "file.txt" };
None of the character buffers referenced by the list may overlap the character buffer of the underlying url, or else the behavior is undefined.
this->assign( init.begin(), init.end() );
Linear in `init.size() + this->url().encoded_query().size() + this->url().encoded_fragment().size()`.
Strong guarantee. Calls to allocate may throw.
Replace segments
iterator
replace(
iterator pos,
pct_string_view s);
This function replaces the segment at the specified position. Reserved characters in the string are automatically escaped. Escapes in the string are preserved.
All iterators that are equal to `pos` or come after are invalidated.
Linear in `s.size() + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw.
Replace segments
iterator
replace(
iterator from,
iterator to,
pct_string_view s);
This function replaces a range of segments with one segment. Reserved characters in the string are automatically escaped. Escapes in the string are preserved.
All iterators that are equal to `from` or come after are invalidated.
Linear in `s.size() + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Replace segments
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
This function replaces a range of segments with a list of segments in an initializer list. Reserved characters in the list are automatically escaped. Escapes in the list are preserved.
All iterators that are equal to `from` or come after are invalidated.
None of the character buffers referenced by the list may overlap the character buffer of the underlying url, or else the behavior is undefined.
Linear in `init.size() + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Replace segments
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
This function replaces a range of segments with annother range of segments. Reserved characters in the new range are automatically escaped. Escapes in the new range are preserved.
All iterators that are equal to `from` or come after are invalidated.
None of the character buffers referenced by the new range may overlap the character buffer of the underlying url, or else the behavior is undefined.
Linear in `std::distance( first, last ) + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw. Exceptions thrown on invalid input.
Erase segments
iterator
erase(iterator pos) noexcept;
This function removes a segment.
All iterators that are equal to `pos` or come after are invalidated.
Linear in `this->url().encoded_resource().size()`.
Throws nothing.
Erase segments
iterator
erase(
iterator first,
iterator last) noexcept;
This function removes a range of segments.
All iterators that are equal to `first` or come after are invalidated.
Linear in `this->url().encoded_resource().size()`.
Throws nothing.
Insert segments
iterator
insert(
iterator before,
core::string_view s);
This function inserts a segment before the specified position. Reserved characters in the segment are automatically escaped.
All iterators that are equal to `before` or come after are invalidated.
Linear in `s.size() + this->url().encoded_resource().size()`.
Strong guarantee. Calls to allocate may throw.
Insert segments
iterator
insert(
iterator before,
std::initializer_list init);
This function inserts the segments in an initializer list before the specified position. Reserved characters in the list are percent-escaped in the result.
All iterators that are equal to `before` or come after are invalidated.
None of the character buffers referenced by the list may overlap the character buffer of the underlying url, or else the behavior is undefined.
url u( "/file.txt" );
u.segments().insert( u.segments().begin(), { "path", "to" } );
Linear in `init.size() + this->url().encoded_resource().size()`.
Strong guarantee. Calls to allocate may throw.
Insert segments
template
iterator
insert(
iterator before,
FwdIt first,
FwdIt last);
This function inserts the segments in a range before the specified position. Reserved characters in the list are automatically escaped.
All iterators that are equal to `before` or come after are invalidated.
None of the character buffers referenced by the range may overlap the character buffer of the underlying url, or else the behavior is undefined.
std::is_convertible< std::iterator_traits< FwdIt >::reference_type, core::string_view >::value == true
Linear in `std::distance( first, last ) + this->url().encoded_resource().size()`.
Strong guarantee. Calls to allocate may throw.
Replace segments
iterator
replace(
iterator pos,
core::string_view s);
This function replaces the segment at the specified position. Reserved characters in the string are automatically escaped.
All iterators that are equal to `pos` or come after are invalidated.
Linear in `s.size() + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw.
Replace segments
iterator
replace(
iterator from,
iterator to,
core::string_view s);
This function replaces a range of segments with one segment. Reserved characters in the string are automatically escaped.
All iterators that are equal to `from` or come after are invalidated.
Linear in `s.size() + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw.
Replace segments
iterator
replace(
iterator from,
iterator to,
std::initializer_list init);
This function replaces a range of segments with a list of segments in an initializer list. Reserved characters in the list are automatically escaped.
All iterators that are equal to `from` or come after are invalidated.
None of the character buffers referenced by the list may overlap the character buffer of the underlying url, or else the behavior is undefined.
Linear in `init.size() + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw.
Replace segments
template
iterator
replace(
iterator from,
iterator to,
FwdIt first,
FwdIt last);
This function replaces a range of segments with annother range of segments. Reserved characters in the new range are automatically escaped.
All iterators that are equal to `from` or come after are invalidated.
None of the character buffers referenced by the new range may overlap the character buffer of the underlying url, or else the behavior is undefined.
Linear in `std::distance( first, last ) + this->url().encoded_resouce().size()`.
Strong guarantee. Calls to allocate may throw.
Return the query as a container of parameters
params_view
params() const noexcept;
This function returns a bidirectional view of key/value pairs over the query. The returned view references the same underlying character buffer; ownership is not transferred. Any percent-escapes in strings returned when iterating the view are decoded first.
params_view pv = url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).params();
Constant.
Throws nothing.
query = *( pchar / "/" / "?" )
query-param = key [ "=" value ]
query-params = [ query-param ] *( "&" query-param )
params_view
params(encoding_opts opt) const noexcept;
Constructor
url() noexcept;
Default constructed urls contain a zero-length string. This matches the grammar for a relative-ref with an empty path and no query or fragment.
url u;
this->empty() == true
Constant.
Throws nothing.
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Constructor
url(core::string_view s);
This function constructs a URL from the string `s`, which must contain a valid URI or relative-ref or else an exception is thrown. The new url retains ownership by allocating a copy of the passed string.
url u( "https://www.example.com" );
return url( parse_uri_reference( s ).value() );
this->buffer().data() != s.data()
Linear in `s.size()`.
Calls to allocate may throw. Exceptions thrown on invalid input.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Constructor
url(url&& u) noexcept;
The contents of `u` are transferred to the newly constructed object, which includes the underlying character buffer. After construction, the moved-from object is as if default constructed.
u.empty() == true
Constant.
Throws nothing.
Constructor
url(url_view_base const& u);
The newly constructed object contains a copy of `u`.
this->buffer() == u.buffer() && this->buffer().data() != u.buffer().data()
Linear in `u.size()`.
Strong guarantee. Calls to allocate may throw.
Constructor
url(url const& u);
The newly constructed object contains a copy of `u`.
this->buffer() == u.buffer() && this->buffer().data() != u.buffer().data()
Linear in `u.size()`.
Strong guarantee. Calls to allocate may throw.
Assignment
url&
operator=(url&& u) noexcept;
The contents of `u` are transferred to `this`, including the underlying character buffer. The previous contents of `this` are destroyed. After assignment, the moved-from object is as if default constructed.
u.empty() == true
Constant.
Throws nothing.
Assignment
url&
operator=(url_view_base const& u);
The contents of `u` are copied and the previous contents of `this` are destroyed. Capacity is preserved, or increases.
this->buffer() == u.buffer() && this->buffer().data() != u.buffer().data()
Linear in `u.size()`.
Strong guarantee. Calls to allocate may throw.
Assignment
url&
operator=(url const& u);
The contents of `u` are copied and the previous contents of `this` are destroyed. Capacity is preserved, or increases.
this->buffer() == u.buffer() && this->buffer().data() != u.buffer().data()
Linear in `u.size()`.
Strong guarantee. Calls to allocate may throw.
Constructor
static_url() noexcept;
Default constructed urls contain a zero-length string. This matches the grammar for a relative-ref with an empty path and no query or fragment.
static_url< 1024 > u;
this->empty() == true
Constant.
Throws nothing.
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Constructor
static_url(core::string_view s);
This function constructs a url from the string `s`, which must contain a valid URI or relative-ref or else an exception is thrown. The new url retains ownership by making a copy of the passed string.
static_url< 1024 > u( "https://www.example.com" );
return static_url( parse_uri_reference( s ).value() );
this->buffer().data() != s.data()
Linear in `s.size()`.
Exceptions thrown on invalid input.
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Constructor
static_url(static_url const& u) noexcept;
The newly constructed object contains a copy of `u`.
this->buffer() == u.buffer() && this->buffer.data() != u.buffer().data()
Linear in `u.size()`.
Exception thrown if maximum size exceeded.
Constructor
static_url(url_view_base const& u);
The newly constructed object contains a copy of `u`.
this->buffer() == u.buffer() && this->buffer.data() != u.buffer().data()
Linear in `u.size()`.
Exception thrown if capacity exceeded.
Assignment
static_url&
operator=(static_url const& u) noexcept;
The contents of `u` are copied and the previous contents of `this` are discarded. Capacity remains unchanged.
this->buffer() == u.buffer() && this->buffer().data() != u.buffer().data()
Linear in `u.size()`.
Throws nothing.
Assignment
static_url&
operator=(url_view_base const& u);
The contents of `u` are copied and the previous contents of `this` are discarded.
this->buffer() == u.buffer() && this->buffer().data() != u.buffer().data()
Linear in `u.size()`.
Strong guarantee. Exception thrown if capacity exceeded.
Format arguments into a URL
template
url
format(
core::string_view fmt,
Args&&... args);
Format arguments according to the format URL string into a url .
The rules for a format URL string are the same as for a `std::format_string`, where replacement fields are delimited by curly braces.
The URL components to which replacement fields belong are identified before replacement is applied and any invalid characters for that formatted argument are percent-escaped.
Hence, the delimiters between URL components, such as `:`, `//`, `?`, and `#`, should be included in the URL format string. Likewise, a format string with a single `"{}"` is interpreted as a path and any replacement characters invalid in this component will be encoded to form a valid URL.
assert(format("{}", "Hello world!").buffer() == "Hello%20world%21");
All replacement fields must be valid and the resulting URL should be valid after arguments are formatted into the URL.
Because any invalid characters for a URL component are encoded by this function, only replacements in the scheme and port components might be invalid, as these components do not allow percent-encoding of arbitrary characters.
replacement_field ::= "{" [arg_id] [":" (format_spec | chrono_format_spec)] "}"
arg_id ::= integer | identifier
integer ::= digit+
digit ::= "0"..."9"
identifier ::= id_start id_continue*
id_start ::= "a"..."z" | "A"..."Z" | "_"
id_continue ::= id_start | digit
Format arguments into a URL
url
format(
core::string_view fmt,
std::initializer_list args);
Format arguments according to the format URL string into a url .
This overload allows type-erased arguments to be passed as an initializer_list, which is mostly convenient for named parameters.
All arguments must be convertible to a implementation defined type able to store a type-erased reference to any valid format argument.
The rules for a format URL string are the same as for a `std::format_string`, where replacement fields are delimited by curly braces.
The URL components to which replacement fields belong are identified before replacement is applied and any invalid characters for that formatted argument are percent-escaped.
Hence, the delimiters between URL components, such as `:`, `//`, `?`, and `#`, should be included in the URL format string. Likewise, a format string with a single `"{}"` is interpreted as a path and any replacement characters invalid in this component will be encoded to form a valid URL.
assert(format("user/{id}", {{"id", 1}}).buffer() == "user/1");
All replacement fields must be valid and the resulting URL should be valid after arguments are formatted into the URL.
Because any invalid characters for a URL component are encoded by this function, only replacements in the scheme and port components might be invalid, as these components do not allow percent-encoding of arbitrary characters.
replacement_field ::= "{" [arg_id] [":" (format_spec | chrono_format_spec)] "}"
arg_id ::= integer | identifier
integer ::= digit+
digit ::= "0"..."9"
identifier ::= id_start id_continue*
id_start ::= "a"..."z" | "A"..."Z" | "_"
id_continue ::= id_start | digit
Format arguments into a URL
template
void
format_to(
url_base& u,
core::string_view fmt,
Args&&... args);
Format arguments according to the format URL string into a url_base .
The rules for a format URL string are the same as for a `std::format_string`, where replacement fields are delimited by curly braces.
The URL components to which replacement fields belong are identified before replacement is applied and any invalid characters for that formatted argument are percent-escaped.
Hence, the delimiters between URL components, such as `:`, `//`, `?`, and `#`, should be included in the URL format string. Likewise, a format string with a single `"{}"` is interpreted as a path and any replacement characters invalid in this component will be encoded to form a valid URL.
static_url<30> u;
format(u, "{}", "Hello world!");
assert(u.buffer() == "Hello%20world%21");
All replacement fields must be valid and the resulting URL should be valid after arguments are formatted into the URL.
Because any invalid characters for a URL component are encoded by this function, only replacements in the scheme and port components might be invalid, as these components do not allow percent-encoding of arbitrary characters.
Strong guarantee.
replacement_field ::= "{" [arg_id] [":" (format_spec | chrono_format_spec)] "}"
arg_id ::= integer | identifier
integer ::= digit+
digit ::= "0"..."9"
identifier ::= id_start id_continue*
id_start ::= "a"..."z" | "A"..."Z" | "_"
id_continue ::= id_start | digit
Format arguments into a URL
void
format_to(
url_base& u,
core::string_view fmt,
std::initializer_list args);
Format arguments according to the format URL string into a url_base .
This overload allows type-erased arguments to be passed as an initializer_list, which is mostly convenient for named parameters.
All arguments must be convertible to a implementation defined type able to store a type-erased reference to any valid format argument.
The rules for a format URL string are the same as for a `std::format_string`, where replacement fields are delimited by curly braces.
The URL components to which replacement fields belong are identified before replacement is applied and any invalid characters for that formatted argument are percent-escaped.
Hence, the delimiters between URL components, such as `:`, `//`, `?`, and `#`, should be included in the URL format string. Likewise, a format string with a single `"{}"` is interpreted as a path and any replacement characters invalid in this component will be encoded to form a valid URL.
static_url<30> u;
format_to(u, "user/{id}", {{"id", 1}})
assert(u.buffer() == "user/1");
All replacement fields must be valid and the resulting URL should be valid after arguments are formatted into the URL.
Because any invalid characters for a URL component are encoded by this function, only replacements in the scheme and port components might be invalid, as these components do not allow percent-encoding of arbitrary characters.
Strong guarantee.
replacement_field ::= "{" [arg_id] [":" (format_spec | chrono_format_spec)] "}"
arg_id ::= integer | identifier
integer ::= digit+
digit ::= "0"..."9"
identifier ::= id_start id_continue*
id_start ::= "a"..."z" | "A"..."Z" | "_"
id_continue ::= id_start | digit
constexpr
hash() = default;
constexpr
hash(hash const&) = default;
hash(size_t salt) noexcept;
constexpr
hash() = default;
constexpr
hash(hash const&) = default;
hash(size_t salt) noexcept;
hash() = default;
hash(hash const&) = default;
hash(size_t salt) noexcept;