DefaultSearchMatcher.cs 911 B

123456789101112131415161718192021222324
  1. using System.IO.Abstractions;
  2. namespace Terminal.Gui;
  3. internal class DefaultSearchMatcher : ISearchMatcher
  4. {
  5. private string [] terms;
  6. public void Initialize (string terms) { this.terms = terms.Split (new [] { " " }, StringSplitOptions.RemoveEmptyEntries); }
  7. public bool IsMatch (IFileSystemInfo f)
  8. {
  9. //Contains overload with StringComparison is not available in (net472) or (netstandard2.0)
  10. //return f.Name.Contains (terms, StringComparison.OrdinalIgnoreCase);
  11. return
  12. // At least one term must match the file name only e.g. "my" in "myfile.csv"
  13. terms.Any (t => f.Name.IndexOf (t, StringComparison.OrdinalIgnoreCase) >= 0)
  14. &&
  15. // All terms must exist in full path e.g. "dos my" can match "c:\documents\myfile.csv"
  16. terms.All (t => f.FullName.IndexOf (t, StringComparison.OrdinalIgnoreCase) >= 0);
  17. }
  18. }