Beispiel #1
0
 void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, Query query)
 {
     while (runQueue.Count > 0)
     {
         runQueue.Dequeue();
         ScanQueuedRuns(runQueue, query, addHighlightDelegate);
     }
 }
Beispiel #2
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);
     }
 }
Beispiel #3
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;
                }
            }
        }
Beispiel #4
0
 public static void FillRunQueue(RunQueue rq, List<Run> lr)
 {
     
     for (int i = 0; i < lr.Count; i++)
     {
         rq.Enqueue(lr[i]);
         Assert.AreEqual(i + 1, rq.Count);
         Assert.AreEqual(lr[i].Text, rq[i].Text);
     }
 }
        public void MakeInvalid()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.UseRegularExpressions = true;
            Query q = new Query(".*[");
            RunQueue rq = new RunQueue(1);
            rq.Enqueue(new System.Windows.Documents.Run("hello this is it"));
            model.ScanQueuedRuns(rq, q, null);
            Assert.IsFalse(q.Valid);
            Assert.AreEqual("Regular expression error, parsing \".*[\" - Unterminated [] set.", q.ReasonInvalid);

        }
Beispiel #6
0
        /// <summary>
        /// Clones this.
        /// </summary>
        public RunQueue Clone()
        {
            RunQueue clone = new RunQueue(Size);

            for (int i = 0; i < store.Length; i++)
            {
                clone.store[i] = store[i];
                // clone.runLengths[i] = runLengths[i];
                clone.start = start;
                clone.count = count;
            }
            return(clone);
        }
Beispiel #7
0
        public void TestRunQueue()
        {
            RunQueue rq = new RunQueue(5);
            FillRunQueue(rq, GetTestRuns());

            //now wrap
            rq.Enqueue(new Run("bbbb"));
            Assert.AreEqual(5, rq.Count);
            rq.Enqueue(new Run("cccc"));
            Assert.AreEqual(5, rq.Count);

            Assert.AreEqual("5555 6666", rq[0].Text);
            Assert.AreEqual("7777 8888", rq[1].Text);
            Assert.AreEqual("9999 aaaa", rq[2].Text);
            Assert.AreEqual("bbbb", rq[3].Text);
            Assert.AreEqual("cccc", rq[4].Text);

        }
Beispiel #8
0
        public void TestScanRunQueue()
        {
            RunQueue rq = new RunQueue(5) ;
            
            FillRunQueue(rq, GetTestRuns());

            RunQueue rq_clone = rq.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            //easy one
            model.ScanQueuedRuns(rq, new Keyoti.RapidFindReplace.WPF.Query("1111"), 
                delegate(Run run, int index, int length){
                    Assert.AreEqual(rq_clone[0].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(4, length);
                }
            );

            //easy one
            model.ScanQueuedRuns(rq, "4444",
                delegate(Run run, int index, int length)
                {
                    Assert.AreEqual(rq_clone[1].Run, run);
                    Assert.AreEqual(5, index);
                    Assert.AreEqual(4, length);
                }
            );

            //harder one
            int callInc = 0;
            model.ScanQueuedRuns(rq, "44445555",
                delegate(Run run, int index, int length)
                {
                    if (callInc == 0)
                    {
                        Assert.AreEqual(rq_clone[1].Run, run);
                        Assert.AreEqual(5, index);
                        Assert.AreEqual(4, length);
                    }
                    else if (callInc == 1)
                    {
                        Assert.AreEqual(rq_clone[2].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(4, length);
                    }
                    callInc++;
                }
            );

            //harder one
            callInc = 0;
            RunQueue rq2 = new RunQueue(5);
            
            FillRunQueue(rq2, GetTestRuns2());
            RunQueue rq2_clone = rq2.Clone();
            model.ScanQueuedRuns(rq2, "22223",
                delegate(Run run, int index, int length)
                {
                    if (callInc == 0)
                    {
                        Assert.AreEqual(rq2_clone[0].Run, run);
                        Assert.AreEqual(2, index);
                        Assert.AreEqual(4, length);
                    }
                    else if (callInc == 1)
                    {
                        Assert.AreEqual(rq2_clone[1].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }

                    Assert.IsTrue(callInc < 2);
                    callInc++;
                }
            );
        
        }
Beispiel #9
0
        public void TestCrossRunMatch2()
        {
            RunQueue queue = new RunQueue(2);
            Run r1 = new Run("1234co"), r2 = new Run("co5678");
            int callInc = 0;
            queue.Enqueue(r1);
            queue.Enqueue(r2);
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.ScanQueuedRuns(queue, "coco",
                delegate(Run run, int index, int length)
                {
                    Assert.IsTrue(callInc < 2);
                    if (callInc == 0)
                    {

                        Assert.AreEqual(r1, run);
                        Assert.AreEqual(4, index);
                        Assert.AreEqual(2, length);
                    }
                    else if (callInc == 1)
                    {
                        Assert.AreEqual(r2, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(2, length);
                    }
                    callInc++;
                }
             );
            Assert.AreEqual(2, callInc);
        }
Beispiel #10
0
        public void TestScanRunQueueMultipleTimes3()
        {
            //harder one
            int callInc = 0;
            RunQueue rq2 = new RunQueue(5);
            FillRunQueue(rq2, GetTestRuns2());
            
            rq2.Enqueue(new Run("3 3"));
            rq2.Enqueue(new Run("232"));
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.ScanQueuedRuns(rq2, "3",
                delegate(Run run, int index, int length)
                {
                    Assert.IsTrue(callInc< 4);
                    if (callInc == 0)
                    {

                        Assert.AreEqual(rq2_clone[1].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }
                    else if (callInc == 1)
                    {

                        Assert.AreEqual(rq2_clone[3].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }
                    else if (callInc == 2)
                    {

                        Assert.AreEqual(rq2_clone[3].Run, run);
                        Assert.AreEqual(2, index);
                        Assert.AreEqual(1, length);
                    }
                    else if (callInc == 3)
                    {

                        Assert.AreEqual(rq2_clone[4].Run, run);
                        Assert.AreEqual(1, index);
                        Assert.AreEqual(1, length);
                    }
                    callInc++;

                }
            );
            

        }
Beispiel #11
0
        public void TestScanRunQueueMultipleTimes2()
        {
            //harder one
            int callInc = 0;
            RunQueue rq2 = new RunQueue(5);
            FillRunQueue(rq2, GetTestRuns2());
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.ScanQueuedRuns(rq2, "3",
                delegate(Run run, int index, int length)
                {
                    Assert.IsTrue(callInc < 1);
                    if (callInc == 0)
                    {
                        Assert.AreEqual(rq2_clone[1].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }
                    callInc++;

                }
            );
            //add new item and search again, this time we don't want to hit 3 again
            rq2.Enqueue(new Run("3"));
            model.ScanQueuedRuns(rq2, "3",
                delegate(Run run, int index, int length)
                {

                    Assert.AreEqual("3", run.Text);

                }
            );

        }
 void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, Query query)
 {
     while (runQueue.Count > 0)
     {
         runQueue.Dequeue();
         ScanQueuedRuns(runQueue, query, addHighlightDelegate);
     }
 }
Beispiel #13
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);
        }
        /// <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;
                }


            }
        }
     /*   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);
        }
Beispiel #16
0
        /// <summary>
        /// Clones this.
        /// </summary>
        public RunQueue Clone()
        {
            RunQueue clone = new RunQueue(Size);
            for (int i = 0; i < store.Length; i++)
            {
                clone.store[i] = store[i];
               // clone.runLengths[i] = runLengths[i];
                clone.start = start;
                clone.count = count;

            }
            return clone;
        }
        void ProcessRun(AddHighlight addHighlightDelegate, Run run, RunQueue runQueue, Query searchText)
        {
            if (run != null && !string.IsNullOrEmpty(run.Text))
            {

                runQueue.Enqueue(run);
                ScanQueuedRuns(runQueue, searchText, addHighlightDelegate);

            }
        }