private bool doMatch(object operand, out MatchInfo matchResult, out string operandString) { bool success = false; Match[] array = null; int index = 0; matchResult = null; MatchInfo info = operand as MatchInfo; if (info != null) { operandString = info.Line; if ((this.preContext > 0) || (this.postContext > 0)) { this.preContext = 0; this.postContext = 0; this.globalContextTracker = new ContextTracker(this.preContext, this.postContext); this.WarnFilterContext(); } } else { operandString = (string)LanguagePrimitives.ConvertTo(operand, typeof(string), CultureInfo.InvariantCulture); } if (!this.simpleMatch) { while (index < this.pattern.Length) { Regex regex = this.regexPattern[index]; if (this.allMatches && !this.notMatch) { MatchCollection matchs = regex.Matches(operandString); if ((matchs != null) && (matchs.Count > 0)) { array = new Match[matchs.Count]; matchs.CopyTo(array, 0); success = true; } } else { Match match = regex.Match(operandString); success = match.Success; if (match.Success) { array = new Match[] { match }; } } if (success) { break; } index++; } } else { StringComparison comparisonType = this.caseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; while (index < this.pattern.Length) { string str = this.pattern[index]; if (operandString.IndexOf(str, comparisonType) >= 0) { success = true; break; } index++; } } if (this.notMatch) { success = !success; index = 0; } if (!success) { return(false); } if (info != null) { if (info.Context != null) { matchResult = info.Clone(); matchResult.Context.DisplayPreContext = new string[0]; matchResult.Context.DisplayPostContext = new string[0]; } else { matchResult = info; } return(true); } matchResult = new MatchInfo(); matchResult.IgnoreCase = !this.caseSensitive; matchResult.Line = operandString; matchResult.Pattern = this.pattern[index]; if ((this.preContext > 0) || (this.postContext > 0)) { matchResult.Context = new MatchInfoContext(); } matchResult.Matches = (array != null) ? array : new Match[0]; return(true); }
protected override void ProcessRecord() { if (!this.doneProcessing) { List <string> list = null; if (this.fullName != null) { list = this.ResolveFilePaths(this.fullName, this.isLiteralPath); if (list == null) { return; } } else { FileInfo baseObject = this.inputObject.BaseObject as FileInfo; if (baseObject != null) { list = new List <string> { baseObject.FullName }; } } if (list != null) { foreach (string str in list) { bool flag = this.ProcessFile(str); if (this.quiet && flag) { return; } } if (this.quiet) { if (this.list) { base.WriteObject(null); } else { base.WriteObject(false); } } } else { this.inputRecordNumber++; object operand = this.inputObject.BaseObject as MatchInfo; if (operand == null) { operand = this.inputObject; } MatchInfo matchResult = null; string operandString = null; if (this.doMatch(operand, out matchResult, out operandString)) { if (!(operand is MatchInfo)) { matchResult.LineNumber = this.inputRecordNumber; } this.globalContextTracker.TrackMatch(matchResult); } else { this.globalContextTracker.TrackLine(operandString); } if (this.FlushTrackerQueue(this.globalContextTracker) && this.quiet) { this.doneProcessing = true; } } } }
public void TrackMatch(MatchInfo match) { this.displayTracker.TrackMatch(match); this.logicalTracker.TrackMatch(match); this.UpdateQueue(); }
private bool ProcessFile(string filename) { ContextTracker contextTracker = new ContextTracker(this.preContext, this.postContext); bool flag = false; try { if (!this.meetsIncludeExcludeCriteria(filename)) { return(false); } using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader reader = new StreamReader(stream, this.textEncoding)) { string str; int num = 0; while ((str = reader.ReadLine()) != null) { num++; MatchInfo matchResult = null; string operandString = null; if (this.doMatch(str, out matchResult, out operandString)) { matchResult.Path = filename; matchResult.LineNumber = num; contextTracker.TrackMatch(matchResult); } else { contextTracker.TrackLine(str); } if (contextTracker.EmitQueue.Count > 0) { flag = true; if (this.quiet || this.list) { goto Label_00C9; } this.FlushTrackerQueue(contextTracker); } } } } Label_00C9: contextTracker.TrackEOF(); if (this.FlushTrackerQueue(contextTracker)) { flag = true; } } catch (NotSupportedException exception) { base.WriteError(BuildErrorRecord(MatchStringStrings.FileReadError, filename, exception.Message, "ProcessingFile", exception)); } catch (IOException exception2) { base.WriteError(BuildErrorRecord(MatchStringStrings.FileReadError, filename, exception2.Message, "ProcessingFile", exception2)); } catch (SecurityException exception3) { base.WriteError(BuildErrorRecord(MatchStringStrings.FileReadError, filename, exception3.Message, "ProcessingFile", exception3)); } catch (UnauthorizedAccessException exception4) { base.WriteError(BuildErrorRecord(MatchStringStrings.FileReadError, filename, exception4.Message, "ProcessingFile", exception4)); } return(flag); }
public ContextEntry(MatchInfo match) { this.Match = match; }
private void WriteNotMatch(string line, string pattern, string path) { var match = new MatchInfo(path, pattern, line, _lineNumber, !CaseSensitive); WriteMatch(match); }
private void WriteNotMatch(string line, string pattern, string path) { var match = new MatchInfo(path, pattern, line, _lineNumber, !CaseSensitive); WriteMatch(match); }
private void WriteMatch(MatchInfo match) { _matchedAtLeastOneItem = true; if (Quiet.IsPresent) { WriteObject(true); } else { WriteObject(match); } }