From 788a9ea107a579b1cd144105a4a77c7e134ee2dd Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 27 Oct 2021 17:10:56 +0100 Subject: [PATCH] WIP: funcky wildcard pattern match --- IO/SmartFileSystem.cs | 82 +++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/IO/SmartFileSystem.cs b/IO/SmartFileSystem.cs index bed749f..6b75186 100644 --- a/IO/SmartFileSystem.cs +++ b/IO/SmartFileSystem.cs @@ -170,33 +170,7 @@ namespace RandomFileRunner.IO public static bool MatchFileSearchPattern(string pattern, string subject) { - if (pattern.Contains(';')) - { - string[] parts = pattern.Split(';'); - for (int i=0; i x.Equals('*')); - if (wildcardCount <= 0) + Func matchAllPattern = (pattern, subject) => { - return subject.Equals(wildcardPattern, StringComparison.CurrentCultureIgnoreCase); - } - else if (wildcardCount == 1) - { - string newWildcardPattern = wildcardPattern.Replace("*", ""); - - if (wildcardPattern.StartsWith("*")) + int wildcardCount = pattern.Count(x => x.Equals('*')); + if (wildcardCount <= 0) { - return subject.EndsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + return subject.Equals(pattern, StringComparison.CurrentCultureIgnoreCase); } - else if (wildcardPattern.EndsWith("*")) + else if (wildcardCount == 1) { - return subject.StartsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + string newWildcardPattern = pattern.Replace("*", ""); + + if (pattern.StartsWith("*")) + { + return subject.EndsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + } + else if (pattern.EndsWith("*")) + { + return subject.StartsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + } + else + { + return matchPattern(pattern, subject); + } } else { - return matchPattern(wildcardPattern, subject); + return matchPattern(pattern, subject); } + }; + + if (pattern.Contains(';')) + { + string[] parts = pattern.Split(';'); + for (int i=0; i