diff options
Diffstat (limited to 'AK')
-rw-r--r-- | AK/LexicalPath.cpp | 8 | ||||
-rw-r--r-- | AK/LexicalPath.h | 1 |
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> |