mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 05:25:13 +00:00
AK: Add URL::create_with_url_or_path()
This is an utility to create a URL from a given string, which may be either a URL such as http://example.com (which will be used as-is), or a file path such as /etc/fstab (which will be transformed into file:///etc/fstab).
This commit is contained in:
parent
5a96a6565b
commit
0aeff9c0c4
Notes:
sideshowbarker
2024-07-19 07:28:54 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/0aeff9c0c45 Pull-request: https://github.com/SerenityOS/serenity/pull/1866
2 changed files with 11 additions and 0 deletions
10
AK/URL.cpp
10
AK/URL.cpp
|
@ -297,4 +297,14 @@ URL URL::create_with_file_protocol(const String& path)
|
|||
return url;
|
||||
}
|
||||
|
||||
URL URL::create_with_url_or_path(const String& url_or_path)
|
||||
{
|
||||
URL url = url_or_path;
|
||||
if (url.is_valid())
|
||||
return url;
|
||||
|
||||
String path = canonicalized_path(url_or_path);
|
||||
return URL::create_with_file_protocol(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
1
AK/URL.h
1
AK/URL.h
|
@ -65,6 +65,7 @@ public:
|
|||
|
||||
URL complete_url(const String&) const;
|
||||
|
||||
static URL create_with_url_or_path(const String& url_or_path);
|
||||
static URL create_with_file_protocol(const String& path);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue