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; } }