summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-09-11 12:55:07 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-10-10 15:18:55 -0700
commit50ad2945275def8ff9d6ccc956f365dfeab520b5 (patch)
treed3903d3573b2eacf7d9a6b07691c768930fb9f68 /AK
parent24e7196158e4673c90aca5c6bff89319d3427282 (diff)
downloadserenity-50ad2945275def8ff9d6ccc956f365dfeab520b5.zip
AK: Implement a way to resolve relative paths lexically
Diffstat (limited to 'AK')
-rw-r--r--AK/LexicalPath.cpp8
-rw-r--r--AK/LexicalPath.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp
index f1bd4c5a72..7a4afdf2ec 100644
--- a/AK/LexicalPath.cpp
+++ b/AK/LexicalPath.cpp
@@ -121,6 +121,14 @@ String LexicalPath::canonicalized_path(String path)
return builder.to_string();
}
+String LexicalPath::absolute_path(String dir_path, String target)
+{
+ if (LexicalPath(target).is_absolute()) {
+ return LexicalPath::canonicalized_path(target);
+ }
+ return LexicalPath::canonicalized_path(join(dir_path, target).string());
+}
+
String LexicalPath::relative_path(StringView const& a_path, StringView const& a_prefix)
{
if (!a_path.starts_with('/') || !a_prefix.starts_with('/')) {
diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h
index a14795d6bf..562adbe83b 100644
--- a/AK/LexicalPath.h
+++ b/AK/LexicalPath.h
@@ -33,6 +33,7 @@ public:
[[nodiscard]] LexicalPath parent() const;
[[nodiscard]] static String canonicalized_path(String);
+ [[nodiscard]] static String absolute_path(String dir_path, String target);
[[nodiscard]] static String relative_path(StringView const& absolute_path, StringView const& prefix);
template<typename... S>