Ada 2.9.2
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
url_search_params.h
Go to the documentation of this file.
1
5#ifndef ADA_URL_SEARCH_PARAMS_H
6#define ADA_URL_SEARCH_PARAMS_H
7
8#include <optional>
9#include <string>
10#include <string_view>
11#include <vector>
12
13namespace ada {
14
16 KEYS,
17 VALUES,
18 ENTRIES,
19};
20
21template <typename T, url_search_params_iter_type Type>
22struct url_search_params_iter;
23
24typedef std::pair<std::string_view, std::string_view> key_value_view_pair;
25
29 url_search_params_iter<std::string_view,
34
39 url_search_params() = default;
40
45 explicit url_search_params(const std::string_view input) {
46 initialize(input);
47 }
48
50 url_search_params(url_search_params &&u) noexcept = default;
53 ~url_search_params() = default;
54
55 [[nodiscard]] inline size_t size() const noexcept;
56
60 inline void append(std::string_view key, std::string_view value);
61
65 inline void remove(std::string_view key);
66 inline void remove(std::string_view key, std::string_view value);
67
71 inline std::optional<std::string_view> get(std::string_view key);
72
76 inline std::vector<std::string> get_all(std::string_view key);
77
81 inline bool has(std::string_view key) noexcept;
82 inline bool has(std::string_view key, std::string_view value) noexcept;
83
87 inline void set(std::string_view key, std::string_view value);
88
92 inline void sort();
93
97 inline std::string to_string() const;
98
107
115
124
129 inline auto begin() const { return params.begin(); }
130 inline auto end() const { return params.end(); }
131 inline auto front() const { return params.front(); }
132 inline auto back() const { return params.back(); }
133 inline auto operator[](size_t index) const { return params[index]; }
134
141 void reset(std::string_view input);
142
143 private:
144 typedef std::pair<std::string, std::string> key_value_pair;
145 std::vector<key_value_pair> params{};
146
150 void initialize(std::string_view init);
151
152 template <typename T, url_search_params_iter_type Type>
154}; // url_search_params
155
162template <typename T, url_search_params_iter_type Type>
164 inline url_search_params_iter() : params(EMPTY) {}
168 default;
171
175 inline std::optional<T> next();
176
177 inline bool has_next() const;
178
179 private:
180 static url_search_params EMPTY;
181 inline url_search_params_iter(url_search_params &params_) : params(params_) {}
182
183 url_search_params &params;
184 size_t pos = 0;
185
186 friend struct url_search_params;
187};
188
189} // namespace ada
190#endif
Definition ada_idna.h:13
url_search_params_iter_type
std::pair< std::string_view, std::string_view > key_value_view_pair
url_search_params_iter(const url_search_params_iter &u)=default
url_search_params_iter & operator=(url_search_params_iter &&u) noexcept=default
url_search_params_iter(url_search_params_iter &&u) noexcept=default
url_search_params_iter & operator=(const url_search_params_iter &u)=default
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)
url_search_params(const url_search_params &u)=default
url_search_params(url_search_params &&u) noexcept=default
auto operator[](size_t index) const
url_search_params_entries_iter get_entries()
std::string to_string() const
url_search_params & operator=(url_search_params &&u) noexcept=default
url_search_params_keys_iter get_keys()
size_t size() const noexcept
url_search_params & operator=(const url_search_params &u)=default
void append(std::string_view key, std::string_view value)
url_search_params(const std::string_view input)
url_search_params_values_iter get_values()
~url_search_params()=default
std::optional< std::string_view > get(std::string_view key)
bool has(std::string_view key) noexcept