From 79eee65372ef18a8add85646f8263cdf69180b92 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Apr 2020 22:02:04 +0200 Subject: [PATCH] AK: Add URL::create_with_file_protocol(path) This is a convenience helper that allows you to easily construct a file:// URL from an absolute path. --- AK/URL.cpp | 8 ++++++++ AK/URL.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/AK/URL.cpp b/AK/URL.cpp index 62e23e062c..329f13f07c 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -287,4 +287,12 @@ bool URL::compute_validity() const return true; } +URL URL::create_with_file_protocol(const String& path) +{ + URL url; + url.set_protocol("file"); + url.set_path(path); + return url; +} + } diff --git a/AK/URL.h b/AK/URL.h index 7cc82d83be..4f827cbd03 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -65,6 +65,8 @@ public: URL complete_url(const String&) const; + static URL create_with_file_protocol(const String& path); + private: bool parse(const StringView&); bool compute_validity() const;