ClrPlus.Core.Extensions.StringExtensions.NewIsWildcardMatch C# (CSharp) Метод

NewIsWildcardMatch() публичный статический Метод

The new implementation of the wildcard matching function. Rules: * means matches anything except slash or backslash ? means match any one character ** means matches anything
public static NewIsWildcardMatch ( this text, string wildcardMask, bool isMatchingLocation = false, string currentLocation = null ) : bool
text this
wildcardMask string
isMatchingLocation bool
currentLocation string
Результат bool
        public static bool NewIsWildcardMatch(this string text, string wildcardMask, bool isMatchingLocation = false, string currentLocation = null) {
            string key;

            if (!isMatchingLocation) {
                key = (currentLocation ?? "") + wildcardMask;
                lock (NewWildcards) {
                    if (!NewWildcards.ContainsKey(key)) {
                        NewWildcards.Add(key, WildcardToRegex(key));
                    }
                }
                return NewWildcards[key].IsMatch(text);
            }

            key = wildcardMask + (currentLocation ?? "");
            if (!NewWildcards.ContainsKey(key)) {
                var prefix = currentLocation == null
                    ? @".*[\\|\/]"
                    : Regex.Escape((currentLocation.EndsWith("\\") || currentLocation.EndsWith("/")
                        ? currentLocation
                        : currentLocation + (text.Contains("\\") ? "\\" : (text.Contains("/") ? "/" : ""))));
                NewWildcards.Add(key, WildcardToRegex(wildcardMask, prefix));
            }

            return NewWildcards[key].IsMatch(text);
        }