AK: Make LexicalPath::relative_path() fallible

This commit is contained in:
stasoid 2024-10-22 22:53:25 +05:00 committed by Andrew Kaster
commit 31bf40b659
Notes: github-actions[bot] 2024-11-09 19:43:30 +00:00
8 changed files with 12 additions and 14 deletions

View file

@ -147,12 +147,10 @@ ByteString LexicalPath::absolute_path(ByteString dir_path, ByteString target)
return LexicalPath::canonicalized_path(join(dir_path, target).string());
}
ByteString LexicalPath::relative_path(StringView a_path, StringView a_prefix)
Optional<ByteString> LexicalPath::relative_path(StringView a_path, StringView a_prefix)
{
if (!a_path.starts_with('/') || !a_prefix.starts_with('/')) {
// FIXME: This should probably VERIFY or return an Optional<ByteString>.
return ""sv;
}
if (!a_path.starts_with('/') || !a_prefix.starts_with('/'))
return {};
if (a_path == a_prefix)
return ".";