public static void Parse(WildcardPattern pattern, WildcardPatternParser parser) { parser.BeginWildcardPattern(pattern); bool isEscaped = false, isBracketExpr = false, isBracketExprStart = false; StringBuilder sbBracketContents = null, sbBracketOperators = null; foreach (char ch in pattern.Pattern) { if (isBracketExpr) { if (ch == ']' && !isBracketExprStart && !isEscaped) { isBracketExpr = false; parser.AppendBracketExpression(sbBracketContents.ToString(), sbBracketOperators.ToString(), pattern.Pattern); sbBracketContents = null; sbBracketOperators = null; } else if (ch != WildcardPattern.EscapeChar || isEscaped) { sbBracketContents.Append(ch); sbBracketOperators.Append(ch == '-' && !isEscaped ? '-' : ' '); } isBracketExprStart = false; } else if (ch == '*' && !isEscaped) { parser.AppendAsterix(); } else if (ch == '?' && !isEscaped) { parser.AppendQuestionMark(); } else if (ch == '[' && !isEscaped) { isBracketExpr = true; isBracketExprStart = true; sbBracketContents = new StringBuilder(); sbBracketOperators = new StringBuilder(); } else if (ch != WildcardPattern.EscapeChar || isEscaped) { parser.AppendLiteralCharacter(ch); } isEscaped = ch == WildcardPattern.EscapeChar && !isEscaped; } if (isBracketExpr) { throw NewWildcardPatternException(pattern.Pattern); } if (isEscaped && !pattern.Pattern.Equals(new string(WildcardPattern.EscapeChar, 1), StringComparison.Ordinal)) { parser.AppendLiteralCharacter(pattern.Pattern[pattern.Pattern.Length - 1]); } parser.EndWildcardPattern(); }
public static void Parse (WildcardPattern pattern, WildcardPatternParser parser) { parser.BeginWildcardPattern(pattern); bool isEscaped = false, isBracketExpr = false, isBracketExprStart = false; StringBuilder sbBracketContents = null, sbBracketOperators = null; foreach (char ch in pattern.Pattern) { if (isBracketExpr) { if (ch == ']' && !isBracketExprStart && !isEscaped) { isBracketExpr = false; parser.AppendBracketExpression(sbBracketContents.ToString(), sbBracketOperators.ToString(), pattern.Pattern); sbBracketContents = null; sbBracketOperators = null; } else if (ch != WildcardPattern.EscapeChar || isEscaped) { sbBracketContents.Append(ch); sbBracketOperators.Append(ch == '-' && !isEscaped ? '-' : ' '); } isBracketExprStart = false; } else if (ch == '*' && !isEscaped) { parser.AppendAsterix(); } else if (ch == '?' && !isEscaped) { parser.AppendQuestionMark(); } else if (ch == '[' && !isEscaped) { isBracketExpr = true; isBracketExprStart = true; sbBracketContents = new StringBuilder(); sbBracketOperators = new StringBuilder(); } else if (ch != WildcardPattern.EscapeChar || isEscaped) { parser.AppendLiteralCharacter(ch); } isEscaped = ch == WildcardPattern.EscapeChar && !isEscaped; } if (isBracketExpr) throw NewWildcardPatternException(pattern.Pattern); if (isEscaped && !pattern.Pattern.Equals(new string(WildcardPattern.EscapeChar, 1), StringComparison.Ordinal)) parser.AppendLiteralCharacter(pattern.Pattern[pattern.Pattern.Length - 1]); parser.EndWildcardPattern(); }