1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08: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:
Sergey Bugaev 2020-04-19 11:55:59 +03:00 committed by Andreas Kling
parent 5a96a6565b
commit 0aeff9c0c4
2 changed files with 11 additions and 0 deletions

View file

@ -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);
}
}