mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
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>
This commit is contained in:
parent
3f9927b0c3
commit
2de11b0dc8
Notes:
sideshowbarker
2024-07-18 18:17:14 +09:00
Author: https://github.com/sin-ack Commit: https://github.com/SerenityOS/serenity/commit/2de11b0dc8b Pull-request: https://github.com/SerenityOS/serenity/pull/6993 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bgianfo Reviewed-by: https://github.com/gunnarbeutner
2 changed files with 23 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue