public ExclusionMatch(MatchFinder finder, MatchableExclusion exclusion, int line, int column) { _finder = finder; _exclusion = exclusion; _line = line; _column = column; }
/// <summary> /// See <c>IScanner</c> documentation. /// </summary> public IMultiFileScanResult Scan(IEnumerable <string> filePaths, IEnumerable <ITermTable> termTables, FileScanCompleted callback, FileContentGetter contentGetter, ScanStopper stopper) { if (filePaths == null) { throw new ArgumentNullException("filePaths"); } if (termTables == null) { throw new ArgumentNullException("termTables"); } MatchFinder finder = new MatchFinder(termTables); MultiFileScanResult allResults = new MultiFileScanResult(); foreach (string filePath in filePaths) { if (stopper != null && stopper()) { break; } if (FileShouldBeScanned(filePath)) { IScanResult fileResult = ScanFile(filePath, finder, contentGetter, stopper); allResults.Append(fileResult); if (callback != null) { callback(fileResult); } } } return(allResults); }
public TermMatch(MatchFinder finder, MatchableTerm term, int line, int column) { _finder = finder; _term = term; _line = line; _column = column; }
private static IScanResult ScanFile(string filePath, MatchFinder finder, FileContentGetter contentGetter, ScanStopper stopper) { if (filePath == null) { throw new ArgumentNullException("filePath"); } // See if the content getter can give us the file contents. If so, we'll scan that // string rather than loading the file from disk. if (contentGetter != null) { string content = contentGetter(filePath); if (content != null) { return(ScanResult.ScanOccurred(filePath, GetScanHits(filePath, content, finder, stopper))); } } StreamReader reader = null; try { try { reader = File.OpenText(filePath); } catch (Exception ex) { if (ex is UnauthorizedAccessException || ex is ArgumentException || ex is ArgumentNullException || ex is PathTooLongException || ex is DirectoryNotFoundException || ex is FileNotFoundException || ex is NotSupportedException || ex is IOException) { return(ScanResult.ScanNotPossible(filePath)); } else { throw; } } return(ScanResult.ScanOccurred(filePath, GetScanHits(filePath, reader, finder, stopper))); } finally { if (reader != null) { reader.Close(); } } }
public override void AddChar(char c) { if (!DiscardPending) { if (IsMatched) { // The term was already matched. If we're now watching for the end-of-word // separator, see if this is it. if (_nextCharMustBeSeparator) { if (MatchFinder.IsSeparator(c)) { _nextCharMustBeSeparator = false; } else { // The character following the term match was not a separator, so // this match is not valid. Discard it. MarkForDiscard(); } } } else { // This match is still in progress. See if the current character matches // the text we're looking for. if (Char.ToLowerInvariant(Term.Term.Text[_matchedChars]) == Char.ToLowerInvariant(c)) { ++_matchedChars; if (IsMatched) { _nextCharMustBeSeparator = true; } } else { MarkForDiscard(); } } // If this term is now matched, discard all other pending matches that overlap // its span. if (IsMatchedAndConfirmed) { _finder.RemoveAllMatchesInRangeExceptOne(Line, Column, Line, Column + Term.Term.Text.Length - 1, this); } } }
private static IEnumerable <IScanHit> GetScanHits(string filePath, string content, MatchFinder finder, ScanStopper stopper) { List <IScanHit> hits = new List <IScanHit>(); MatchFoundCallback callback = delegate(ISearchTerm term, int line, int column, string lineText, string warning) { hits.Add(new ScanHit(filePath, line, column, lineText, term, warning)); }; finder.Reset(); foreach (char c in content) { if (stopper != null && stopper()) { break; } finder.AnalyzeNextCharacter(c, callback); } finder.Finish(callback); return(hits); }
private static IEnumerable <IScanHit> GetScanHits(string filePath, StreamReader reader, MatchFinder finder, ScanStopper stopper) { List <IScanHit> hits = new List <IScanHit>(); MatchFoundCallback callback = (term, line, column, lineText, warning) => hits.Add(new ScanHit(filePath, line, column, lineText, term, warning)); finder.Reset(); while (!reader.EndOfStream) { if (stopper != null && stopper()) { break; } finder.AnalyzeNextCharacter((char)reader.Read(), callback); } finder.Finish(callback); return(hits); }
public bool Excludes(TermMatch match) { return(match.Term == _exclusion.Term && MatchFinder.RangeContains(_line, _column, _line, _column + _exclusion.Text.Length - 1, match.Line, match.Column) && MatchFinder.RangeContains(_line, _column, _line, _column + _exclusion.Text.Length - 1, match.Line, match.Column + match.Term.Term.Text.Length - 1)); }