public void Scan_StringStartsAsterisk_MultipleWildCardToken() { var token = WildcardToken.Scan("*bc"); Assert.NotNull(token); Assert.Equal(WildcardType.Multiple, token.Type); Assert.Equal("*", token.Value); }
public void Scan_StringStartsQuestionMark_SingleWildCardToken() { var token = WildcardToken.Scan("?bc"); Assert.NotNull(token); Assert.Equal(WildcardType.Single, token.Type); Assert.Equal("?", token.Value); }
public void Visit(WildcardToken token) { // if no more tokens then just return as * matches the rest of the segment, and therefore no more matching. int remainingCount = _Tokens.Length - (_currentTokenIndex + 1); // Add a nested CompositeTokenEvaluator, passing all of our remaining tokens to it. IGlobToken[] remaining = new IGlobToken[remainingCount]; Array.Copy(_Tokens, _currentTokenIndex + 1, remaining, 0, remainingCount); AddEvaluator(_evaluatorFactory.CreateTokenEvaluator(token, new CompositeTokenEvaluator(remaining, _evaluatorFactory))); _finished = true; // signlas to stop visiting any further tokens as we have offloaded them all to the nested evaluator. }
void IGlobTokenVisitor.Visit(WildcardToken token) { // if no more tokens then just return as * matches the rest of the segment, and therefore no more matching. int remainingCount = _tokens.Length - (_currentTokenIndex + 1); // Add a nested CompositeTokenEvaluator, passing all of our remaining tokens to it. IGlobToken[] remaining = new IGlobToken[remainingCount]; Array.Copy(_tokens, _currentTokenIndex + 1, remaining, 0, remainingCount); var subEvaluator = new WildcardTokenMatchGenerator(token, _random, new CompositeTokenMatchGenerator(_random, remaining)); AddMatchGenerator(subEvaluator); _finished = true; // signlas to stop visiting any further tokens as we have offloaded them all to the nested evaluator. }
public WildcardTokenMatchGenerator(WildcardToken token, Random random, CompositeTokenMatchGenerator subGenerator) { this.token = token; _subGenerator = subGenerator; _random = random; }
public WildcardTokenEvaluator(WildcardToken token, CompositeTokenEvaluator subEvaluator) { _token = token; _subEvaluator = subEvaluator; _requiresSubEvaluation = _subEvaluator.EvaluatorCount > 0; }
void IGlobTokenVisitor.Visit(WildcardToken token) { _stringBuilder.Append('*'); }
public IGlobTokenEvaluator CreateTokenEvaluator(WildcardToken token, CompositeTokenEvaluator nestedCompositeTokenEvaluator) { return(new WildcardTokenEvaluator(token, nestedCompositeTokenEvaluator)); }
public void Visit(WildcardToken token) { // When * encountered, // Dequees all remaining tokens and passes them to a nested Evaluator. // Keeps seing if the nested evaluator will match, and if it doesn't then // will consume / match against one character, and retry. // Exits when match successful, or when the end of the current path segment is reached. GlobTokenMatch match = null; match = new GlobTokenMatch() { Token = token }; AddMatch(match); var remainingText = _Reader.ReadToEnd(); int endOfSegmentPos; using (var pathReader = new GlobStringReader(remainingText)) { var thisPath = pathReader.ReadPathSegment(); endOfSegmentPos = pathReader.CurrentIndex; } var remaining = _TokenQueue.ToArray(); // if no more tokens remaining then just return as * matches the rest of the segment. if (remaining.Length == 0) { this.Success = true; match.Value = remainingText; return; } // we have to attempt to match the remaining tokens, and if they dont all match, // then consume a character, until we have matched the entirity of this segment. var matchedText = new StringBuilder(endOfSegmentPos); var nestedEval = new GlobTokenMatchAnalysisEvaluator(remaining); var pathSegments = new List <string>(); // we keep a record of text that this wildcard matched in order to satisfy the // greatest number of child token matches. var bestMatchText = new StringBuilder(endOfSegmentPos); IList <GlobTokenMatch> bestMatches = null; // the most tokens that were matched. for (int i = 0; i <= endOfSegmentPos; i++) { var matchInfo = nestedEval.Evaluate(remainingText); if (matchInfo.Success) { break; } // match a single character matchedText.Append(remainingText[0]); // re-attempt matching of child tokens against this remaining string. remainingText = remainingText.Substring(1); // If we have come closer to matching, record our best results. if ((bestMatches == null && matchInfo.Matches.Any()) || (bestMatches != null && bestMatches.Count < matchInfo.Matches.Length)) { bestMatches = matchInfo.Matches.ToArray(); bestMatchText.Clear(); bestMatchText.Append(matchedText.ToString()); } } this.Success = nestedEval.Success; if (nestedEval.Success) { // add all child matches. this.MatchedTokens.AddRange(nestedEval.MatchedTokens); } else { // add the most tokens we managed to match. if (bestMatches != null && bestMatches.Any()) { this.MatchedTokens.AddRange(bestMatches); } } match.Value = matchedText.ToString(); _TokenQueue.Clear(); }
void IGlobTokenVisitor.Visit(WildcardToken token) { _stringBuilder.Append(@"[^/\\]*"); }
public void Scan_StringStartsWithNonWildcardChar_Null() { Assert.Null(WildcardToken.Scan("abc")); }
public WildcardTokenEvaluator(WildcardToken token, CompositeTokenEvaluator subEvaluator) { _token = token; _subEvaluator = subEvaluator; }