WIP: funcky wildcard pattern match
This commit is contained in:
parent
0c01ab92c1
commit
788a9ea107
@ -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<parts.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(parts[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (MatchWildcard(parts[i].Trim(), subject))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MatchWildcard(pattern, subject);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool MatchWildcard(string wildcardPattern, string subject)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(wildcardPattern))
|
||||
if (string.IsNullOrWhiteSpace(pattern))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -245,31 +219,57 @@ namespace RandomFileRunner.IO
|
||||
return true;
|
||||
};
|
||||
|
||||
int wildcardCount = wildcardPattern.Count(x => x.Equals('*'));
|
||||
if (wildcardCount <= 0)
|
||||
Func<string, string, bool> 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<parts.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(parts[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matchAllPattern(parts[i].Trim(), subject))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return matchPattern(wildcardPattern, subject);
|
||||
return matchAllPattern(pattern, subject);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user