0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::http: Add convenience query string array tool w/ decode.

This commit is contained in:
Jason Volk 2020-04-21 19:41:29 -07:00
parent 17d73eeae7
commit acbbb08d3c
2 changed files with 47 additions and 0 deletions

View file

@ -154,6 +154,9 @@ struct ircd::http::query::string
string_view at(const string_view &key, const size_t &idx = 0) const;
template<class T> T at(const string_view &key, const size_t &idx = 0) const;
vector_view<string_view> array(const mutable_buffer &, const string_view &key, string_view *const &, const size_t &) const;
template<size_t MAX> vector_view<string_view> array(const mutable_buffer &, const string_view &key, string_view (&)[MAX]) const;
size_t count(const string_view &key) const;
bool has(const string_view &key) const;
@ -361,6 +364,16 @@ enum ircd::http::code
CLOUDFLARE_REQUEST_TIMEOUT = 524,
};
template<size_t MAX>
inline ircd::vector_view<ircd::string_view>
ircd::http::query::string::array(const mutable_buffer &buf,
const string_view &key,
string_view (&out)[MAX])
const
{
return array(buf, key, out, MAX);
}
template<class T>
T
ircd::http::query::string::get(const string_view &key,

View file

@ -869,6 +869,40 @@ const
return ret;
}
ircd::vector_view<ircd::string_view>
ircd::http::query::string::array(const mutable_buffer &buf,
const string_view &key,
string_view *const &out,
const size_t &max)
const
{
if(unlikely(!max))
return {};
size_t ret(0);
window_buffer wb(buf);
for_each(key, [&out, &max, &ret, &wb]
(const auto &query)
{
wb([&out, &max, &ret, &query]
(const mutable_buffer &buf)
{
assert(ret < max);
const auto &[_, server_name] {query};
out[ret] = url::decode(buf, server_name);
return out[ret];
});
return ++ret < max;
});
return vector_view<string_view>
{
out, ret
};
}
ircd::string_view
ircd::http::query::string::at(const string_view &key,
const size_t &idx)