Loading...
Searching...
No Matches
ada::url_search_params Struct Reference

Class for parsing and manipulating URL query strings. More...

`#include <url_search_params.h>`

## Public Member Functions

| url_search_params ()=default
| url_search_params (const std::string_view input)
| url_search_params (const url_search_params &u)=default
| url_search_params (url_search_params &&u) noexcept=default
url_search_params & | operator= (url_search_params &&u) noexcept=default
url_search_params & | operator= (const url_search_params &u)=default
| ~url_search_params ()=default
size_t | size () const noexcept
void | append (std::string_view key, std::string_view value)
void | remove (std::string_view key)
void | remove (std::string_view key, std::string_view value)
std::optional< std::string_view > | get (std::string_view key)
std::vector< std::string > | get_all (std::string_view key)
bool | has (std::string_view key) noexcept
bool | has (std::string_view key, std::string_view value) noexcept
void | set (std::string_view key, std::string_view value)
void | sort ()
std::string | to_string () const
url_search_params_keys_iter | get_keys ()
url_search_params_values_iter | get_values ()
url_search_params_entries_iter | get_entries ()
auto | begin () const
auto | end () const
auto | front () const
auto | back () const
auto | operator[] (size_t index) const

## Friends

template<typename T, url_search_params_iter_type Type>
struct | url_search_params_iter

## Detailed Description

Class for parsing and manipulating URL query strings.

The url_search_params class provides methods to parse, modify, and serialize URL query parameters (the part after '?' in a URL). It handles percent-encoding and decoding automatically.

All string inputs must be valid UTF-8. The caller is responsible for ensuring UTF-8 validity.

See also
  https://url.spec.whatwg.org/#interface-urlsearchparams

Definition at line 60 of file url_search_params.h.

## Constructor & Destructor Documentation

## url_search_params() [1/4]

ada::url_search_params::url_search_params | ( |  | ) |

default

Referenced by operator=(), operator=(), url_search_params(), and url_search_params().

## url_search_params() [2/4]

ada::url_search_params::url_search_params | ( | const std::string_view | input | ) |

inline explicit

Constructs url_search_params by parsing a query string.

Parameters

  input | A query string (with or without leading '?'). Must be UTF-8.

Definition at line 67 of file url_search_params.h.

## url_search_params() [3/4]

ada::url_search_params::url_search_params | ( | const url_search_params & | u | ) |

default

References url_search_params().

## url_search_params() [4/4]

ada::url_search_params::url_search_params | ( | url_search_params && | u | ) |

default noexcept

References url_search_params().

## ~url_search_params()

ada::url_search_params::~url_search_params | ( |  | ) |

default

References append(), get(), get_all(), get_entries(), get_keys(), get_values(), has(), remove(), set(), sort(), and to_string().

## Member Function Documentation

## append()

void ada::url_search_params::append | ( | std::string_view | key,
|  | std::string_view | value )

inline

Appends a new key-value pair to the parameter list.

Parameters

  key | The parameter name (must be valid UTF-8).
  value | The parameter value (must be valid UTF-8).

See also
  https://url.spec.whatwg.org/#dom-urlsearchparams-append

Definition at line 70 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## back()

auto ada::url_search_params::back | ( |  | ) | const

inline

Definition at line 187 of file url_search_params.h.

## begin()

auto ada::url_search_params::begin | ( |  | ) | const

inline

C++ style conventional iterator support. const only because we do not really want the params to be modified via the iterator.

Definition at line 184 of file url_search_params.h.

References begin().

Referenced by begin().

## end()

auto ada::url_search_params::end | ( |  | ) | const

inline

Definition at line 185 of file url_search_params.h.

## front()

auto ada::url_search_params::front | ( |  | ) | const

inline

Definition at line 186 of file url_search_params.h.

## get()

std::optional< std::string_view > ada::url_search_params::get | ( | std::string_view | key | ) |

inline

Returns the value of the first pair with the given key.

Parameters

  key | The parameter name to search for.

Returns
  The value if found, or std::nullopt if not present.

See also
  https://url.spec.whatwg.org/#dom-urlsearchparams-get

Definition at line 77 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## get_all()

std::vector< std::string > ada::url_search_params::get_all | ( | std::string_view | key | ) |

inline

Returns all values for pairs with the given key.

Parameters

  key | The parameter name to search for.

Returns
  A vector of all matching values (may be empty).

See also
  https://url.spec.whatwg.org/#dom-urlsearchparams-getall

Definition at line 89 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## get_entries()

url_search_params_entries_iter ada::url_search_params::get_entries | ( |  | ) |

inline

Returns an iterator over all key-value pairs.

Returns
  An iterator yielding key-value pair views.

Note
  The iterator is invalidated if this object is modified.

See also
  https://url.spec.whatwg.org/#interface-urlsearchparams

Definition at line 258 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## get_keys()

url_search_params_keys_iter ada::url_search_params::get_keys | ( |  | ) |

inline

Returns an iterator over all parameter keys. Keys may repeat if there are duplicate parameters.

Returns
  An iterator yielding string_view keys.

Note
  The iterator is invalidated if this object is modified.

Definition at line 244 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## get_values()

url_search_params_values_iter ada::url_search_params::get_values | ( |  | ) |

inline

Returns an iterator over all parameter values.

Returns
  An iterator yielding string_view values.

Note
  The iterator is invalidated if this object is modified.

See also
  https://url.spec.whatwg.org/#interface-urlsearchparams

Definition at line 251 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## has() [1/2]

bool ada::url_search_params::has | ( | std::string_view | key | ) |

inline noexcept

Checks if any pair has the given key.

Parameters

  key | The parameter name to search for.

Returns
  true if at least one pair has this key.

See also
  https://url.spec.whatwg.org/#dom-urlsearchparams-has

Definition at line 102 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## has() [2/2]

bool ada::url_search_params::has | ( | std::string_view | key,
|  | std::string_view | value )

inline noexcept

Checks if any pair matches the given key and value.

Parameters

  key | The parameter name to search for.
  value | The parameter value to match.

Returns
  true if a matching pair exists.

Definition at line 108 of file url_search_params-inl.h.

## operator=() [1/2]

url_search_params & ada::url_search_params::operator= | ( | const url_search_params & | u | ) |

default

References url_search_params().

## operator=() [2/2]

url_search_params & ada::url_search_params::operator= | ( | url_search_params && | u | ) |

default noexcept

References url_search_params().

## operator[]()

auto ada::url_search_params::operator[] | ( | size_t | index | ) | const

inline

Definition at line 188 of file url_search_params.h.

## remove() [1/2]

void ada::url_search_params::remove | ( | std::string_view | key | ) |

inline

Removes all pairs with the given key.

Parameters

  key | The parameter name to remove.

See also
  https://url.spec.whatwg.org/#dom-urlsearchparams-delete

Definition at line 152 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## remove() [2/2]

void ada::url_search_params::remove | ( | std::string_view | key,
|  | std::string_view | value )

inline

Removes all pairs with the given key and value.

Parameters

  key | The parameter name.
  value | The parameter value to match.

Definition at line 157 of file url_search_params-inl.h.

## set()

void ada::url_search_params::set | ( | std::string_view | key,
|  | std::string_view | value )

inline

Sets a parameter value, replacing any existing pairs with the same key.

Parameters

  key | The parameter name (must be valid UTF-8).
  value | The parameter value (must be valid UTF-8).

See also
  https://url.spec.whatwg.org/#dom-urlsearchparams-set

Definition at line 137 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## size()

size_t ada::url_search_params::size | ( |  | ) | const

inline nodiscard noexcept

Returns the number of key-value pairs.

Returns
  The total count of parameters.

Definition at line 75 of file url_search_params-inl.h.

Referenced by LLVMFuzzerTestOneInput().

## sort()

void ada::url_search_params::sort | ( |  | ) |

inline

Sorts all key-value pairs by their keys using code unit comparison.

See also
  https://url.spec.whatwg.org/#dom-urlsearchparams-sort

Definition at line 164 of file url_search_params-inl.h.

Referenced by ~url_search_params().

## to_string()

std::string ada::url_search_params::to_string | ( |  | ) | const

inline

Serializes the parameters to a query string (without leading '?').

Returns
  The percent-encoded query string.

See also
  https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior

Definition at line 116 of file url_search_params-inl.h.

References ada::character_sets::WWW_FORM_URLENCODED_PERCENT_ENCODE.

Referenced by ~url_search_params().

## Friends And Related Symbol Documentation

## url_search_params_iter

template<typename T, url_search_params_iter_type Type>

friend struct url_search_params_iter

friend

Definition at line 209 of file url_search_params.h.

References url_search_params_iter.

Referenced by url_search_params_iter.

The documentation for this struct was generated from the following files:

- include/ada/url_search_params.h
- include/ada/url_search_params-inl.h