Skip to content

Commit

Permalink
FileSystemPath: Add a has_extension() helper.
Browse files Browse the repository at this point in the history
This code:

    if (path.string().to_lowercase().ends_with(".foo"))

Can now be written as:

    if (path.has_extension(".foo"))
  • Loading branch information
awesomekling committed May 26, 2019
1 parent 6ac8aab commit 5ba2dba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions AK/FileSystemPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 2 additions & 0 deletions AK/FileSystemPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class FileSystemPath {

const Vector<String>& parts() const { return m_parts; }

bool has_extension(StringView) const;

private:
bool canonicalize(bool resolve_symbolic_links = false);

Expand Down

0 comments on commit 5ba2dba

Please sign in to comment.