Skip to content

Commit

Permalink
add ToLower and ToUpper method
Browse files Browse the repository at this point in the history
  • Loading branch information
MeilCli committed Apr 16, 2017
1 parent d68d892 commit 4a0b127
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Source/Plugin.CrossFormattedText.Abstractions/FormattedString.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -579,6 +580,46 @@ public FormattedString Subspan(int startIndex,int length) {
return new FormattedString(nAr);
}

public FormattedString ToLower() {
Span[] sAr = ToClonedSpanArray();

foreach(Span span in sAr) {
span.Text = span.Text.ToLower();
}

return new FormattedString(sAr);
}

public FormattedString ToLowerInvariant() {
Span[] sAr = ToClonedSpanArray();

foreach(Span span in sAr) {
span.Text = span.Text.ToLowerInvariant();
}

return new FormattedString(sAr);
}

public FormattedString ToUpper() {
Span[] sAr = ToClonedSpanArray();

foreach(Span span in sAr) {
span.Text = span.Text.ToUpper();
}

return new FormattedString(sAr);
}

public FormattedString ToUpperInvariant() {
Span[] sAr = ToClonedSpanArray();

foreach(Span span in sAr) {
span.Text = span.Text.ToUpperInvariant();
}

return new FormattedString(sAr);
}

public bool AnySpanReferenceEquals(FormattedString formattedString) {
foreach(var span1 in spans) {
foreach(var span2 in formattedString.spans) {
Expand Down
26 changes: 26 additions & 0 deletions Test/Test.CrossFormattedText.Unit/FormattedStringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,31 @@ public void SubspanText() {
Assert.AreEqual(newText1.Text,text.Text.Substring(text[0].Text.Length));
Assert.AreEqual(newText1.AnySpanReferenceEquals(text),false);
}

[TestMethod]
public void ToLowerTest() {
var newText1 = text.ToLower();

Assert.AreEqual(newText1.Text,text.Text.ToLower());
Assert.AreEqual(newText1.AnySpanReferenceEquals(text),false);

var newText2 = text.ToLowerInvariant();

Assert.AreEqual(newText2.Text,text.Text.ToLowerInvariant());
Assert.AreEqual(newText2.AnySpanReferenceEquals(text),false);
}

[TestMethod]
public void ToUpperTest() {
var newText1 = text.ToUpper();

Assert.AreEqual(newText1.Text,text.Text.ToUpper());
Assert.AreEqual(newText1.AnySpanReferenceEquals(text),false);

var newText2 = text.ToUpperInvariant();

Assert.AreEqual(newText2.Text,text.Text.ToUpperInvariant());
Assert.AreEqual(newText2.AnySpanReferenceEquals(text),false);
}
}
}

0 comments on commit 4a0b127

Please sign in to comment.