Beispiel #1
0
        internal override Text AppendComplexText(ComplexText tail)
        {
            Debug.Assert(tail != null);
            Debug.Assert(tail.Length > 0);
            Debug.Assert(this.Length > 0);

            var tailComponents = tail.texts;
            var textComponents = new List <Text>();

            if (IsComplexTextAppendableTo(tail))
            {
                textComponents.Add(this.AppendSimpleText((SimpleText)tailComponents[0]));
                textComponents.AddRange(tailComponents.Skip(1));
            }
            else
            {
                textComponents.Add(this);
                textComponents.AddRange(tailComponents);
            }

            if (textComponents.Count == 1)
            {
                return(textComponents[0]);
            }

            return(Text.Join(textComponents));
        }
        internal override Text AppendComplexText(ComplexText tail)
        {
            Debug.Assert(tail != null);
            Debug.Assert(tail.Length > 0);
            Debug.Assert(this.Length > 0);

            var text = IsComplexTextAppendableTo(tail) ?
                       new ComplexText(
                this.texts.Take(this.texts.Count - 1)
                .Concat(new[] { this.texts.Last().AppendSimpleText((SimpleText)tail.texts.First()) })
                .Concat(tail.texts.Skip(1)),
                enableOptimizations: false) :
                       new ComplexText(
                this.texts.Concat(tail.texts),
                enableOptimizations: false);

            var texts = text.texts;

            if (texts.Count == 0)
            {
                return(Text.Empty);
            }
            if (texts.Count == 1)
            {
                return(text.texts[0]);
            }
            return(text);
        }
Beispiel #3
0
        internal override bool IsComplexTextAppendableTo(ComplexText tail)
        {
            Debug.Assert(tail != null);
            Debug.Assert(tail.Length > 0);
            Debug.Assert(this.Length > 0);

            var firstTailComponent = tail.texts[0] as SimpleText;

            return
                (firstTailComponent != null &&
                 IsSimpleTextAppendableTo(firstTailComponent));
        }
Beispiel #4
0
        public static Text Join(IEnumerable <Text> texts)
        {
            texts.AssertNotNull();
            var result           = new ComplexText(texts);
            var resultComponents = result.texts;

            if (resultComponents.Count == 0)
            {
                return(Text.Empty);
            }
            if (resultComponents.Count == 1)
            {
                return(resultComponents[0]);
            }

            return(result);
        }
Beispiel #5
0
 internal abstract Text AppendComplexText(ComplexText tail);
Beispiel #6
0
 internal abstract bool IsComplexTextAppendableTo(ComplexText tail);