Ejemplo n.º 1
0
        public void TestSearchBackwardMany()
        {
            GapBuffer buffer = new GapBuffer();

            buffer.Text = new string ('a', 100);
            Assert.AreEqual(100, buffer.SearchBackward("a", buffer.Length).Count());
        }
Ejemplo n.º 2
0
        public void ComplexOperationTests()
        {
            var          gapBuffer = new GapBuffer();
            const string lorem     = "Lorem";

            gapBuffer.Insert(' ', 0);

            foreach (var character in lorem)
            {
                gapBuffer.Insert(character, gapBuffer.GetLength());
            }

            var actualResult = gapBuffer.GetText(0, gapBuffer.GetLength() - 1);

            Assert.AreEqual(" Lorem", actualResult, "The returned text differs.");


            foreach (var character in lorem)
            {
                gapBuffer.Insert(character, 0);
            }

            actualResult = gapBuffer.GetText(0, gapBuffer.GetLength() - 1);
            Assert.AreEqual("meroL Lorem", actualResult, "The returned text differs.");

            gapBuffer.Delete(3, 3);
            actualResult = gapBuffer.GetText(0, gapBuffer.GetLength() - 1);
            Assert.AreEqual("merL Lorem", actualResult, "The returned text differs.");

            gapBuffer.Delete(0, gapBuffer.GetLength() - 1);
            actualResult = gapBuffer.GetText(0, 0);
            Assert.AreEqual(default, actualResult, "The returned text differs.");
Ejemplo n.º 3
0
        public void GapBuffer_RemoveTest()
        {
            GapBuffer <int> buf = CreateTestGapBuffer();

            Assert.IsFalse(buf.Remove(0));

            Assert.AreEqual(16, buf.IndexOf(999));
            Assert.IsTrue(buf.Remove(999));
            Assert.AreEqual(-1, buf.IndexOf(999));

            buf.RemoveAt(1);
            Assert.AreEqual(1, buf.Gap);

            buf.RemoveAt(0);
            Assert.AreEqual(23, buf.Count);
            Assert.AreEqual(0, buf.Gap);
            Assert.AreEqual(9, buf.GapCount);
            Assert.AreEqual(9, buf.AfterGap);

            buf.RemoveAt(21);
            Assert.AreEqual(21, buf.Gap);

            buf.RemoveAt(21);
            Assert.AreEqual(21, buf.Count);
            Assert.AreEqual(21, buf.Gap);
            Assert.AreEqual(11, buf.GapCount);
            Assert.AreEqual(32, buf.AfterGap);

            for (int i = 0; i < buf.Count; i++)
            {
                Assert.AreEqual(102 + i, buf[i]);
            }
        }
Ejemplo n.º 4
0
        public void GapBuffer_RealAndVirtualTest()
        {
            GapBuffer <int> buf = CreateTestGapBuffer();

            Assert.AreEqual(26, buf.Count);
            Assert.AreEqual(17, buf.Gap);
            Assert.AreEqual(23, buf.AfterGap);
            Assert.AreEqual(6, buf.GapCount);
            Assert.AreEqual(32, buf.AllocatedCount);

            Assert.AreEqual(26, buf.Count);
            Assert.AreEqual(0, buf.ToReal(0));
            Assert.AreEqual(16, buf.ToReal(16));
            Assert.AreEqual(23, buf.ToReal(17));
            Assert.AreEqual(32, buf.ToReal(26));

            Assert.AreEqual(0, buf.ToVirtual(0));
            Assert.AreEqual(16, buf.ToVirtual(16));
            Assert.AreEqual(17, buf.ToVirtual(23));
            Assert.AreEqual(26, buf.ToVirtual(32));

            buf.Clear();
            Assert.AreEqual(0, buf.Count);
            Assert.AreEqual(0, buf.ToReal(0));
            Assert.AreEqual(0, buf.ToVirtual(0));
        }
Ejemplo n.º 5
0
        public void InsertTest()
        {
            var gb = new GapBuffer <int>(4);

            gb.Insert(0, 1);

            Assert.Equal(1, gb.Count);
            Assert.Equal(1, gb[0]);
        }
Ejemplo n.º 6
0
        GapBuffer <char> replacement, replaced;   //置き換え後の文字列、置き換え前の文字列

        public ReplaceCommand(StringBuffer buf, int start, int length, string str)
        {
            this.Buffer           = buf;
            this.ReplacementRange = new TextRange(start, str.Length);
            this.replacement      = new GapBuffer <char>();
            this.replacement.AddRange(Util.GetEnumrator(str));
            this.ReplacedRange = new TextRange(start, length);
            this.replaced      = new GapBuffer <char>();
            this.replaced.AddRange(this.Buffer.GetEnumerator(start, length));
        }
Ejemplo n.º 7
0
        internal void Replace(GapBuffer <char> buf)
        {
            using (this.rwlock.WriterLock())
            {
                this.Clear();
                this.buf = buf;
            }

            this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, 0, 0, buf.Count));
        }
Ejemplo n.º 8
0
        public void TestSearchBackward()
        {
            GapBuffer buffer = new GapBuffer();

            for (int i = 0; i < 100; i++)
            {
                buffer.Insert(0, "a");
            }
            var idx = new List <int> (new [] { 0, buffer.Length / 2, buffer.Length });

            idx.ForEach(i => buffer.Insert(i, "test"));

            // move gap to the beginning
            buffer.Replace(idx[0], 1, buffer.GetCharAt(idx[0]).ToString());

            List <int> results = new List <int> (buffer.SearchBackward("test", buffer.Length));

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);

            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }

            // move gap to the middle
            buffer.Replace(idx[1], 1, buffer.GetCharAt(idx[1]).ToString());

            results = new List <int> (buffer.SearchBackward("test", buffer.Length));
            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }

            // move gap to the end
            buffer.Replace(idx[2], 1, buffer.GetCharAt(idx[2]).ToString());

            results = new List <int> (buffer.SearchBackward("test", buffer.Length));

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }

            // move gap to the end
            buffer.Replace(buffer.Length - 1, 1, buffer.GetCharAt(buffer.Length - 1).ToString());

            results = new List <int> (buffer.SearchBackward("test", buffer.Length));
            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }
        }
Ejemplo n.º 9
0
        private void Fill(GapBuffer <int> gb, List <int> l, int count)
        {
            var rng = new Random(0);

            for (int i = 0; i < count; i++)
            {
                var n = rng.Next(i);
                l.Insert(n, i);
                gb.Insert(n, i);
            }
        }
Ejemplo n.º 10
0
        public void GapBuffer_ToArrayTest()
        {
            GapBuffer <int> buf = CreateTestGapBuffer();

            int[] array = buf.ToArray();
            Assert.AreEqual(buf.Count, array.Length);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(buf[i], array[i]);
            }
        }
Ejemplo n.º 11
0
        public void InsertTest2()
        {
            var l  = new List <int>(4);
            var gb = new GapBuffer <int>(4);

            Fill(gb, l, 1000);

            Assert.Equal(l.Count, gb.Count);
            for (int i = 0; i < l.Count; i++)
            {
                Assert.Equal(l[i], gb[i]);
            }
        }
Ejemplo n.º 12
0
        public void InsertStringTest()
        {
            // Arrange.
            var gapBuffer      = new GapBuffer();
            var expectedResult = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse nisl.";

            // Act.
            gapBuffer.Insert(expectedResult, 0);
            var actualResult = gapBuffer.GetText(0, gapBuffer.GetLength() - 1);

            // Assert.
            Assert.AreEqual(expectedResult, actualResult, "The buffer storage content differs.");
        }
Ejemplo n.º 13
0
        public void GapBuffer_ConstructTest()
        {
            GapBuffer <int> buf = new GapBuffer <int>();

            Assert.AreEqual(0, buf.Count);
            Assert.AreEqual(0, buf.ToReal(0));
            Assert.AreEqual(0, buf.ToVirtual(0));
            Assert.AreEqual(0, buf.Gap);
            Assert.AreEqual(0, buf.AfterGap);
            Assert.AreEqual(0, buf.GapCount);
            Assert.AreEqual(0, buf.AllocatedCount);
            Assert.IsFalse(buf.IsReadOnly);
        }
Ejemplo n.º 14
0
        public void GetLengthInsertTest()
        {
            // Arrange.
            var gapBuffer      = new GapBuffer();
            var expectedResult = 5;

            // Act.
            gapBuffer.Insert("Lorem", 0);
            var actualResult = gapBuffer.GetLength();

            // Assert.
            Assert.AreEqual(expectedResult, actualResult, "The buffer storage length differs.");
        }
Ejemplo n.º 15
0
        private static GapBuffer <int> CreateTestGapBuffer()
        {
            GapBuffer <int> buf = new GapBuffer <int>();

            for (int i = 100; i < 125; i++)
            {
                buf.Add(i);
            }

            buf.Insert(16, 999);

            return(buf);
        }
Ejemplo n.º 16
0
        public void GetTextMiddleStringTest()
        {
            // Arrange.
            var gapBuffer      = new GapBuffer();
            var expectedResult = "ipsum";

            gapBuffer.Insert("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse nisl.", 0);

            // Act.
            var actualResult = gapBuffer.GetText(6, 10);

            // Assert.
            Assert.AreEqual(expectedResult, actualResult, "The returned text differs.");
        }
        public void TestSearchBackwardMany()
        {
            GapBuffer buffer = new GapBuffer();

            buffer.Text = new string ('a', 100);
            int cnt = 0;
            int o   = buffer.TextLength;

            while (o > 0 && (o = buffer.LastIndexOf("a", o - 1, o, StringComparison.Ordinal)) != -1)
            {
                cnt++;
            }
            Assert.AreEqual(100, cnt);
        }
        public void TestSearchForwardMany()
        {
            GapBuffer buffer = new GapBuffer();

            buffer.Text = new string ('a', 100);
            int cnt = 0;
            int o   = 0;

            while ((o = buffer.IndexOf("a", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                cnt++;
                o++;
            }
            Assert.AreEqual(100, cnt);
        }
Ejemplo n.º 19
0
        public void RemoveTest()
        {
            var gb = new GapBuffer <int>(4);

            gb.InsertRange(0, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9);

            gb.RemoveRange(3, 4);

            Assert.Equal(5, gb.Count);
            Assert.Equal(1, gb[0]);
            Assert.Equal(2, gb[1]);
            Assert.Equal(3, gb[2]);
            Assert.Equal(8, gb[3]);
            Assert.Equal(9, gb[4]);
        }
Ejemplo n.º 20
0
        public void GapBuffer_IndexOfTest()
        {
            GapBuffer <int> buf = CreateTestGapBuffer();

            Assert.AreEqual(0, buf.IndexOf(100));
            Assert.AreEqual(15, buf.IndexOf(115));
            Assert.AreEqual(17, buf.IndexOf(116));
            Assert.AreEqual(25, buf.IndexOf(124));
            Assert.AreEqual(-1, buf.IndexOf(125));
            Assert.AreEqual(16, buf.IndexOf(999));

            Assert.IsTrue(buf.Contains(100));
            Assert.IsTrue(buf.Contains(999));
            Assert.IsFalse(buf.Contains(0));
        }
Ejemplo n.º 21
0
        public void EnlargeTest()
        {
            var gb = new GapBuffer <int>(2);

            gb.Insert(0, 3);
            gb.Insert(1, 4);
            gb.Insert(0, 1);
            gb.Insert(3, 5);
            gb.Insert(1, 2);

            Assert.Equal(5, gb.Count);
            Assert.Equal(1, gb[0]);
            Assert.Equal(2, gb[1]);
            Assert.Equal(3, gb[2]);
            Assert.Equal(4, gb[3]);
            Assert.Equal(5, gb[4]);
        }
Ejemplo n.º 22
0
		public void TestSearchForward ()
		{
			GapBuffer buffer = new GapBuffer ();
			for (int i = 0; i < 100; i++) {
				buffer.Insert (0, "a");
			}
			var idx = new List<int> (new [] { 0,  buffer.Length / 2, buffer.Length });
			
			idx.ForEach (i => buffer.Insert (i, "test"));
			
			// move gap to the beginning
			buffer.Replace (idx[0], 1, buffer.GetCharAt (idx[0]).ToString ());
			
			List<int> results = new List<int> (buffer.SearchForward ("test", 0));
			
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
			
			// move gap to the middle
			buffer.Replace (idx[1], 1, buffer.GetCharAt (idx[1]).ToString ());
			
			results = new List<int> (buffer.SearchForward ("test", 0));
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
			
			// move gap to the end
			buffer.Replace (idx[2], 1, buffer.GetCharAt (idx[2]).ToString ());
			
			results = new List<int> (buffer.SearchForward ("test", 0));
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
			
			// move gap to the end
			buffer.Replace (buffer.Length - 1, 1, buffer.GetCharAt (buffer.Length - 1).ToString ());
			
			results = new List<int> (buffer.SearchForward ("test", 0));
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
		}
Ejemplo n.º 23
0
        public void InsertCharTest()
        {
            // Arrange.
            var gapBuffer      = new GapBuffer();
            var expectedResult = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse nisl.";

            // Act.
            var index = 0;

            foreach (var character in expectedResult)
            {
                gapBuffer.Insert(character, index);
                index++;
            }

            var actualResult = gapBuffer.GetText(0, gapBuffer.GetLength() - 1);

            // Assert.
            Assert.AreEqual(expectedResult, actualResult, "The buffer storage content differs.");
        }
Ejemplo n.º 24
0
        public EntityComponentRegistry(int capacity, Type[] types)
        {
            alive = new GapBuffer <int>(capacity);
            flags = new ulong[capacity];
            gens  = new byte[capacity];

            entities = new RingBuffer <int>(capacity);
            for (var i = 0; i < capacity; i++)
            {
                entities.Enqueue(i);
            }

            components = new IComponentRegistry[types.Length];
            for (var typeIndex = 0; typeIndex < types.Length; typeIndex++)
            {
                var t = types[typeIndex];
                typeIndices[t]        = typeIndex;
                components[typeIndex] = CreateComponentRegistry(t);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Use this when you wish to tokenize only a partial string in a longer string
        /// Allows you to start with a comment depth different of 0
        /// </summary>
        public ProTokenizer(string data, int posOffset, int initLine, int initColumn, int initCommentDepth, int initIncludeDepth, bool initInDoubleQuoteString, bool initInSimpleQuoteString, Action <int, int, int, bool, bool> pushLineInfo)
        {
            _offset                         = posOffset;
            _line                           = initLine;
            _column                         = initColumn;
            _commentDepth                   = initCommentDepth;
            _includeDepth                   = initIncludeDepth;
            _pushLineInfo                   = pushLineInfo;
            _inDoubleQuoteString            = initInDoubleQuoteString;
            _inSimpleQuoteString            = initInSimpleQuoteString;
            _includeDepthWhenEnteringString = _inDoubleQuoteString || _inSimpleQuoteString ?_includeDepth : 0;

            // push first line info
            if (_pushLineInfo != null)
            {
                _pushLineInfo(_line, _commentDepth, IncludeDepth, _inDoubleQuoteString, _inSimpleQuoteString);
            }

            _tokenList = new GapBuffer <Token>();
            Construct(data);
        }
Ejemplo n.º 26
0
        public void InsertTest3()
        {
            var l  = new List <int>(4);
            var gb = new GapBuffer <int>(4);

            Fill(gb, l, 1000);

            var rng = new Random(1);

            for (int i = 0; i < 500; i++)
            {
                var n = rng.Next(i);
                l.RemoveAt(n);
                gb.RemoveAt(n);
            }

            Assert.Equal(l.Count, gb.Count);
            for (int i = 0; i < l.Count; i++)
            {
                Assert.Equal(l[i], gb[i]);
            }
        }
Ejemplo n.º 27
0
        public void GapBuffer_RemoveRangeTest()
        {
            GapBuffer <int> buf = CreateTestGapBuffer();

            buf.RemoveRange(8, 16);
            Assert.AreEqual(10, buf.Count);
            Assert.AreEqual(8, buf.Gap);
            Assert.AreEqual(22, buf.GapCount);

            buf.RemoveRange(0, 5);
            Assert.AreEqual(5, buf.Count);
            Assert.AreEqual(0, buf.Gap);
            Assert.AreEqual(27, buf.GapCount);

            Assert.AreEqual(105, buf[0]);
            Assert.AreEqual(106, buf[1]);
            Assert.AreEqual(124, buf[4]);

            buf.RemoveRange(0, 5);
            Assert.AreEqual(0, buf.Count);
            Assert.AreEqual(0, buf.Gap);
            Assert.AreEqual(32, buf.GapCount);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// constructor
 /// </summary>
 public ProLexer(string data)
 {
     _tokenList = new GapBuffer <Token>();
     Construct(data);
 }
Ejemplo n.º 29
0
        public int IndexOf(GapBuffer <char> buf, int start, int end)
        {
            //QuickSearch法
            int buflen     = buf.Count - 1;
            int plen       = this.patternLength;
            int i          = start;
            int search_end = end - plen;

            //最適化のためわざとコピペした
            if (this.caseInsenstive)
            {
                while (i <= search_end)
                {
                    int j = 0;
                    while (j < plen)
                    {
                        if (CharTool.ToUpperFastIf(buf[i + j]) != this.pattern[j])
                        {
                            break;
                        }
                        j++;
                    }
                    if (j == plen)
                    {
                        return(i);
                    }
                    else
                    {
                        int k = i + plen;
                        if (k <= buflen)        //buffer以降にアクセスする可能性がある
                        {
                            int moveDelta;
                            if (this.qsTable.TryGetValue(buf[k], out moveDelta))
                            {
                                i += moveDelta;
                            }
                            else
                            {
                                i += plen;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                while (i <= search_end)
                {
                    int j = 0;
                    while (j < plen)
                    {
                        if (buf[i + j] != this.pattern[j])
                        {
                            break;
                        }
                        j++;
                    }
                    if (j == plen)
                    {
                        return(i);
                    }
                    else
                    {
                        int k = i + plen;
                        if (k <= buflen)        //buffer以降にアクセスする可能性がある
                        {
                            int moveDelta;
                            if (this.qsTable.TryGetValue(buf[k], out moveDelta))
                            {
                                i += moveDelta;
                            }
                            else
                            {
                                i += plen;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            return(-1);
        }
Ejemplo n.º 30
0
        public void TestSearchBackward()
        {
            GapBuffer buffer = new GapBuffer ();
            for (int i = 0; i < 100; i++) {
                buffer.Insert (0, "a");
            }
            var idx = new List<int> (new [] { 0,  buffer.TextLength / 2, buffer.TextLength });

            idx.ForEach (i => buffer.Insert (i, "test"));

            // move gap to the beginning
            buffer.Replace (idx [0], 1, buffer.GetCharAt (idx [0]).ToString ());

            List<int> results = new List<int> ();
            int o = buffer.TextLength;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);

            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [idx.Count - 1 - i], results [i], (i + 1) + ". match != " + idx [idx.Count - 1 - i] + " was " + results [i]);

            // move gap to the middle
            buffer.Replace (idx [1], 1, buffer.GetCharAt (idx [1]).ToString ());

            results = new List<int> ();
            o = buffer.TextLength - 1;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [idx.Count - 1 - i], results [i], (i + 1) + ". match != " + idx [idx.Count - 1 - i] + " was " + results [i]);

            // move gap to the end
            buffer.Replace (idx [2], 1, buffer.GetCharAt (idx [2]).ToString ());

            results = new List<int> ();
            o = buffer.TextLength - 1;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [idx.Count - 1 - i], results [i], (i + 1) + ". match != " + idx [idx.Count - 1 - i] + " was " + results [i]);

            // move gap to the end
            buffer.Replace (buffer.TextLength - 1, 1, buffer.GetCharAt (buffer.TextLength - 1).ToString ());

            results = new List<int> ();
            o = buffer.TextLength - 1;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }
            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx[idx.Count -  1 - i], results[i], (i + 1) +". match != " + idx[idx.Count -  1 - i] +  " was " + results[i]);
        }
Ejemplo n.º 31
0
 public void TestSearchForwardMany()
 {
     GapBuffer buffer = new GapBuffer ();
     buffer.Text = new string ('a', 100);
     int cnt = 0;
     int o = 0;
     while ((o = buffer.IndexOf ("a", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0) {
         cnt++;
         o++;
     }
     Assert.AreEqual (100, cnt);
 }
Ejemplo n.º 32
0
 public void TestSearchBackwardMany()
 {
     GapBuffer buffer = new GapBuffer ();
     buffer.Text = new string ('a', 100);
     int cnt = 0;
     int o = buffer.TextLength;
     while (o > 0 && (o = buffer.LastIndexOf ("a", o - 1, o, StringComparison.Ordinal)) != -1) {
         cnt++;
     }
     Assert.AreEqual (100, cnt);
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Initializes a new instance
 /// </summary>
 public DocumentLines()
 {
     _linesList = new GapBuffer<int> {0, 0};
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Simulates the insertion of the whole text, use this to reset the lines info 
        /// (when switching document for instance)
        /// </summary>
        internal void Reset()
        {
            _lastEncoding = Npp.Encoding;
            _oneByteCharEncoding = _lastEncoding.Equals(Encoding.Default);

            // bypass the hard work for simple encoding
            if (_oneByteCharEncoding)
                return;

            _linesList = new GapBuffer<int> { 0, 0 };
            var scn = new SCNotification {
                linesAdded = SciGetLineCount() - 1,
                position = 0,
                length = SciGetLength()
            };
            scn.text = Npp.Sci.Send(SciMsg.SCI_GETRANGEPOINTER, new IntPtr(scn.position), new IntPtr(scn.length));
            OnInsertedText(scn);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Parses a list of tokens into a list of parsedItems
        /// </summary>
        public Parser(GapBuffer <Token> tokens, string filePathBeingParsed, ParsedScopeBlock defaultScope, bool matchKnownWords, StringBuilder debugListOut)
        {
            // process inputs
            _filePathBeingParsed = filePathBeingParsed;
            _matchKnownWords     = matchKnownWords && KnownStaticItems != null;

            var rootToken = new TokenEos(null, 0, 0, 0, 0)
            {
                OwnerNumber = 0
            };

            // the first of this list represents the file currently being parsed
            _parsedIncludes.Add(
                new ParsedIncludeFile(
                    "root",
                    rootToken,
                    // the preprocessed variable {0} equals to the filename...
                    new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase)
            {
                { "0", Path.GetFileName(FilePathBeingParsed) }
            },
                    _filePathBeingParsed,
                    null)
                );

            // init context
            _context = new ParseContext {
                BlockStack              = new Stack <ParsedScope>(),
                CurrentStatement        = new ParsedStatement(rootToken),
                CurrentStatementIsEnded = true
            };

            // create root item
            var rootScope = defaultScope ?? new ParsedFile("Root", rootToken);

            _context.BlockStack.Push(rootScope);
            if (defaultScope == null)
            {
                AddParsedItem(rootScope, 0);
            }

            // Analyze
            _tokenList  = tokens;
            _tokenCount = _tokenList.Count;
            _tokenPos   = -1;
            ReplaceIncludeAndPreprocVariablesAhead(1); // replaces an include or a preproc var {&x} at token position 0
            ReplaceIncludeAndPreprocVariablesAhead(2); // @position 1
            while (MoveNext())
            {
                try {
                    Analyze();
                } catch (Exception e) {
                    ErrorHandler.LogError(e, "Error while parsing the following file : " + filePathBeingParsed);
                }
            }
            AddLineInfo(_tokenList[_tokenList.Count - 1]); // add info on last line
            PopOneStatementIndentBlock(0);                 // make sure to pop the final block

            // add missing values to the line dictionary
            // missing values will be for the lines within a multilines comment/string for which we didn't match an EOL to add line info
            var currentLineInfo = _lineInfo[_tokenList[_tokenList.Count - 1].Line];

            for (int i = PeekAt(-1).Line - 1; i >= 0; i--)
            {
                if (!_lineInfo.ContainsKey(i))
                {
                    _lineInfo.Add(i, currentLineInfo);
                }
                else
                {
                    currentLineInfo = _lineInfo[i];
                }
            }

            // check for parser errors
            while (_context.BlockStack.Count > 1)
            {
                ParsedScope scope = _context.BlockStack.Pop();
                // check that we match a RESUME for each SUSPEND
                if (scope is ParsedScopePreProcBlock)
                {
                    _parserErrors.Add(new ParserError(ParserErrorType.MissingUibBlockEnd, PeekAt(-1), _context.BlockStack.Count, _parsedIncludes));
                }

                // check that we match an &ENDIF for each &IF
                else if (scope is ParsedScopePreProcIfBlock)
                {
                    _parserErrors.Add(new ParserError(ParserErrorType.MissingPreprocEndIf, PeekAt(-1), _context.BlockStack.Count, _parsedIncludes));
                }

                // check that we match an END. for each block
                else
                {
                    _parserErrors.Add(new ParserError(ParserErrorType.MissingBlockEnd, PeekAt(-1), _context.BlockStack.Count, _parsedIncludes));
                }
            }

            // returns the concatenation of all the tokens once the parsing is done
            if (debugListOut != null)
            {
                foreach (var token in _tokenList)
                {
                    debugListOut.Append(token.Value);
                }
            }

            // dispose
            _context.BlockStack = null;
            _context            = null;
            _tokenList          = null;
            _functionPrototype  = null;
            _parsedIncludes     = null;
            _knownWords         = null;

            // if we are parsing an include file that was saved for later use, update it
            if (SavedTokenizerInclude.ContainsKey(filePathBeingParsed))
            {
                SavedTokenizerInclude.Remove(filePathBeingParsed);
            }
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Parses a text into a list of parsedItems
        /// </summary>
        public Parser(ProLexer proLexer, string filePathBeingParsed, ParsedScopeItem defaultScope, bool matchKnownWords)
        {
            // process inputs
            _filePathBeingParsed = filePathBeingParsed;
            _matchKnownWords     = matchKnownWords && KnownStaticItems != null;

            // the first of this list represents the file currently being parsed
            _parsedIncludes.Add(
                new ParsedIncludeFile(
                    "root",
                    new TokenEos(null, 0, 0, 0, 0),
                    // the preprocessed variable {0} equals to the filename...
                    new Dictionary <string, List <Token> >(StringComparer.CurrentCultureIgnoreCase)
            {
                { "0", new List <Token> {
                      new TokenWord(Path.GetFileName(FilePathBeingParsed), 0, 0, 0, 0)
                  } }
            },
                    _filePathBeingParsed,
                    null)
                );

            // init context
            _context = new ParseContext {
                BlockStack     = new Stack <BlockInfo>(),
                PreProcIfStack = new Stack <ParsedPreProcBlock>(),
                UibBlockStack  = new Stack <ParsedPreProcBlock>()
            };

            // create root item
            if (defaultScope == null)
            {
                var rootToken = new TokenEos(null, 0, 0, 0, 0);
                rootToken.OwnerNumber = 0;
                _rootScope            = new ParsedFile("Root", rootToken);
                AddParsedItem(_rootScope, rootToken.OwnerNumber);
            }
            else
            {
                _rootScope = defaultScope;
            }
            _context.Scope = _rootScope;

            // Analyze
            _tokenList  = proLexer.GetTokensList;
            _tokenCount = _tokenList.Count;
            ReplacePreProcVariablesAhead(1); // replaces a preproc var {&x} at token position 0
            ReplacePreProcVariablesAhead(2); // replaces a preproc var {&x} at token position 1
            while (MoveNext())
            {
                try {
                    Analyze();
                } catch (Exception e) {
                    ErrorHandler.LogError(e, "Error while parsing the following file : " + filePathBeingParsed);
                }
            }

            // add missing values to the line dictionary
            var current = new LineInfo(GetCurrentDepth(), _rootScope);

            for (int i = proLexer.MaxLine; i >= 0; i--)
            {
                if (_lineInfo.ContainsKey(i))
                {
                    current = _lineInfo[i];
                }
                else
                {
                    _lineInfo.Add(i, current);
                }
            }

            // check that we match an &ENDIF for each &IF
            if (_context.PreProcIfStack.Count > 0)
            {
                _parserErrors.Add(new ParserError(ParserErrorType.MismatchNumberOfIfEndIf, PeekAt(0), _context.PreProcIfStack.Count, _parsedIncludes));
            }

            // dispose
            _context.BlockStack.Clear();
            _context.PreProcIfStack.Clear();
            _context.UibBlockStack.Clear();
            _context   = null;
            _tokenList = null;

            // if we are parsing an include file that was saved for later use, update it
            if (SavedLexerInclude.ContainsKey(filePathBeingParsed))
            {
                SavedLexerInclude.Remove(filePathBeingParsed);
            }
        }
Ejemplo n.º 37
0
		public void TestSearchBackwardMany ()
		{
			GapBuffer buffer = new GapBuffer ();
			buffer.Text = new string ('a', 100);
			Assert.AreEqual (100, buffer.SearchBackward ("a", buffer.Length).Count ());
		}