From 69f5f406172bd722f3905aea606db598faccb9d3 Mon Sep 17 00:00:00 2001 From: stasoid Date: Fri, 15 Nov 2024 16:20:53 +0500 Subject: [PATCH] AK: Add static bool LexicalPath::is_absolute_path(StringView path); --- AK/LexicalPath.cpp | 4 ++-- AK/LexicalPath.h | 3 ++- AK/LexicalPathWindows.cpp | 11 +++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp index ab492db3eca..91b8106dd0f 100644 --- a/AK/LexicalPath.cpp +++ b/AK/LexicalPath.cpp @@ -58,9 +58,9 @@ LexicalPath::LexicalPath(ByteString path) } } -bool LexicalPath::is_absolute() const +bool LexicalPath::is_absolute_path(StringView path) { - return m_string.starts_with('/'); + return path.starts_with('/'); } Vector LexicalPath::parts() const diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h index 0053c439b42..d23638aff82 100644 --- a/AK/LexicalPath.h +++ b/AK/LexicalPath.h @@ -26,7 +26,8 @@ public: explicit LexicalPath(ByteString); - bool is_absolute() const; + static bool is_absolute_path(StringView path); + bool is_absolute() const { return is_absolute_path(m_string); } ByteString const& string() const { return m_string; } StringView dirname() const { return m_dirname; } diff --git a/AK/LexicalPathWindows.cpp b/AK/LexicalPathWindows.cpp index c86f224b46c..8ea9cf47076 100644 --- a/AK/LexicalPathWindows.cpp +++ b/AK/LexicalPathWindows.cpp @@ -10,14 +10,9 @@ namespace AK { -static bool is_absolute_path(StringView path) -{ - return path.length() >= 2 && path[1] == ':'; -} - static bool is_root(auto const& parts) { - return parts.size() == 1 && is_absolute_path(parts[0]); + return parts.size() == 1 && LexicalPath::is_absolute_path(parts[0]); } LexicalPath::LexicalPath(ByteString path) @@ -45,9 +40,9 @@ LexicalPath::LexicalPath(ByteString path) } } -bool LexicalPath::is_absolute() const +bool LexicalPath::is_absolute_path(StringView path) { - return is_absolute_path(m_string); + return path.length() >= 2 && path[1] == ':'; } Vector LexicalPath::parts() const