ソースを参照

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"))
Andreas Kling 6 年 前
コミット
5ba2dba392
2 ファイル変更8 行追加0 行削除
  1. 6 0
      AK/FileSystemPath.cpp
  2. 2 0
      AK/FileSystemPath.h

+ 6 - 0
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());
 }
 
+}

+ 2 - 0
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);