Upa URL C++ library
A WHATWG URL Standard implementation
Loading...
Searching...
No Matches
upa::url_search_params Class Reference

URLSearchParams class. More...

#include <upa/url_search_params.h>

Public Types

using name_value_pair = std::pair<std::string, std::string>
using name_value_list = std::list<name_value_pair>
using const_iterator = name_value_list::const_iterator
using const_reverse_iterator = name_value_list::const_reverse_iterator
using iterator = const_iterator
using reverse_iterator = const_reverse_iterator
using size_type = name_value_list::size_type
using value_type = name_value_pair

Public Member Functions

 url_search_params ()=default
 Default constructor.
 url_search_params (const url_search_params &other)
 Copy constructor.
 url_search_params (url_search_params &&other) noexcept(std::is_nothrow_move_constructible_v< name_value_list >)
 Move constructor.
template<class StrT, enable_if_str_arg_t< StrT > = 0>
 url_search_params (StrT &&query)
 Parsing constructor.
template<class ConT, detail::enable_if_not_base_of_t< url_search_params, ConT > = 0, std::enable_if_t< detail::is_iterable_pairs_v< ConT >, int > = 0>
 url_search_params (ConT &&cont)
 ~url_search_params ()=default
 destructor
url_search_paramsoperator= (const url_search_params &other)
 Copy assignment.
url_search_paramsoperator= (url_search_params &&other) noexcept
 Move assignment.
url_search_paramssafe_assign (url_search_params &&other)
 Safe move assignment.
void clear ()
 Clears parameters.
void swap (url_search_params &other) noexcept
 Swaps the contents of two url_search_params.
template<class StrT, enable_if_str_arg_t< StrT > = 0>
void parse (StrT &&query)
template<class TN, class TV>
void append (TN &&name, TV &&value)
template<class TN>
void del (const TN &name)
template<class TN, class TV>
void del (const TN &name, const TV &value)
template<class TN>
size_type remove (const TN &name)
template<class TN, class TV>
size_type remove (const TN &name, const TV &value)
template<class UnaryPredicate>
size_type remove_if (UnaryPredicate p)
template<class TN>
const std::string * get (const TN &name) const
template<class TN>
std::list< std::string > get_all (const TN &name) const
template<class TN>
bool has (const TN &name) const
template<class TN, class TV>
bool has (const TN &name, const TV &value) const
template<class TN, class TV>
void set (TN &&name, TV &&value)
void sort ()
void serialize (std::string &query) const
std::string to_string () const
const_iterator begin () const noexcept
const_iterator cbegin () const noexcept
const_iterator end () const noexcept
const_iterator cend () const noexcept
const_reverse_iterator rbegin () const noexcept
const_reverse_iterator crbegin () const noexcept
const_reverse_iterator rend () const noexcept
const_reverse_iterator crend () const noexcept
bool empty () const noexcept
size_type size () const noexcept

Static Public Member Functions

template<class StrT, enable_if_str_arg_t< StrT > = 0>
static name_value_list do_parse (bool rem_qmark, StrT &&query)
template<class StrT, enable_if_str_arg_t< StrT > = 0>
static void urlencode (std::string &encoded, StrT &&value)

Friends

class url
class detail::url_search_params_ptr
std::ostream & operator<< (std::ostream &os, const url_search_params &usp)
 Performs stream output on URL search parameters.

Detailed Description

URLSearchParams class.

Follows specification in https://url.spec.whatwg.org/#interface-urlsearchparams

Definition at line 71 of file url_search_params.h.

Member Typedef Documentation

◆ const_iterator

using upa::url_search_params::const_iterator = name_value_list::const_iterator

Definition at line 77 of file url_search_params.h.

◆ const_reverse_iterator

using upa::url_search_params::const_reverse_iterator = name_value_list::const_reverse_iterator

Definition at line 78 of file url_search_params.h.

◆ iterator

◆ name_value_list

Definition at line 76 of file url_search_params.h.

◆ name_value_pair

using upa::url_search_params::name_value_pair = std::pair<std::string, std::string>

Definition at line 75 of file url_search_params.h.

◆ reverse_iterator

◆ size_type

using upa::url_search_params::size_type = name_value_list::size_type

Definition at line 81 of file url_search_params.h.

◆ value_type

Constructor & Destructor Documentation

◆ url_search_params() [1/5]

upa::url_search_params::url_search_params ( )
default

Default constructor.

Constructs empty url_search_params object.

◆ url_search_params() [2/5]

upa::url_search_params::url_search_params ( const url_search_params & other)
inline

Copy constructor.

Parameters
[in]otherurl_search_params object to copy from

Definition at line 442 of file url_search_params.h.

◆ url_search_params() [3/5]

upa::url_search_params::url_search_params ( url_search_params && other)
inlinenoexcept

Move constructor.

Constructs the url_search_params object with the contents of other using move semantics.

Parameters
[in,out]otherurl_search_params object to move from

Definition at line 449 of file url_search_params.h.

◆ url_search_params() [4/5]

template<class StrT, enable_if_str_arg_t< StrT > = 0>
upa::url_search_params::url_search_params ( StrT && query)
inlineexplicit

Parsing constructor.

Initializes name-value pairs list by parsing query string.

Parameters
[in]querystring to parse

Definition at line 111 of file url_search_params.h.

◆ url_search_params() [5/5]

template<class ConT, detail::enable_if_not_base_of_t< url_search_params, ConT > = 0, std::enable_if_t< detail::is_iterable_pairs_v< ConT >, int > = 0>
upa::url_search_params::url_search_params ( ConT && cont)
inlineexplicit

Initializes name-value pairs list by copying pairs fron container.

Parameters
[in]contname-value pairs container

Definition at line 123 of file url_search_params.h.

◆ ~url_search_params()

upa::url_search_params::~url_search_params ( )
default

destructor

Member Function Documentation

◆ append()

template<class TN, class TV>
void upa::url_search_params::append ( TN && name,
TV && value )
inline

Appends given name-value pair to list

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-append

Parameters
[in]name
[in]value

Definition at line 522 of file url_search_params.h.

◆ begin()

const_iterator upa::url_search_params::begin ( ) const
inlinenodiscardnoexcept
Returns
an iterator to the beginning of name-value list

Definition at line 311 of file url_search_params.h.

◆ cbegin()

const_iterator upa::url_search_params::cbegin ( ) const
inlinenodiscardnoexcept
Returns
an iterator to the beginning of name-value list

Definition at line 314 of file url_search_params.h.

◆ cend()

const_iterator upa::url_search_params::cend ( ) const
inlinenodiscardnoexcept
Returns
an iterator to the end of name-value list

Definition at line 320 of file url_search_params.h.

◆ clear()

void upa::url_search_params::clear ( )
inline

Clears parameters.

Definition at line 479 of file url_search_params.h.

◆ crbegin()

const_reverse_iterator upa::url_search_params::crbegin ( ) const
inlinenodiscardnoexcept
Returns
a reverse iterator to the beginning of name-value list

Definition at line 326 of file url_search_params.h.

◆ crend()

const_reverse_iterator upa::url_search_params::crend ( ) const
inlinenodiscardnoexcept
Returns
a reverse iterator to the end of name-value list

Definition at line 332 of file url_search_params.h.

◆ del() [1/2]

template<class TN>
void upa::url_search_params::del ( const TN & name)
inline

Remove all name-value pairs whose name is name from list.

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-delete

Parameters
[in]name

Definition at line 532 of file url_search_params.h.

◆ del() [2/2]

template<class TN, class TV>
void upa::url_search_params::del ( const TN & name,
const TV & value )
inline

Remove all name-value pairs whose name is name and value is value from list.

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-delete

Parameters
[in]name
[in]value

Definition at line 542 of file url_search_params.h.

◆ do_parse()

template<class StrT, enable_if_str_arg_t< StrT >>
url_search_params::name_value_list upa::url_search_params::do_parse ( bool rem_qmark,
StrT && query )
inlinestaticnodiscard

Initializes and returns name-value pairs list by parsing query string.

Parameters
[in]rem_qmarkif it is true and the query starts with U+003F (?), then skips first code point in query
[in]querystring to parse

Definition at line 669 of file url_search_params.h.

◆ empty()

bool upa::url_search_params::empty ( ) const
inlinenodiscardnoexcept

Checks whether the name-value list is empty

Returns
true if the container is empty, false otherwise

Definition at line 339 of file url_search_params.h.

◆ end()

const_iterator upa::url_search_params::end ( ) const
inlinenodiscardnoexcept
Returns
an iterator to the end of name-value list

Definition at line 317 of file url_search_params.h.

◆ get()

template<class TN>
const std::string * upa::url_search_params::get ( const TN & name) const
inlinenodiscard

Returns value of the first name-value pair whose name is name, or nullptr, if there isn't such pair.

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-get

Parameters
[in]name
Returns
pair value, or nullptr

Definition at line 585 of file url_search_params.h.

◆ get_all()

template<class TN>
std::list< std::string > upa::url_search_params::get_all ( const TN & name) const
inlinenodiscard

Return the values of all name-value pairs whose name is name.

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-getall

Parameters
[in]name
Returns
list of values as std::string

Definition at line 595 of file url_search_params.h.

◆ has() [1/2]

template<class TN>
bool upa::url_search_params::has ( const TN & name) const
inlinenodiscard

Tests if list contains a name-value pair whose name is name.

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-has

Parameters
[in]name
Returns
true, if list contains such pair, false otherwise

Definition at line 606 of file url_search_params.h.

◆ has() [2/2]

template<class TN, class TV>
bool upa::url_search_params::has ( const TN & name,
const TV & value ) const
inlinenodiscard

Tests if list contains a name-value pair whose name is name and value is value.

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-has

Parameters
[in]name
[in]value
Returns
true, if list contains such pair, false otherwise

Definition at line 616 of file url_search_params.h.

◆ operator=() [1/2]

url_search_params & upa::url_search_params::operator= ( const url_search_params & other)
inline

Copy assignment.

Replaces the contents with those of other using copy semantics.

Updates linked URL object if any. So this operator can be used to assign a value to the reference returned by url::search_params().

Parameters
[in]otherurl_search_params to copy from
Returns
*this

Definition at line 457 of file url_search_params.h.

◆ operator=() [2/2]

url_search_params & upa::url_search_params::operator= ( url_search_params && other)
inlinenoexcept

Move assignment.

Replaces the contents with those of other using move semantics.

NOTE: It is undefined behavior to use this operator to assign a value to the reference returned by url::search_params(). Use safe_assign instead.

Parameters
[in,out]otherurl_search_params to move to this object
Returns
*this

Definition at line 465 of file url_search_params.h.

◆ parse()

template<class StrT, enable_if_str_arg_t< StrT >>
void upa::url_search_params::parse ( StrT && query)
inline

Initializes name-value pairs list by parsing query string.

Parameters
[in]querystring to parse

Definition at line 515 of file url_search_params.h.

◆ rbegin()

const_reverse_iterator upa::url_search_params::rbegin ( ) const
inlinenodiscardnoexcept
Returns
a reverse iterator to the beginning of name-value list

Definition at line 323 of file url_search_params.h.

◆ remove() [1/2]

template<class TN>
url_search_params::size_type upa::url_search_params::remove ( const TN & name)
inline

Remove all name-value pairs whose name is name from list.

It updates connected URL only if something is removed.

Parameters
[in]name
Returns
the number of pairs removed

Definition at line 553 of file url_search_params.h.

◆ remove() [2/2]

template<class TN, class TV>
url_search_params::size_type upa::url_search_params::remove ( const TN & name,
const TV & value )
inline

Remove all name-value pairs whose name is name and value is value from list.

It updates connected URL only if something is removed.

Parameters
[in]name
[in]value
Returns
the number of pairs removed

Definition at line 562 of file url_search_params.h.

◆ remove_if()

template<class UnaryPredicate>
url_search_params::size_type upa::url_search_params::remove_if ( UnaryPredicate p)
inline

Remove all name-value pairs for which predicate p returns true.

It updates connected URL only if something is removed.

Parameters
[in]punary predicate which returns value of bool type and has const value_type& parameter
Returns
the number of pairs removed

Definition at line 572 of file url_search_params.h.

◆ rend()

const_reverse_iterator upa::url_search_params::rend ( ) const
inlinenodiscardnoexcept
Returns
a reverse iterator to the end of name-value list

Definition at line 329 of file url_search_params.h.

◆ safe_assign()

url_search_params & upa::url_search_params::safe_assign ( url_search_params && other)
inline

Safe move assignment.

Replaces the contents with those of other using move semantics.

Updates linked URL object if any. So this function can be used to assign a value to the reference returned by url::search_params().

Parameters
[in,out]otherURL to move to this object
Returns
*this

Definition at line 471 of file url_search_params.h.

◆ serialize()

void upa::url_search_params::serialize ( std::string & query) const
inline

Serializes name-value pairs to string and appends it to query.

Parameters
[in,out]query

Definition at line 739 of file url_search_params.h.

◆ set()

template<class TN, class TV>
void upa::url_search_params::set ( TN && name,
TV && value )
inline

Sets search parameter value

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-set

Parameters
[in]name
[in]value

Definition at line 628 of file url_search_params.h.

◆ size()

size_type upa::url_search_params::size ( ) const
inlinenodiscardnoexcept
Returns
the number of elements in the name-value list

Definition at line 342 of file url_search_params.h.

◆ sort()

void upa::url_search_params::sort ( )
inline

Sort all name-value pairs, by their names.

Sorting is done by comparison of code units. The relative order between name-value pairs with equal names is preserved.

More info: https://url.spec.whatwg.org/#dom-urlsearchparams-sort

Definition at line 650 of file url_search_params.h.

◆ swap()

void upa::url_search_params::swap ( url_search_params & other)
inlinenoexcept

Swaps the contents of two url_search_params.

NOTE: It is undefined behavior to use this function to swap the contents of references returned by url::search_params().

Parameters
[in,out]otherurl_search_params to exchange the contents with

Definition at line 485 of file url_search_params.h.

◆ to_string()

std::string upa::url_search_params::to_string ( ) const
inlinenodiscard

Serializes name-value pairs to string.

More info: https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior

Returns
serialized name-value pairs

Definition at line 753 of file url_search_params.h.

◆ urlencode()

template<class StrT, enable_if_str_arg_t< StrT >>
void upa::url_search_params::urlencode ( std::string & encoded,
StrT && value )
inlinestatic

Percent encodes the value using application/x-www-form-urlencoded percent-encode set, and replacing 0x20 (SP) with U+002B (+). Appends result to the encoded string.

Parameters
[in,out]encodedstring to append percent encoded value
[in]valuestring value to percent encode

Definition at line 734 of file url_search_params.h.

◆ detail::url_search_params_ptr

friend class detail::url_search_params_ptr
friend

Definition at line 375 of file url_search_params.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const url_search_params & usp )
friend

Performs stream output on URL search parameters.

Outputs URL search parameters serialized to application/x-www-form-urlencoded

Parameters
[in]osthe output stream to write to
[in]uspthe url_search_params object to serialize and output
Returns
a reference to the output stream
See also
https://url.spec.whatwg.org/#urlencoded-serializing

Definition at line 771 of file url_search_params.h.

◆ url

friend class url
friend

Definition at line 374 of file url_search_params.h.


The documentation for this class was generated from the following file: