1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 02:13:56 +09:00

AK: Port LexicalPath to Windows

Supported:
* Normal absolute and relative paths: C:\Windows\Fonts, AK\LexicalPath.h
* Forward slashes and multiple separators: C:/Windows///\\\notepad.exe

Not supported:
* Paths starting with two backslashes: \\?\C:\Windows, \\server\share
* Unusual relative paths like C:, C:a\b, \, \a\b

More on Windows path formats: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
This commit is contained in:
stasoid 2024-10-22 22:47:51 +05:00 committed by Andrew Kaster
parent 9ebed7d8d5
commit f026d495cd
Notes: github-actions[bot] 2024-11-09 19:43:37 +00:00
4 changed files with 176 additions and 6 deletions

View file

@ -58,6 +58,11 @@ LexicalPath::LexicalPath(ByteString path)
}
}
bool LexicalPath::is_absolute() const
{
return m_string.starts_with('/');
}
Vector<ByteString> LexicalPath::parts() const
{
Vector<ByteString> vector;
@ -163,7 +168,7 @@ ByteString LexicalPath::relative_path(StringView a_path, StringView a_prefix)
if (prefix == "/"sv)
return path.substring_view(1);
// NOTE: This means the prefix is a direct child of the path.
// NOTE: This means the path is a direct child of the prefix.
if (path.starts_with(prefix) && path[prefix.length()] == '/') {
return path.substring_view(prefix.length() + 1);
}