void ProcessRun(AddHighlight addHighlightDelegate, Run run, RunQueue runQueue, Query searchText) { if (run != null && !string.IsNullOrEmpty(run.Text)) { runQueue.Enqueue(run); ScanQueuedRuns(runQueue, searchText, addHighlightDelegate); } }
void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, Query query) { while (runQueue.Count > 0) { runQueue.Dequeue(); ScanQueuedRuns(runQueue, query, addHighlightDelegate); } }
public static void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, string searchText) { while (runQueue.Count > 0) { runQueue.Dequeue(); ScanQueuedRuns(runQueue, searchText, addHighlightDelegate); } }
public void FindTextIn(IRunReader runReader, AddHighlight addHighlightDelegate, string searchText) { runQueue.Clear(); foreach (Run run in runReader) { ProcessRun(addHighlightDelegate, run, runQueue, searchText); } ProcessRemainingQueuedRuns(addHighlightDelegate, runQueue, searchText); }
/// <summary> /// Scans a queue of runs and highlights matches. /// </summary> /// <param name="runQueue">Run queue</param> /// <param name="query">Query</param> /// <param name="addHighlightDelegate">Delegate to call when a hit is found</param> public virtual void ScanQueuedRuns(RunQueue runQueue, Query query, AddHighlight addHighlightDelegate) { //this.searchText = query; System.Text.StringBuilder queuedText = new System.Text.StringBuilder(100); queuedText.Length = 0; for (int i = 0; i < runQueue.Count && (i <= 1 || queuedText.Length < 100); i++)//look at the text in queue up until 100 chars of the 2nd run { queuedText.Append(runQueue[i].HitAvailableText); } int currentIndex = 0; string text = queuedText.ToString(); int index; Hit hit; TextMatchers textMatchers = query.GetTextMatchers(text, FindOptions); while ((hit = GetNextMatch(textMatchers, currentIndex)).Start > -1 && currentGlobalScanHighlightCount < maximumHitsToHighlight)//find a hit for searchText in the plain text version. { index = hit.Start; //we have a hit, we need to find the runs it was in and highlight int highlightStart; int gobbledChars = 0; int runHitLength = hit.Length; int highlightLength; //string searchSegment = query.QueryText; bool moreToFind = true; while (moreToFind) { Run runAtPos = runQueue.HitPosition(index, runHitLength, out highlightStart, out gobbledChars); //gobbledChars is the number of chars in runAtPos that were used (this could be the entire run length if the runHitLength is less than the //number of chars in the run). //indexOffset is where in the run to start highlighting if (gobbledChars < runHitLength) { moreToFind = true; //there weren't enough chars in the run, so we'll need to look for more index += gobbledChars; runHitLength -= gobbledChars; highlightLength = gobbledChars; } else { moreToFind = false; highlightLength = runHitLength; } addHighlightDelegate(runAtPos, highlightStart, highlightLength); currentGlobalScanHighlightCount++; currentIndex = index + runHitLength; } } }
/// <summary> /// Finds the <c>searchText</c> query in Runs returned by <c>runReader</c>. /// </summary> /// <param name="runReader">IRunReader that will return an enumeration of Runs to search in</param> /// <param name="addHighlightDelegate">Delegate to call when hits are found</param> /// <param name="searchText">The query to search for</param> public void FindTextIn(IRunReader runReader, AddHighlight addHighlightDelegate, Query searchText) { runQueue.Clear(); currentGlobalScanHighlightCount = 0; foreach (Run run in runReader) { ProcessRun(addHighlightDelegate, run, runQueue, searchText); } ProcessRemainingQueuedRuns(addHighlightDelegate, runQueue, searchText); }
public void FindTextIn(List <Run> runs, AddHighlight addHighlightDelegate, string searchText) { if (searchText == null) { searchText = this.searchText; } runQueue.Clear(); foreach (Run run in runs) { ProcessRun(addHighlightDelegate, run, runQueue, searchText); } ProcessRemainingQueuedRuns(addHighlightDelegate, runQueue, searchText); }
/// <summary> /// Finds the <c>searchText</c> query in Runs. /// </summary> /// <param name="runs">Collection of runs to look in</param> /// <param name="addHighlightDelegate">Delegate to call when hits are found</param> /// <param name="searchText">The query to search for</param> public void FindTextIn(List <Run> runs, AddHighlight addHighlightDelegate, Query searchText) { if (searchText == null) { searchText = Query; } runQueue.Clear(); currentGlobalScanHighlightCount = 0; foreach (Run run in runs) { ProcessRun(addHighlightDelegate, run, runQueue, searchText); } ProcessRemainingQueuedRuns(addHighlightDelegate, runQueue, searchText); }
public static void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) { System.Text.StringBuilder queuedText = new System.Text.StringBuilder(100); queuedText.Length = 0; for (int i = 0; i < runQueue.Count && (i == 0 || queuedText.Length < 100); i++)//look at the text in queue up until 100 chars of the 2nd run { queuedText.Append(runQueue[i].HitAvailableText); } int currentIndex = 0; string text = queuedText.ToString(); int index; while ((index = text.IndexOf(searchText, currentIndex, StringComparison.CurrentCultureIgnoreCase)) > -1)//find a hit for searchText in the plain text version. { //we have a hit, we need to find the runs it was in and highlight int indexOffset; int remainingChars = 0; int hitLength = 0; string searchSegment = searchText; bool moreToFind = true; while (moreToFind) { Run runAtPos = runQueue.HitPosition(index, searchSegment.Length, out indexOffset, out remainingChars); //remainingChars is # of chars in the run after the hit position - so if the hit spreads over 2 or more runs //then remainingChars will be less than the searchSegment. if (remainingChars < searchSegment.Length) { //partial match, find parts with rest moreToFind = true; searchSegment = searchText.Substring(remainingChars); hitLength = remainingChars; index = text.IndexOf(searchSegment, index + hitLength, StringComparison.CurrentCultureIgnoreCase); } else { moreToFind = false; hitLength = searchSegment.Length; } addHighlightDelegate(runAtPos, indexOffset, hitLength); currentIndex = index + hitLength; } } }
public static void ProcessRun(AddHighlight addHighlightDelegate, Run run, RunQueue runQueue, string searchText) { if (run != null && !string.IsNullOrEmpty(run.Text)) { runQueue.Enqueue(run); ScanQueuedRuns(runQueue, searchText, addHighlightDelegate); } }
public void FindTextIn(List<Run> runs, AddHighlight addHighlightDelegate, string searchText) { if (searchText == null) searchText = this.searchText; runQueue.Clear(); foreach (Run run in runs) { ProcessRun(addHighlightDelegate, run, runQueue, searchText); } ProcessRemainingQueuedRuns(addHighlightDelegate, runQueue, searchText); }
/* public static void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) * { * * } */ #if DEBUG //testing usage /// <summary> /// /// </summary> /// <param name="runQueue"></param> /// <param name="searchText"></param> /// <param name="addHighlightDelegate"></param> public void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) { ScanQueuedRuns(runQueue, new Keyoti.RapidFindReplace.WPF.Query(searchText), addHighlightDelegate); }
/* public static void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) { } */ #if DEBUG //testing usage /// <summary> /// /// </summary> /// <param name="runQueue"></param> /// <param name="searchText"></param> /// <param name="addHighlightDelegate"></param> public void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) { ScanQueuedRuns(runQueue, new Keyoti.RapidFindReplace.WPF.Query(searchText), addHighlightDelegate); }
/// <summary> /// Finds the <c>searchText</c> query in Runs. /// </summary> /// <param name="runs">Collection of runs to look in</param> /// <param name="addHighlightDelegate">Delegate to call when hits are found</param> /// <param name="searchText">The query to search for</param> public void FindTextIn(List<Run> runs, AddHighlight addHighlightDelegate, Query searchText) { if (searchText == null) searchText = Query; runQueue.Clear(); currentGlobalScanHighlightCount = 0; foreach (Run run in runs) { ProcessRun(addHighlightDelegate, run, runQueue, searchText); } ProcessRemainingQueuedRuns(addHighlightDelegate, runQueue, searchText); }
public static void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate,RunQueue runQueue, string searchText) { while (runQueue.Count > 0) { runQueue.Dequeue(); ScanQueuedRuns(runQueue, searchText, addHighlightDelegate); } }
public static void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) { System.Text.StringBuilder queuedText = new System.Text.StringBuilder(100); queuedText.Length = 0; for (int i = 0; i < runQueue.Count && (i==0 || queuedText.Length < 100); i++)//look at the text in queue up until 100 chars of the 2nd run { queuedText.Append(runQueue[i].HitAvailableText); } int currentIndex = 0; string text = queuedText.ToString(); int index; while ((index = text.IndexOf(searchText, currentIndex, StringComparison.CurrentCultureIgnoreCase)) >-1)//find a hit for searchText in the plain text version. { //we have a hit, we need to find the runs it was in and highlight int indexOffset; int remainingChars=0; int hitLength=0; string searchSegment = searchText; bool moreToFind = true; while (moreToFind) { Run runAtPos = runQueue.HitPosition(index, searchSegment.Length, out indexOffset, out remainingChars); //remainingChars is # of chars in the run after the hit position - so if the hit spreads over 2 or more runs //then remainingChars will be less than the searchSegment. if (remainingChars < searchSegment.Length) { //partial match, find parts with rest moreToFind = true; searchSegment = searchText.Substring(remainingChars); hitLength = remainingChars; index = text.IndexOf(searchSegment, index + hitLength, StringComparison.CurrentCultureIgnoreCase); } else { moreToFind = false; hitLength = searchSegment.Length; } addHighlightDelegate(runAtPos, indexOffset, hitLength); currentIndex = index + hitLength; } } }