Ejemplo n.º 1
0
        private Dictionary <string, object> MatchWholeCorpus(ParsedPattern parsedPattern, string corpus)
        {
            var dictionary      = new Dictionary <string, object>();
            var matchCollection = parsedPattern.Pattern.Matches(corpus);

            if ((parsedPattern.Options & SudoRegexOptions.Global) == SudoRegexOptions.None)
            {
                if (matchCollection.Count >= 1)
                {
                    dictionary["0"] = this.HashMatch(matchCollection[0]);
                }
            }
            else
            {
                foreach (Match match in parsedPattern.Pattern.Matches(corpus))
                {
                    dictionary[match.Index.ToString()] = this.HashMatch(match);
                }
            }
            dictionary["matchSummary"] = new {
                total = dictionary.Count
            };
            return(dictionary);
        }
Ejemplo n.º 2
0
        private Dictionary<string, object> MatchCorpusTests( ParsedPattern parsedPattern, string corpus )
        {
            var summary = new Dictionary<string, object> {
                                                         	{ "total", 0 },
                                                         	{ "tests", true },
                                                         	{ "passed", 0 },
                                                         	{ "failed", 0 }
                                                         };
            var results = new Dictionary<string, object> {
                                                         	{ "matchSummary", summary }
                                                         };

            Action<string, int, bool> addMatch = delegate( string line, int offset, bool passed ) {
                                                 	summary[ "total" ] = (int) summary[ "total" ] + 1;
                                                 	var key = passed ? "passed" : "failed";
                                                 	summary[ key ] = (int) summary[ key ] + 1;
                                                 	results[ offset.ToString() ] = new object[] {
                                                 	                                            	offset,
                                                 	                                            	line.Length,
                                                 	                                            	passed ? "match" : "nomatch"
                                                 	                                            };
                                                 };
            Action<string, int> nothingMatcher = delegate { };
            Action<string, int> positiveMatcher =
                delegate( string line, int offset ) { addMatch( line, offset, parsedPattern.Pattern.IsMatch( line ) ); };
            Action<string, int> negativeMatcher =
                delegate( string line, int offset ) { addMatch( line, offset, !parsedPattern.Pattern.IsMatch( line ) ); };
            Func<string, Action<string, int>> func = delegate( string line ) {
                                                     	if( line.Length <= 1 )
                                                     	{
                                                     		return nothingMatcher;
                                                     	}
                                                     	if( line[ 1 ] == '+' )
                                                     	{
                                                     		return positiveMatcher;
                                                     	}
                                                     	if( line[ 1 ] == '-' )
                                                     	{
                                                     		return negativeMatcher;
                                                     	}
                                                     	return nothingMatcher;
                                                     };
            var action = nothingMatcher;
            var num = 0;
            var array = corpus.Split( new[] {
                                                '\n'
                                            } );
            for( var i = 0; i < array.Length; i++ )
            {
                var text = array[ i ];
                if( text.Length > 1 && text[ 0 ] == '#' )
                {
                    action = func( text );
                }
                else if( text.Length > 0 )
                {
                    action( text, num );
                }
                num += text.Length + 1;
            }
            return results;
        }
Ejemplo n.º 3
0
        private Dictionary <string, object> MatchCorpusTests(ParsedPattern parsedPattern, string corpus)
        {
            var summary = new Dictionary <string, object> {
                { "total", 0 },
                { "tests", true },
                { "passed", 0 },
                { "failed", 0 }
            };
            var results = new Dictionary <string, object> {
                { "matchSummary", summary }
            };

            Action <string, int, bool> addMatch = delegate(string line, int offset, bool passed) {
                summary["total"] = (int)summary["total"] + 1;
                var key = passed ? "passed" : "failed";
                summary[key] = (int)summary[key] + 1;
                results[offset.ToString()] = new object[] {
                    offset,
                    line.Length,
                    passed ? "match" : "nomatch"
                };
            };
            Action <string, int> nothingMatcher  = delegate { };
            Action <string, int> positiveMatcher =
                delegate(string line, int offset) { addMatch(line, offset, parsedPattern.Pattern.IsMatch(line)); };
            Action <string, int> negativeMatcher =
                delegate(string line, int offset) { addMatch(line, offset, !parsedPattern.Pattern.IsMatch(line)); };
            Func <string, Action <string, int> > func = delegate(string line) {
                if (line.Length <= 1)
                {
                    return(nothingMatcher);
                }
                if (line[1] == '+')
                {
                    return(positiveMatcher);
                }
                if (line[1] == '-')
                {
                    return(negativeMatcher);
                }
                return(nothingMatcher);
            };
            var action = nothingMatcher;
            var num    = 0;
            var array  = corpus.Split(new[] {
                '\n'
            });

            for (var i = 0; i < array.Length; i++)
            {
                var text = array[i];
                if (text.Length > 1 && text[0] == '#')
                {
                    action = func(text);
                }
                else if (text.Length > 0)
                {
                    action(text, num);
                }
                num += text.Length + 1;
            }
            return(results);
        }
Ejemplo n.º 4
0
 private Dictionary<string, object> MatchWholeCorpus( ParsedPattern parsedPattern, string corpus )
 {
     var dictionary = new Dictionary<string, object>();
     var matchCollection = parsedPattern.Pattern.Matches( corpus );
     if( ( parsedPattern.Options & SudoRegexOptions.Global ) == SudoRegexOptions.None )
     {
         if( matchCollection.Count >= 1 )
         {
             dictionary[ "0" ] = this.HashMatch( matchCollection[ 0 ] );
         }
     }
     else
     {
         foreach( Match match in parsedPattern.Pattern.Matches( corpus ) )
         {
             dictionary[ match.Index.ToString() ] = this.HashMatch( match );
         }
     }
     dictionary[ "matchSummary" ] = new {
                                        	total = dictionary.Count
                                        };
     return dictionary;
 }