コード例 #1
0
 void ProcessRun(AddHighlight addHighlightDelegate, Run run, RunQueue runQueue, Query searchText)
 {
     if (run != null && !string.IsNullOrEmpty(run.Text))
     {
         runQueue.Enqueue(run);
         ScanQueuedRuns(runQueue, searchText, addHighlightDelegate);
     }
 }
コード例 #2
0
 void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, Query query)
 {
     while (runQueue.Count > 0)
     {
         runQueue.Dequeue();
         ScanQueuedRuns(runQueue, query, addHighlightDelegate);
     }
 }
コード例 #3
0
 public static void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, string searchText)
 {
     while (runQueue.Count > 0)
     {
         runQueue.Dequeue();
         ScanQueuedRuns(runQueue, searchText, addHighlightDelegate);
     }
 }
コード例 #4
0
 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);
 }
コード例 #5
0
        /// <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;
                }
            }
        }
コード例 #6
0
 /// <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);
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 /// <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);
 }
コード例 #9
0
        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;
                }
            }
        }
コード例 #10
0
        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);

            }
        }
コード例 #11
0
 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);
 }
コード例 #12
0
 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);
 }
コード例 #13
0
 void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, Query query)
 {
     while (runQueue.Count > 0)
     {
         runQueue.Dequeue();
         ScanQueuedRuns(runQueue, query, addHighlightDelegate);
     }
 }
コード例 #14
0
        /*   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);
        }
コード例 #15
0
     /*   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);
        }
コード例 #16
0
        /// <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;
                }


            }
        }
コード例 #17
0
 /// <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);
 }
コード例 #18
0
 public static void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate,RunQueue runQueue, string searchText)
 {
     while (runQueue.Count > 0)
     {
         runQueue.Dequeue();
         ScanQueuedRuns(runQueue, searchText, addHighlightDelegate);
     }
 }
コード例 #19
0
        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;
                    }


            }
        }
コード例 #20
0
 /// <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);
 }