diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp index 91b8106dd0f..04c8455d520 100644 --- a/AK/LexicalPath.cpp +++ b/AK/LexicalPath.cpp @@ -63,6 +63,11 @@ bool LexicalPath::is_absolute_path(StringView path) return path.starts_with('/'); } +bool LexicalPath::is_root() const +{ + return m_string == "/"; +} + Vector LexicalPath::parts() const { Vector vector; diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h index d23638aff82..a3a57df6334 100644 --- a/AK/LexicalPath.h +++ b/AK/LexicalPath.h @@ -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; } diff --git a/AK/LexicalPathWindows.cpp b/AK/LexicalPathWindows.cpp index 8ea9cf47076..c6f46162f0b 100644 --- a/AK/LexicalPathWindows.cpp +++ b/AK/LexicalPathWindows.cpp @@ -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 LexicalPath::parts() const { Vector 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;