Example #1
0
        protected List <GrepSearchResult.GrepMatch> doFuzzySearchMultiline(int lineNumber, string text, string searchPattern, GrepSearchOption searchOptions, bool includeContext)
        {
            var lineEndIndexes = GetLineEndIndexes(verboseMatchCount && lineNumber == -1 ? text : null);

            int counter = 0;

            fuzzyMatchEngine.Match_Threshold = (float)fuzzyMatchThreshold;
            bool isWholeWord = (searchOptions & GrepSearchOption.WholeWord) == GrepSearchOption.WholeWord;
            List <GrepSearchResult.GrepMatch> globalMatches = new List <GrepSearchResult.GrepMatch>();

            while (counter < text.Length)
            {
                int matchLocation = fuzzyMatchEngine.match_main(text.Substring(counter), searchPattern, counter);
                if (matchLocation == -1)
                {
                    break;
                }

                if (isWholeWord && !Utils.IsValidBeginText(text.Substring(counter).Substring(0, matchLocation)))
                {
                    counter = counter + matchLocation + searchPattern.Length;
                    continue;
                }

                int matchLength = fuzzyMatchEngine.match_length(text.Substring(counter), searchPattern, matchLocation, isWholeWord, fuzzyMatchThreshold);

                if (matchLength == -1)
                {
                    counter = counter + matchLocation + searchPattern.Length;
                    continue;
                }

                if (verboseMatchCount && lineEndIndexes.Count > 0)
                {
                    lineNumber = lineEndIndexes.FindIndex(i => i > matchLocation + counter) + 1;
                }

                globalMatches.Add(new GrepSearchResult.GrepMatch(lineNumber, matchLocation + counter, matchLength));

                counter = counter + matchLocation + matchLength;
            }
            return(globalMatches);
        }
Example #2
0
        private IEnumerable <GrepMatch> FuzzySearchIterator(int lineNumber, int filePosition, string text, string searchPattern, GrepSearchOption searchOptions)
        {
            var lineEndIndexes = GetLineEndIndexes(initParams.VerboseMatchCount && lineNumber == -1 ? text : null);

            if (fuzzyMatchEngine == null)
            {
                fuzzyMatchEngine = new GoogleMatch();
            }
            fuzzyMatchEngine.Match_Threshold = initParams.FuzzyMatchThreshold;

            bool isWholeWord = searchOptions.HasFlag(GrepSearchOption.WholeWord);

            int counter = 0;

            while (counter < text.Length)
            {
                int matchLocation = fuzzyMatchEngine.match_main(text.Substring(counter), searchPattern, counter);
                if (matchLocation == -1)
                {
                    break;
                }

                if (isWholeWord && !Utils.IsValidBeginText(text.Substring(counter).Substring(0, matchLocation)))
                {
                    counter = counter + matchLocation + searchPattern.Length;
                    continue;
                }

                int matchLength = fuzzyMatchEngine.match_length(text.Substring(counter), searchPattern, matchLocation, isWholeWord, initParams.FuzzyMatchThreshold);

                if (matchLength == -1)
                {
                    counter = counter + matchLocation + searchPattern.Length;
                    continue;
                }

                if (initParams.VerboseMatchCount && lineEndIndexes.Count > 0)
                {
                    lineNumber = lineEndIndexes.FindIndex(i => i > matchLocation + counter) + 1;
                }

                yield return(new GrepMatch(searchPattern, lineNumber, matchLocation + filePosition + counter, matchLength));

                counter = counter + matchLocation + matchLength;
            }
        }