예제 #1
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());
            }
        }
예제 #2
0
        /// <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);
            }
        }