예제 #1
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void EmptyRopeFromString()
        {
            Rope <char> empty = new Rope <char>(string.Empty);

            Assert.AreEqual(0, empty.Length);
            Assert.AreEqual("", empty.ToString());
        }
예제 #2
0
        /// <summary>
        /// Creates a string from the rope. Runs in O(N).
        /// </summary>
        /// <returns>A string consisting of all elements in the rope as comma-separated list in {}.
        /// As a special case, Rope&lt;char&gt; will return its contents as string without any additional separators or braces,
        /// so it can be used like StringBuilder.ToString().</returns>
        /// <remarks>
        /// This method counts as a read access and may be called concurrently to other read accesses.
        /// </remarks>
        public override string ToString()
        {
            Rope <char> charRope = this as Rope <char>;

            if (charRope != null)
            {
                return(charRope.ToString(0, this.Length));
            }
            else
            {
                StringBuilder b = new StringBuilder();
                foreach (T element in this)
                {
                    if (b.Length == 0)
                    {
                        b.Append('{');
                    }
                    else
                    {
                        b.Append(", ");
                    }
                    b.Append(element.ToString());
                }
                b.Append('}');
                return(b.ToString());
            }
        }
예제 #3
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void InitializeRopeFromShortString()
        {
            Rope <char> rope = new Rope <char>("Hello, World");

            Assert.AreEqual(12, rope.Length);
            Assert.AreEqual("Hello, World", rope.ToString());
        }
예제 #4
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void AppendLongTextToEmptyRope()
        {
            string      text = BuildLongString(1000);
            Rope <char> rope = new Rope <char>();

            rope.AddText(text);
            Assert.AreEqual(text, rope.ToString());
        }
예제 #5
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void InitializeRopeFromLongString()
        {
            string      text = BuildLongString(1000);
            Rope <char> rope = new Rope <char>(text);

            Assert.AreEqual(text.Length, rope.Length);
            Assert.AreEqual(text, rope.ToString());
            Assert.AreEqual(text.ToCharArray(), rope.ToArray());
        }
예제 #6
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void ConcatenateSmallRopesToRope()
        {
            StringBuilder b    = new StringBuilder();
            Rope <char>   rope = new Rope <char>();

            for (int i = 1; i <= 1000; i++)
            {
                b.Append(i.ToString());
                b.Append(' ');
                rope.AddRange(CharRope.Create(i.ToString() + " "));
            }
            Assert.AreEqual(b.ToString(), rope.ToString());
        }
예제 #7
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void ConcatenateStringToRope()
        {
            StringBuilder b    = new StringBuilder();
            Rope <char>   rope = new Rope <char>();

            for (int i = 1; i <= 1000; i++)
            {
                b.Append(i.ToString());
                rope.AddText(i.ToString());
                b.Append(' ');
                rope.Add(' ');
            }
            Assert.AreEqual(b.ToString(), rope.ToString());
        }
예제 #8
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void TestToArrayAndToStringWithParts()
        {
            string      text = BuildLongString(1000);
            Rope <char> rope = new Rope <char>(text);

            string textPart = text.Substring(1200, 600);

            char[] arrayPart = textPart.ToCharArray();
            Assert.AreEqual(textPart, rope.ToString(1200, 600));
            Assert.AreEqual(arrayPart, rope.ToArray(1200, 600));

            Rope <char> partialRope = rope.GetRange(1200, 600);

            Assert.AreEqual(textPart, partialRope.ToString());
            Assert.AreEqual(arrayPart, partialRope.ToArray());
        }
예제 #9
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void ConcatenateSmallRopesToRopeBackwards()
        {
            StringBuilder b    = new StringBuilder();
            Rope <char>   rope = new Rope <char>();

            for (int i = 1; i <= 1000; i++)
            {
                b.Append(i.ToString());
                b.Append(' ');
            }
            for (int i = 1000; i >= 1; i--)
            {
                rope.InsertRange(0, CharRope.Create(i.ToString() + " "));
            }
            Assert.AreEqual(b.ToString(), rope.ToString());
        }
예제 #10
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void ConcatenateStringToRopeBackwards()
        {
            StringBuilder b    = new StringBuilder();
            Rope <char>   rope = new Rope <char>();

            for (int i = 1; i <= 1000; i++)
            {
                b.Append(i.ToString());
                b.Append(' ');
            }
            for (int i = 1000; i >= 1; i--)
            {
                rope.Insert(0, ' ');
                rope.InsertText(0, i.ToString());
            }
            Assert.AreEqual(b.ToString(), rope.ToString());
        }
예제 #11
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void ConcatenateSmallRopesByInsertionInMiddle()
        {
            StringBuilder b    = new StringBuilder();
            Rope <char>   rope = new Rope <char>();

            for (int i = 1; i <= 1000; i++)
            {
                b.Append(i.ToString("d3"));
                b.Append(' ');
            }
            int middle = 0;

            for (int i = 1; i <= 500; i++)
            {
                rope.InsertRange(middle, CharRope.Create(i.ToString("d3") + " "));
                middle += 4;
                rope.InsertRange(middle, CharRope.Create((1001 - i).ToString("d3") + " "));
            }
            Assert.AreEqual(b.ToString(), rope.ToString());
        }
예제 #12
0
파일: CharRope.cs 프로젝트: dnGrep/dnGrep
        /// <summary>
        /// Gets the index of the last occurrence of the search text.
        /// </summary>
        public static int LastIndexOf(this Rope <char> rope, string searchText, int startIndex, int length, StringComparison comparisonType)
        {
            if (rope == null)
            {
                throw new ArgumentNullException("rope");
            }
            if (searchText == null)
            {
                throw new ArgumentNullException("searchText");
            }
            rope.VerifyRange(startIndex, length);
            int pos = rope.ToString(startIndex, length).LastIndexOf(searchText, comparisonType);

            if (pos < 0)
            {
                return(-1);
            }
            else
            {
                return(pos + startIndex);
            }
        }
예제 #13
0
파일: RopeTests.cs 프로젝트: sq/ILSpy-JSIL
        public void ConcatenateStringToRopeByInsertionInMiddle()
        {
            StringBuilder b    = new StringBuilder();
            Rope <char>   rope = new Rope <char>();

            for (int i = 1; i <= 998; i++)
            {
                b.Append(i.ToString("d3"));
                b.Append(' ');
            }
            int middle = 0;

            for (int i = 1; i <= 499; i++)
            {
                rope.InsertText(middle, i.ToString("d3"));
                middle += 3;
                rope.Insert(middle, ' ');
                middle++;
                rope.InsertText(middle, (999 - i).ToString("d3"));
                rope.Insert(middle + 3, ' ');
            }
            Assert.AreEqual(b.ToString(), rope.ToString());
        }