Skip to content

Commit

Permalink
add AppendLine method
Browse files Browse the repository at this point in the history
  • Loading branch information
MeilCli committed May 2, 2017
1 parent ba3abbe commit 3a0a3a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,32 @@ public void Append(string value,Span span) {
Length += ar.Length;
}

public void AppendLine() {
Append(Environment.NewLine);
}

public void AppendLine(Span span) {
Append(Environment.NewLine,span);
}

public void AppendLine(string value) {
AppendLine(value,null);
}

public void AppendLine(string value,Span span) {
if(value == null) {
throw new ArgumentNullException(nameof(value));
}

EnsureCapacity(Length + value.Length + Environment.NewLine.Length);

span = span ?? new Span();
CharSpan[] ar = (value + Environment.NewLine).ToCharArray().Select(x => new CharSpan(x,span)).ToArray();

Array.Copy(ar,0,values,Length,ar.Length);
Length += ar.Length;
}

public FormattedString ToFormattedString() {
return MergeCharSpan();
}
Expand Down
13 changes: 13 additions & 0 deletions Test/Test.CrossFormattedText.Unit/FormattedStringBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,18 @@ public void AppendTest() {

Assert.AreEqual(fsb.ToFormattedString().Text,sb.ToString());
}

[TestMethod]
public void AppendLineTest() {
var sb = new StringBuilder();
var fsb = new FormattedStringBuilder();

sb.AppendLine();
fsb.AppendLine();
sb.AppendLine("aaa");
fsb.AppendLine("aaa");

Assert.AreEqual(fsb.ToFormattedString().Text,sb.ToString());
}
}
}

0 comments on commit 3a0a3a5

Please sign in to comment.