1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00
serenity/Userland/Libraries/LibWeb/URL/URLSearchParams.h
Idan Horowitz af5b62d8cd LibWeb: Move url_{encode, decode} to URL/URLSearchParams.{h, cpp}
The new URL built-in that will reside in URL.{h, cpp} will have an
URLSearchParams member, which means it has to include its header, and
as such URLSearchParams.h can't include URL's header, which it needs as
it uses the url_{encode, decode} functions.
2021-09-14 00:14:45 +02:00

54 lines
1.3 KiB
C++

/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/URL.h>
#include <AK/Vector.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/ExceptionOr.h>
namespace Web::URL {
struct QueryParam {
String name;
String value;
};
String url_encode(const Vector<QueryParam>&, AK::URL::PercentEncodeSet);
Vector<QueryParam> url_decode(StringView const&);
class URLSearchParams : public Bindings::Wrappable
, public RefCounted<URLSearchParams> {
public:
using WrapperType = Bindings::URLSearchParamsWrapper;
static NonnullRefPtr<URLSearchParams> create(Vector<QueryParam> list)
{
return adopt_ref(*new URLSearchParams(move(list)));
}
static DOM::ExceptionOr<NonnullRefPtr<URLSearchParams>> create_with_global_object(Bindings::WindowObject&, const String& init);
void append(String const& name, String const& value);
void delete_(String const& name);
String get(String const& name);
bool has(String const& name);
void set(String const& name, String const& value);
void sort();
String to_string();
private:
explicit URLSearchParams(Vector<QueryParam> list)
: m_list(move(list)) {};
void update();
Vector<QueryParam> m_list;
};
}