Ada 2.8.0
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 url_search_params(const std::string_view input) { initialize(input); }
46
48 url_search_params(url_search_params &&u) noexcept = default;
51 ~url_search_params() = default;
52
53 [[nodiscard]] inline size_t size() const noexcept;
54
58 inline void append(std::string_view key, std::string_view value);
59
63 inline void remove(std::string_view key);
64 inline void remove(std::string_view key, std::string_view value);
65
69 inline std::optional<std::string_view> get(std::string_view key);
70
74 inline std::vector<std::string> get_all(std::string_view key);
75
79 inline bool has(std::string_view key) noexcept;
80 inline bool has(std::string_view key, std::string_view value) noexcept;
81
85 inline void set(std::string_view key, std::string_view value);
86
90 inline void sort();
91
95 inline std::string to_string() const;
96
105
113
122
127 inline auto begin() const { return params.begin(); }
128 inline auto end() const { return params.end(); }
129 inline auto front() const { return params.front(); }
130 inline auto back() const { return params.back(); }
131 inline auto operator[](size_t index) const { return params[index]; }
132
133 private:
134 typedef std::pair<std::string, std::string> key_value_pair;
135 std::vector<key_value_pair> params{};
136
140 void initialize(std::string_view init);
141
142 template <typename T, url_search_params_iter_type Type>
144}; // url_search_params
145
152template <typename T, url_search_params_iter_type Type>
154 inline url_search_params_iter() : params(EMPTY) {}
158 default;
161
165 inline std::optional<T> next();
166
167 inline bool has_next();
168
169 private:
170 static url_search_params EMPTY;
171 inline url_search_params_iter(url_search_params &params_) : params(params_) {}
172
173 url_search_params &params;
174 size_t pos = 0;
175
176 friend struct url_search_params;
177};
178
179} // namespace ada
180#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