AK: Add LexicalPath::is_root()

This commit is contained in:
stasoid 2024-11-15 19:00:57 +05:00 committed by Andrew Kaster
commit a423493dd8
Notes: github-actions[bot] 2024-11-20 05:08:15 +00:00
3 changed files with 14 additions and 2 deletions

View file

@ -45,6 +45,11 @@ bool LexicalPath::is_absolute_path(StringView path)
return path.length() >= 2 && path[1] == ':';
}
bool LexicalPath::is_root() const
{
return AK::is_root(m_parts);
}
Vector<ByteString> LexicalPath::parts() const
{
Vector<ByteString> vector;
@ -81,7 +86,7 @@ ByteString LexicalPath::canonicalized_path(ByteString path)
continue;
if (part == ".." && !canonical_parts.is_empty()) {
// At the root, .. does nothing.
if (is_root(canonical_parts))
if (AK::is_root(canonical_parts))
continue;
// A .. and a previous non-.. part cancel each other.
if (canonical_parts.last() != "..") {
@ -95,7 +100,7 @@ ByteString LexicalPath::canonicalized_path(ByteString path)
StringBuilder builder;
builder.join('\\', canonical_parts);
// "X:" -> "X:\"
if (is_root(canonical_parts))
if (AK::is_root(canonical_parts))
builder.append('\\');
path = builder.to_byte_string();
return path == "" ? "." : path;