diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-05-12 19:17:39 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-12 22:38:20 +0200 |
commit | 2de11b0dc8bbaa0c264a7e6dbb32b5481a337fb8 (patch) | |
tree | 54ebe5f2b5b9cf5106c830516654f7e53d9218ef /AK/LexicalPath.h | |
parent | 3f9927b0c36d31270781ded6fccf97a7f1beb82e (diff) | |
download | serenity-2de11b0dc8bbaa0c264a7e6dbb32b5481a337fb8.zip |
AK: Add LexicalPath::append and LexicalPath::join
This patch adds two new methods to LexicalPath. LexicalPath::append
appends a new path component to a LexicalPath, and LexicalPath::join
constructs a new LexicalPath from one or more components.
Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
Diffstat (limited to 'AK/LexicalPath.h')
-rw-r--r-- | AK/LexicalPath.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h index 20ceadaa0a..e5c3b2d733 100644 --- a/AK/LexicalPath.h +++ b/AK/LexicalPath.h @@ -29,9 +29,21 @@ public: bool has_extension(const StringView&) const; + void append(String const& component); + static String canonicalized_path(String); static String relative_path(String absolute_path, String const& prefix); + template<typename... S> + static LexicalPath join(String const& first, S&&... rest) + { + StringBuilder builder; + builder.append(first); + ((builder.append('/'), builder.append(forward<S>(rest))), ...); + + return LexicalPath { builder.to_string() }; + } + private: void canonicalize(); |