Exemplo n.º 1
0
 private static StringRebuilder ConsolidateOrBalanceTreeNode(StringRebuilder left, StringRebuilder right)
 {
     if ((left.Length + right.Length < TextModelOptions.StringRebuilderMaxCharactersToConsolidate) &&
         (left.LineBreakCount + right.LineBreakCount <= TextModelOptions.StringRebuilderMaxLinesToConsolidate))
     {
         //Consolidate the two rebuilders into a single simple string rebuilder
         return(StringRebuilder.Consolidate(left, right));
     }
     else
     {
         return(BinaryStringRebuilder.BalanceTreeNode(left, right));
     }
 }
Exemplo n.º 2
0
        public static StringRebuilder Create(StringRebuilder left, StringRebuilder right)
        {
            if (left == null)
            {
                throw new ArgumentNullException(nameof(left));
            }
            if (right == null)
            {
                throw new ArgumentNullException(nameof(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(StringRebuilder.Consolidate(left, right));
            }
            else if ((right.FirstCharacter == '\n') && (left.LastCharacter == '\r'))
            {
                //Don't allow a line break to be broken across the seam
                return(BinaryStringRebuilder.Create(BinaryStringRebuilder.Create(left.GetSubText(new Span(0, left.Length - 1)),
                                                                                 _crlf),
                                                    right.GetSubText(Span.FromBounds(1, right.Length))));
            }
            else
            {
                return(BinaryStringRebuilder.BalanceStringRebuilder(left, right));
            }
        }