mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
AK: Add URL::create_with_help_scheme
helper function
This commit is contained in:
parent
95541d7064
commit
a7fe3183f5
17
AK/URL.cpp
17
AK/URL.cpp
|
@ -178,6 +178,23 @@ URL URL::create_with_file_scheme(String const& path, String const& fragment, Str
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URL URL::create_with_help_scheme(String const& path, String const& fragment, String const& hostname)
|
||||||
|
{
|
||||||
|
LexicalPath lexical_path(path);
|
||||||
|
|
||||||
|
URL url;
|
||||||
|
url.set_scheme("help");
|
||||||
|
// NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
|
||||||
|
// This is because a file URL always needs a non-null hostname.
|
||||||
|
url.set_host(hostname.is_null() || hostname == "localhost" ? String::empty() : hostname);
|
||||||
|
url.set_paths(lexical_path.parts());
|
||||||
|
// NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment.
|
||||||
|
if (path.ends_with('/'))
|
||||||
|
url.append_path("");
|
||||||
|
url.set_fragment(fragment);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
URL URL::create_with_url_or_path(String const& url_or_path)
|
URL URL::create_with_url_or_path(String const& url_or_path)
|
||||||
{
|
{
|
||||||
URL url = url_or_path;
|
URL url = url_or_path;
|
||||||
|
|
1
AK/URL.h
1
AK/URL.h
|
@ -98,6 +98,7 @@ public:
|
||||||
static URL create_with_url_or_path(String const&);
|
static URL create_with_url_or_path(String const&);
|
||||||
static URL create_with_file_scheme(String const& path, String const& fragment = {}, String const& hostname = {});
|
static URL create_with_file_scheme(String const& path, String const& fragment = {}, String const& hostname = {});
|
||||||
static URL create_with_file_protocol(String const& path, String const& fragment = {}) { return create_with_file_scheme(path, fragment); }
|
static URL create_with_file_protocol(String const& path, String const& fragment = {}) { return create_with_file_scheme(path, fragment); }
|
||||||
|
static URL create_with_help_scheme(String const& path, String const& fragment = {}, String const& hostname = {});
|
||||||
static URL create_with_data(String mime_type, String payload, bool is_base64 = false) { return URL(move(mime_type), move(payload), is_base64); };
|
static URL create_with_data(String mime_type, String payload, bool is_base64 = false) { return URL(move(mime_type), move(payload), is_base64); };
|
||||||
|
|
||||||
static bool scheme_requires_port(StringView);
|
static bool scheme_requires_port(StringView);
|
||||||
|
|
Loading…
Reference in a new issue