static private string ConvertPatternToRegex(string pattern) { return("^" + PathUtils.TrimEndSeparator(pattern) .Replace(@"/", @"\/") .Replace(@"\", @"\\") .Replace(@".", @"\.") .Replace("*", @"[^\/\\]*") .Replace("?", @"[^\/\\]?") + "$"); }
static public string ApplyFolderEquality(string path, FolderPathEquality folderEquality) { if (path == null) { throw new ArgumentNullException(); } if (folderEquality == FolderPathEquality.RespectAmbiguity) { path = PathUtils.TrimEndSeparator(path); } return(path); }
static public bool Match(string path, string pattern, bool caseSensitive = true) { if (!IsValid(pattern)) { throw new ArgumentException(); } if (IsSimplePath(pattern)) { return(MatchSimplePath(path, pattern, caseSensitive)); } var regexOptions = RegexOptions.None; if (!caseSensitive) { regexOptions |= RegexOptions.IgnoreCase; } return(Regex.IsMatch(PathUtils.TrimEndSeparator(path), ConvertPatternToRegex(pattern), regexOptions)); }
public bool Match(string path) { return(_regex?.IsMatch(PathUtils.TrimEndSeparator(path)) ?? MatchSimplePath(path, Pattern, CaseSensitive)); }