mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
AK: Add LexicalPath::is_root()
This commit is contained in:
parent
77d205571d
commit
a423493dd8
Notes:
github-actions[bot]
2024-11-20 05:08:15 +00:00
Author: https://github.com/stasoid Commit: https://github.com/LadybirdBrowser/ladybird/commit/a423493dd8f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2188 Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 14 additions and 2 deletions
|
@ -63,6 +63,11 @@ bool LexicalPath::is_absolute_path(StringView path)
|
|||
return path.starts_with('/');
|
||||
}
|
||||
|
||||
bool LexicalPath::is_root() const
|
||||
{
|
||||
return m_string == "/";
|
||||
}
|
||||
|
||||
Vector<ByteString> LexicalPath::parts() const
|
||||
{
|
||||
Vector<ByteString> vector;
|
||||
|
|
|
@ -28,6 +28,8 @@ public:
|
|||
|
||||
static bool is_absolute_path(StringView path);
|
||||
bool is_absolute() const { return is_absolute_path(m_string); }
|
||||
bool is_root() const;
|
||||
|
||||
ByteString const& string() const { return m_string; }
|
||||
|
||||
StringView dirname() const { return m_dirname; }
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue