mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:57:34 +00:00
AK: Add helper functions and private data URL constructor to URL
This adds a few helper functions and a private constructor to instantiate a data URL to the URL class. These will be needed by the upcoming URL parser.
This commit is contained in:
parent
dd392dfa03
commit
8a938a3e25
2 changed files with 20 additions and 0 deletions
|
@ -513,6 +513,12 @@ URL URL::create_with_data(const StringView& mime_type, const StringView& payload
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://url.spec.whatwg.org/#special-scheme
|
||||||
|
bool URL::is_special_scheme(const StringView& scheme)
|
||||||
|
{
|
||||||
|
return scheme.is_one_of("ftp", "file", "http", "https", "ws", "wss");
|
||||||
|
}
|
||||||
|
|
||||||
String URL::basename() const
|
String URL::basename() const
|
||||||
{
|
{
|
||||||
if (!m_valid)
|
if (!m_valid)
|
||||||
|
|
14
AK/URL.h
14
AK/URL.h
|
@ -52,6 +52,9 @@ public:
|
||||||
u16 port() const { return m_port ? m_port : default_port_for_scheme(m_scheme); }
|
u16 port() const { return m_port ? m_port : default_port_for_scheme(m_scheme); }
|
||||||
bool cannot_be_a_base_url() const { return m_cannot_be_a_base_url; }
|
bool cannot_be_a_base_url() const { return m_cannot_be_a_base_url; }
|
||||||
|
|
||||||
|
bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); }
|
||||||
|
bool is_special() const { return is_special_scheme(m_scheme); }
|
||||||
|
|
||||||
void set_scheme(const String&);
|
void set_scheme(const String&);
|
||||||
void set_protocol(const String& protocol) { set_scheme(protocol); }
|
void set_protocol(const String& protocol) { set_scheme(protocol); }
|
||||||
void set_username(const String&);
|
void set_username(const String&);
|
||||||
|
@ -83,8 +86,10 @@ public:
|
||||||
static URL create_with_file_scheme(const String& path, const String& fragment = {});
|
static URL create_with_file_scheme(const String& path, const String& fragment = {});
|
||||||
static URL create_with_file_protocol(const String& path, const String& fragment = {}) { return create_with_file_scheme(path, fragment); }
|
static URL create_with_file_protocol(const String& path, const String& fragment = {}) { return create_with_file_scheme(path, fragment); }
|
||||||
static URL create_with_data(const StringView& mime_type, const StringView& payload, bool is_base64 = false);
|
static URL create_with_data(const StringView& mime_type, const StringView& payload, bool is_base64 = false);
|
||||||
|
|
||||||
static bool scheme_requires_port(const StringView&);
|
static bool scheme_requires_port(const StringView&);
|
||||||
static u16 default_port_for_scheme(const StringView&);
|
static u16 default_port_for_scheme(const StringView&);
|
||||||
|
static bool is_special_scheme(const StringView&);
|
||||||
|
|
||||||
static String percent_encode(const StringView& input, PercentEncodeSet set = PercentEncodeSet::Userinfo);
|
static String percent_encode(const StringView& input, PercentEncodeSet set = PercentEncodeSet::Userinfo);
|
||||||
static String percent_decode(const StringView& input);
|
static String percent_decode(const StringView& input);
|
||||||
|
@ -97,6 +102,15 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
URL(String&& data_mime_type, String&& data_payload, bool payload_is_base64)
|
||||||
|
: m_valid(true)
|
||||||
|
, m_scheme("data")
|
||||||
|
, m_data_payload_is_base64(payload_is_base64)
|
||||||
|
, m_data_mime_type(move(data_mime_type))
|
||||||
|
, m_data_payload(move(data_payload))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool parse(const StringView&);
|
bool parse(const StringView&);
|
||||||
bool compute_validity() const;
|
bool compute_validity() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue