5#ifndef ADA_URL_SEARCH_PARAMS_INL_H
6#define ADA_URL_SEARCH_PARAMS_INL_H
22template <
typename T, ada::url_search_params_iter_type Type>
23url_search_params url_search_params_iter<T, Type>::EMPTY;
25inline void url_search_params::reset(std::string_view
input) {
30inline void url_search_params::initialize(std::string_view
input) {
32 input.remove_prefix(1);
38 if (
equal == std::string_view::npos) {
40 std::ranges::replace(
name,
'+',
' ');
41 params.emplace_back(unicode::percent_decode(
name,
name.find(
'%')),
"");
46 std::ranges::replace(
name,
'+',
' ');
47 std::ranges::replace(value,
'+',
' ');
49 params.emplace_back(unicode::percent_decode(
name,
name.find(
'%')),
50 unicode::percent_decode(value, value.find(
'%')));
54 while (!
input.empty()) {
71 const std::string_view value) {
72 params.emplace_back(key, value);
78 const std::string_view key) {
79 auto entry = std::ranges::find_if(
80 params, [&key](
const auto &
param) {
return param.first == key; });
82 if (
entry == params.end()) {
90 const std::string_view key) {
91 std::vector<std::string>
out{};
93 for (
auto &
param : params) {
94 if (
param.first == key) {
103 auto entry = std::ranges::find_if(
104 params, [&key](
const auto &
param) {
return param.first == key; });
105 return entry != params.end();
109 std::string_view value)
noexcept {
110 auto entry = std::ranges::find_if(params, [&key, &value](
const auto &
param) {
111 return param.first == key &&
param.second == value;
113 return entry != params.end();
119 for (
size_t i = 0;
i < params.size();
i++) {
124 std::ranges::replace(key,
' ',
'+');
125 std::ranges::replace(value,
' ',
'+');
138 const std::string_view value) {
139 const auto find = [&key](
const auto &
param) {
return param.first == key; };
141 auto it = std::ranges::find_if(params,
find);
143 if (
it == params.end()) {
144 params.emplace_back(key, value);
147 params.erase(std::remove_if(std::next(
it), params.end(),
find),
153 std::erase_if(params,
154 [&key](
const auto &
param) {
return param.first == key; });
158 const std::string_view value) {
159 std::erase_if(params, [&key, &value](
const auto &
param) {
160 return param.first == key &&
param.second == value;
167 std::ranges::stable_sort(params, [](
const key_value_pair &
lhs,
168 const key_value_pair &
rhs) {
173 uint32_t codePoint1 = 0, codePoint2 = 0;
175 if (low_surrogate1 != 0) {
176 codePoint1 = low_surrogate1;
179 uint8_t c1 = uint8_t(lhs.first[i]);
180 if (c1 > 0x7F && c1 <= 0xDF && i + 1 < lhs.first.size()) {
181 codePoint1 = ((c1 & 0x1F) << 6) | (uint8_t(lhs.first[i + 1]) & 0x3F);
183 }
else if (
c1 > 0xDF &&
c1 <= 0xEF &&
i + 2 <
lhs.first.size()) {
184 codePoint1 = ((c1 & 0x0F) << 12) |
185 ((uint8_t(lhs.first[i + 1]) & 0x3F) << 6) |
186 (uint8_t(lhs.first[i + 2]) & 0x3F);
188 }
else if (
c1 > 0xEF &&
c1 <= 0xF7 &&
i + 3 <
lhs.first.size()) {
189 codePoint1 = ((c1 & 0x07) << 18) |
190 ((uint8_t(lhs.first[i + 1]) & 0x3F) << 12) |
191 ((uint8_t(lhs.first[i + 2]) & 0x3F) << 6) |
192 (uint8_t(lhs.first[i + 3]) & 0x3F);
195 codePoint1 -= 0x10000;
196 uint16_t high_surrogate = uint16_t(0xD800 + (codePoint1 >> 10));
197 low_surrogate1 = uint16_t(0xDC00 + (codePoint1 & 0x3FF));
198 codePoint1 = high_surrogate;
211 if (
c2 > 0x7F &&
c2 <= 0xDF &&
j + 1 <
rhs.first.size()) {
214 }
else if (
c2 > 0xDF &&
c2 <= 0xEF &&
j + 2 <
rhs.first.size()) {
219 }
else if (
c2 > 0xEF &&
c2 <= 0xF7 &&
j + 3 <
rhs.first.size()) {
262template <
typename T, url_search_params_iter_type Type>
264 return pos < params.params.
size();
268inline std::optional<std::string_view> url_search_params_keys_iter::next() {
272 return params.params[pos++].first;
276inline std::optional<std::string_view> url_search_params_values_iter::next() {
280 return params.params[pos++].second;
284inline std::optional<key_value_view_pair>
285url_search_params_entries_iter::next() {
289 return params.params[pos++];
Definitions of the character sets used by unicode functions.
constexpr uint8_t WWW_FORM_URLENCODED_PERCENT_ENCODE[32]
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
JavaScript-style iterator for url_search_params.
void set(std::string_view key, std::string_view value)
std::vector< std::string > get_all(std::string_view key)
void remove(std::string_view key)
std::string to_string() const
size_t size() const noexcept
void append(std::string_view key, std::string_view value)
std::optional< std::string_view > get(std::string_view key)
bool has(std::string_view key) noexcept
Definitions for all unicode specific functions.
Declaration for the URL Search Params.