mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:17:35 +00:00
AK: Make LexicalPath immutable
This replaces the current LexicalPath::append() API with a new method that returns a new LexicalPath object and doesn't touch the this-object. With this, LexicalPath is now immutable. It also adds a LexicalPath::parent() method and the relevant test cases.
This commit is contained in:
parent
1e80022282
commit
4c018909f7
3 changed files with 38 additions and 11 deletions
|
@ -137,15 +137,14 @@ String LexicalPath::relative_path(String absolute_path, String const& prefix)
|
|||
return absolute_path.substring(prefix_length);
|
||||
}
|
||||
|
||||
void LexicalPath::append(String const& component)
|
||||
LexicalPath LexicalPath::append(StringView const& value) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append(m_string);
|
||||
builder.append('/');
|
||||
builder.append(component);
|
||||
return LexicalPath::join(m_string, value);
|
||||
}
|
||||
|
||||
m_string = builder.to_string();
|
||||
canonicalize();
|
||||
LexicalPath LexicalPath::parent() const
|
||||
{
|
||||
return append("..");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue