1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +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

@ -26,11 +26,11 @@ public:
explicit LexicalPath(ByteString);
bool is_absolute() const { return !m_string.is_empty() && m_string[0] == '/'; }
bool is_absolute() const;
ByteString const& string() const { return m_string; }
StringView dirname() const { return m_dirname; }
StringView basename(StripExtension s = StripExtension::No) const { return s == StripExtension::No ? m_basename : m_basename.substring_view(0, m_basename.length() - m_extension.length() - 1); }
StringView basename(StripExtension s = StripExtension::No) const { return s == StripExtension::No ? m_basename : m_title; }
StringView title() const { return m_title; }
StringView extension() const { return m_extension; }
@ -46,13 +46,14 @@ public:
[[nodiscard]] static ByteString canonicalized_path(ByteString);
[[nodiscard]] static ByteString absolute_path(ByteString dir_path, ByteString target);
[[nodiscard]] static ByteString relative_path(StringView absolute_path, StringView prefix);
[[nodiscard]] static ByteString relative_path(StringView absolute_path, StringView absolute_prefix);
template<typename... S>
[[nodiscard]] static LexicalPath join(StringView first, S&&... rest)
{
StringBuilder builder;
builder.append(first);
// NOTE: On Windows slashes will be converted to backslashes in LexicalPath constructor
((builder.append('/'), builder.append(forward<S>(rest))), ...);
return LexicalPath { builder.to_byte_string() };
@ -88,7 +89,7 @@ private:
StringView m_dirname;
StringView m_basename;
StringView m_title;
StringView m_extension;
StringView m_extension; // doesn't include the dot
};
template<>