diff options
Diffstat (limited to 'AK')
-rw-r--r-- | AK/LexicalPath.cpp | 11 | ||||
-rw-r--r-- | AK/LexicalPath.h | 12 |
2 files changed, 23 insertions, 0 deletions
diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp index e4dbf706ff..0e18d00365 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 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(); |