Example #1
0
        private IEnumerable <GrepMatch> TextSearchIteratorBoolean(int lineNumber, int filePosition, string text,
                                                                  BooleanExpression expression, List <int> lineEndIndexes, bool isWholeWord, StringComparison comparisonType)
        {
            List <GrepMatch> results = new List <GrepMatch>();

            foreach (var operand in expression.Operands)
            {
                var matches = TextSearchIterator(lineNumber, filePosition, text, operand.Value,
                                                 lineEndIndexes, isWholeWord, comparisonType);

                operand.EvaluatedResult = matches.Any();
                operand.Matches         = matches.ToList();

                if (!expression.IsComplete && expression.IsShortCircuitFalse())
                {
                    return(results);
                }
            }

            if (expression.IsComplete)
            {
                var evalResult = expression.Evaluate();
                if (evalResult == EvaluationResult.True)
                {
                    foreach (var operand in expression.Operands)
                    {
                        if (operand.Matches != null)
                        {
                            results.AddRange(operand.Matches);
                        }
                    }

                    // if the expression evaluated to true, then the expression is searching
                    // for things that do not match the operands. Return the whole line
                    if (results.Count == 0)
                    {
                        string temp = text.TrimEndOfLine();
                        results.Add(new GrepMatch(string.Empty, lineNumber, filePosition, temp.Length));
                    }

                    GrepMatch.Normalize(results);
                }
            }

            return(results);
        }
Example #2
0
        private IEnumerable <GrepMatch> TextSearchIteratorOr(int lineNumber, int filePosition, string text,
                                                             List <string> orClauses, List <int> lineEndIndexes, bool isWholeWord, StringComparison comparisonType)
        {
            List <GrepMatch> results = new List <GrepMatch>();

            foreach (string searchText in orClauses)
            {
                var matches = TextSearchIterator(lineNumber, filePosition, text, searchText,
                                                 lineEndIndexes, isWholeWord, comparisonType);

                if (matches.Any())
                {
                    results.AddRange(matches);
                }
            }
            GrepMatch.Normalize(results);
            return(results);
        }
Example #3
0
        private IEnumerable <GrepMatch> RegexSearchIteratorOr(int lineNumber, int filePosition, string text,
                                                              List <string> orClauses, bool isWholeWord, RegexOptions regexOptions)
        {
            List <GrepMatch> results = new List <GrepMatch>();

            foreach (string searchPattern in orClauses)
            {
                var matches = RegexSearchIterator(lineNumber, filePosition, text,
                                                  searchPattern, isWholeWord, regexOptions);

                if (matches.Any())
                {
                    results.AddRange(matches);
                }
            }
            GrepMatch.Normalize(results);
            return(results);
        }