mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
FileSystemPath: Add a has_extension() helper.
This code: if (path.string().to_lowercase().ends_with(".foo")) Can now be written as: if (path.has_extension(".foo"))
This commit is contained in:
parent
6ac8aab941
commit
5ba2dba392
Notes:
sideshowbarker
2024-07-19 13:55:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5ba2dba3929
2 changed files with 8 additions and 0 deletions
|
@ -45,5 +45,11 @@ bool FileSystemPath::canonicalize(bool resolve_symbolic_links)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileSystemPath::has_extension(StringView extension) const
|
||||
{
|
||||
// FIXME: This is inefficient, expand StringView with enough functionality that we don't need to copy strings here.
|
||||
String extension_string = extension;
|
||||
return m_string.to_lowercase().ends_with(extension_string.to_lowercase());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ public:
|
|||
|
||||
const Vector<String>& parts() const { return m_parts; }
|
||||
|
||||
bool has_extension(StringView) const;
|
||||
|
||||
private:
|
||||
bool canonicalize(bool resolve_symbolic_links = false);
|
||||
|
||||
|
|
Loading…
Reference in a new issue