コード例 #1
0
 /// <summary>
 /// Retrieves the text for a portion of the rope.
 /// Runs in O(lg N + M), where M=<paramref name="length"/>.
 /// </summary>
 /// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
 /// <remarks>
 /// This method counts as a read access and may be called concurrently to other read accesses.
 /// </remarks>
 public static string ToString(this Rope <char> rope, int startIndex, int length)
 {
     if (rope == null)
     {
         throw new ArgumentNullException(nameof(rope));
     }
     if (length == 0)
     {
         return(string.Empty);
     }
     char[] buffer = new char[length];
     rope.CopyTo(startIndex, buffer, 0, length);
     return(new string(buffer));
 }
コード例 #2
0
        /// <summary>
        /// Retrieves the text for a portion of the rope.
        /// Runs in O(lg N + M), where M=<paramref name="length"/>.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
        /// <remarks>
        /// This method counts as a read access and may be called concurrently to other read accesses.
        /// </remarks>
        public static string ToString(this Rope <char> rope, int startIndex, int length)
        {
            if (rope == null)
            {
                throw new ArgumentNullException("rope");
            }
            //CHANGE: Fixes an issue if there's no line intendation in which under certain conditions causes an overflow since the length is -1

            // the actual problem is found here:
            // ICSharpCode.NRefactory.Editor.ReadOnlyDocument.GetText
            // ICSharpCode.NRefactory.CSharp.Completion.CSharpCompletionEngine.GetLineIndent, which should never call this method with a length of -1
            if (length <= 0)
            {
                return(string.Empty);
            }
            char[] buffer = new char[length];
            rope.CopyTo(startIndex, buffer, 0, length);
            return(new string(buffer));
        }
コード例 #3
0
ファイル: CharRope.cs プロジェクト: dnGrep/dnGrep
        /// <summary>
        /// Retrieves the text for a portion of the rope.
        /// Runs in O(lg N + M), where M=<paramref name="length"/>.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
        /// <remarks>
        /// This method counts as a read access and may be called concurrently to other read accesses.
        /// </remarks>
        public static string ToString(this Rope <char> rope, int startIndex, int length)
        {
            if (rope == null)
            {
                throw new ArgumentNullException("rope");
            }
#if DEBUG
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException("length", length, "Value must be >= 0");
            }
#endif
            if (length == 0)
            {
                return(string.Empty);
            }
            char[] buffer = new char[length];
            rope.CopyTo(startIndex, buffer, 0, length);
            return(new string(buffer));
        }