diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp index e4dbf706ff7..0e18d00365b 100644 --- a/AK/LexicalPath.cpp +++ b/AK/LexicalPath.cpp @@ -116,4 +116,15 @@ String LexicalPath::relative_path(String absolute_path, const String& prefix) return absolute_path.substring(prefix_length); } +void LexicalPath::append(String const& component) +{ + StringBuilder builder; + builder.append(m_string); + builder.append('/'); + builder.append(component); + + m_string = builder.to_string(); + canonicalize(); +} + } diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h index 20ceadaa0a8..e5c3b2d7333 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 + static LexicalPath join(String const& first, S&&... rest) + { + StringBuilder builder; + builder.append(first); + ((builder.append('/'), builder.append(forward(rest))), ...); + + return LexicalPath { builder.to_string() }; + } + private: void canonicalize();