diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-26 22:33:30 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-27 01:53:42 +0200 |
commit | 5ba2dba392966449ac980eadf3b1dadedaa4487b (patch) | |
tree | dd63bed296a7637c9da72b0dce8031c6d21d3472 /AK | |
parent | 6ac8aab9410a4319c255790f0e920327b50a8327 (diff) | |
download | serenity-5ba2dba392966449ac980eadf3b1dadedaa4487b.zip |
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"))
Diffstat (limited to 'AK')
-rw-r--r-- | AK/FileSystemPath.cpp | 6 | ||||
-rw-r--r-- | AK/FileSystemPath.h | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/AK/FileSystemPath.cpp b/AK/FileSystemPath.cpp index 971bbf52bd..e094c1de3d 100644 --- a/AK/FileSystemPath.cpp +++ b/AK/FileSystemPath.cpp @@ -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()); } +} diff --git a/AK/FileSystemPath.h b/AK/FileSystemPath.h index 64827157a7..3e56523269 100644 --- a/AK/FileSystemPath.h +++ b/AK/FileSystemPath.h @@ -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); |