mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 13:58:11 +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
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);
|
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;
|
bool has_extension(const StringView&) const;
|
||||||
|
|
||||||
|
void append(String const& component);
|
||||||
|
|
||||||
static String canonicalized_path(String);
|
static String canonicalized_path(String);
|
||||||
static String relative_path(String absolute_path, String const& prefix);
|
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:
|
private:
|
||||||
void canonicalize();
|
void canonicalize();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue