summaryrefslogtreecommitdiff
path: root/AK/URL.cpp
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@serenityos.org>2020-04-19 11:55:59 +0300
committerAndreas Kling <kling@serenityos.org>2020-04-19 11:14:26 +0200
commit0aeff9c0c45c086f78af099a7e07a06431347589 (patch)
treecea57def1319b82b7c86e921886c23496fdaa862 /AK/URL.cpp
parent5a96a6565b194ae8323b35db5e3afb64acc8bc80 (diff)
downloadserenity-0aeff9c0c45c086f78af099a7e07a06431347589.zip
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).
Diffstat (limited to 'AK/URL.cpp')
-rw-r--r--AK/URL.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/AK/URL.cpp b/AK/URL.cpp
index d029282b95..8c77031b88 100644
--- a/AK/URL.cpp
+++ b/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);
+}
+
}