internal static WildcardElement Create(string pattern, ref int patternIndex) { if (patternIndex >= pattern.Length) { return(null); } switch (pattern[patternIndex]) { case '*': return(WildcardAsteriskElement.Create(pattern, ref patternIndex)); case '?': return(WildcardQuestionElement.Create(pattern, ref patternIndex)); case '#': return(WildcardSharpElement.Create(pattern, ref patternIndex)); case '[': { int startIndex = patternIndex; WildcardElement element = WildcardRangeElement.Create(pattern, ref patternIndex); if (element == null) { patternIndex = startIndex; element = WildcardStringElement.Create(pattern, ref patternIndex); } return(element); } default: return(WildcardStringElement.Create(pattern, ref patternIndex)); } }
internal new static WildcardStringElement Create(string pattern, ref int patternIndex) { int patternLength = pattern.Length; var builder = new StringBuilder(patternLength - patternLength); while (patternIndex < patternLength) { switch (pattern[patternIndex]) { case '\\': { patternIndex++; if (patternIndex < patternLength) { builder.Append(pattern[patternIndex++]); } } continue; case '*': case '?': case '#': case '[': break; default: { builder.Append(pattern[patternIndex++]); } continue; } break; } var element = new WildcardStringElement(); element.Pattern = builder.ToString(); element.Next = WildcardElement.Create(pattern, ref patternIndex); return(element); }