Ejemplo n.º 1
0
 public void Visit(WildcardDirectoryToken wildcardDirectoryToken)
 {
     _stringBuilder.Append("**");
     if (wildcardDirectoryToken.TrailingPathSeperator != null)
     {
         _stringBuilder.Append(wildcardDirectoryToken.TrailingPathSeperator);
     }
 }
Ejemplo n.º 2
0
        public void Visit(WildcardDirectoryToken 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.
        }
Ejemplo n.º 3
0
 public void Visit(WildcardDirectoryToken wildcardDirectoryToken)
 {
     if (wildcardDirectoryToken.LeadingPathSeparator != null)
     {
         _stringBuilder.Append(wildcardDirectoryToken.LeadingPathSeparator.Value);
     }
     _stringBuilder.Append("**");
     if (wildcardDirectoryToken.TrailingPathSeparator != null)
     {
         _stringBuilder.Append(wildcardDirectoryToken.TrailingPathSeparator.Value);
     }
 }
Ejemplo n.º 4
0
        void IGlobTokenVisitor.Visit(WildcardDirectoryToken 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 WildcardDirectoryTokenMatchGenerator(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.
        }
Ejemplo n.º 5
0
 public IGlobTokenEvaluator CreateTokenEvaluator(WildcardDirectoryToken token, CompositeTokenEvaluator nestedCompositeTokenEvaluator)
 {
     return(new WildcardDirectoryTokenEvaluator(token, nestedCompositeTokenEvaluator));
 }
Ejemplo n.º 6
0
        public void Visit(WildcardDirectoryToken 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 = remainingText.Length; //TODO: improve this.


            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();
        }
 public WildcardDirectoryTokenEvaluator(WildcardDirectoryToken token, CompositeTokenEvaluator subEvaluator)
 {
     _token = token;
     //_remaining = remaining;
     _subEvaluator = subEvaluator;
 }
 public WildcardDirectoryTokenMatchGenerator(WildcardDirectoryToken token, Random random, CompositeTokenMatchGenerator subGenerator)
 {
     this.token    = token;
     _subGenerator = subGenerator;
     _random       = random;
 }