コード例 #1
0
        public override StringRebuilder Substring(Span span)
        {
            if (span.End > this.Length)
            {
                throw new ArgumentOutOfRangeException("span");
            }

            if (span.Length == this.Length)
            {
                return(this);
            }
            else if (span.End <= _left.Length)
            {
                return(_left.Substring(span));
            }
            else if (span.Start >= _left.Length)
            {
                return(_right.Substring(new Span(span.Start - _left.Length, span.Length)));
            }
            else
            {
                return(BinaryStringRebuilder.Create(_left.Substring(Span.FromBounds(span.Start, _left.Length)),
                                                    _right.Substring(Span.FromBounds(0, span.End - _left.Length))));
            }
        }
コード例 #2
0
 private StringRebuilder Assemble(Span left, StringRebuilder text, Span right)
 {
     if (text.Length == 0)
     {
         return(Assemble(left, right));
     }
     else if (left.Length == 0)
     {
         return((right.Length == 0) ? text : BinaryStringRebuilder.Create(text, this.GetSubText(right)));
     }
     else if (right.Length == 0)
     {
         return(BinaryStringRebuilder.Create(this.GetSubText(left), text));
     }
     else if (left.Length < right.Length)
     {
         return(BinaryStringRebuilder.Create(BinaryStringRebuilder.Create(this.GetSubText(left), text),
                                             this.GetSubText(right)));
     }
     else
     {
         return(BinaryStringRebuilder.Create(this.GetSubText(left),
                                             BinaryStringRebuilder.Create(text, this.GetSubText(right))));
     }
 }
コード例 #3
0
 private StringRebuilder Assemble(Span left, Span right)
 {
     if (left.Length == 0)
     {
         return(this.GetSubText(right));
     }
     else if (right.Length == 0)
     {
         return(this.GetSubText(left));
     }
     else if (left.Length + right.Length == this.Length)
     {
         return(this);
     }
     else
     {
         return(BinaryStringRebuilder.Create(this.GetSubText(left), this.GetSubText(right)));
     }
 }
コード例 #4
0
        public static StringRebuilder Create(StringRebuilder left, StringRebuilder right)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }
            if (right == null)
            {
                throw new ArgumentNullException("right");
            }

            if (left.Length == 0)
            {
                return(right);
            }
            else if (right.Length == 0)
            {
                return(left);
            }
            else if ((left.Length + right.Length < TextModelOptions.StringRebuilderMaxCharactersToConsolidate) &&
                     (left.LineBreakCount + right.LineBreakCount <= TextModelOptions.StringRebuilderMaxLinesToConsolidate))
            {
                //Consolidate the two rebuilders into a single simple string rebuilder
                return(SimpleStringRebuilder.Create(left, right));
            }
            else if (right.StartsWithNewLine && left.EndsWithReturn)
            {
                //Don't allow a line break to be broken across the seam
                return(BinaryStringRebuilder.Create(BinaryStringRebuilder.Create(left.Substring(new Span(0, left.Length - 1)),
                                                                                 _crlf),
                                                    right.Substring(Span.FromBounds(1, right.Length))));
            }
            else
            {
                return(BinaryStringRebuilder.BalanceStringRebuilder(left, right));
            }
        }