diff --git a/sources/Text/MutableText.uc b/sources/Text/MutableText.uc index 6ebbf5e..8a780c7 100644 --- a/sources/Text/MutableText.uc +++ b/sources/Text/MutableText.uc @@ -427,7 +427,8 @@ public final function MutableText Replace( * goes beyond `[0; self.GetLength() - 1]`, then intersection with a valid * range will be used. * - * @param startPosition Position of the first character to change formatting + * @param newFormatting New formatting to apply. + * @param startIndex Position of the first character to change formatting * of. By default `0`, corresponding to the very first character. * @param maxLength Max length of the segment to change formatting of. * By default `0`, - that and all negative values are replaces by `MaxInt`, @@ -435,14 +436,17 @@ public final function MutableText Replace( * @return Reference to the caller `MutableText` to allow for method chaining. */ public final function MutableText ChangeFormatting( - int startIndex, - int maxLength, - Formatting newFormatting) + Formatting newFormatting, + optional int startIndex, + optional int maxLength) { local int endIndex; - if (maxLength <= 0) return self; - if (startIndex >= GetLength()) return self; - + if (startIndex >= GetLength()) { + return self; + } + if (maxLength <= 0) { + maxLength = MaxInt; + } endIndex = Min(startIndex + maxLength, GetLength()) - 1; startIndex = Max(startIndex, 0); if (startIndex > endIndex) { diff --git a/sources/Text/Tests/TEST_Text.uc b/sources/Text/Tests/TEST_Text.uc index 59b1b30..73d018e 100644 --- a/sources/Text/Tests/TEST_Text.uc +++ b/sources/Text/Tests/TEST_Text.uc @@ -1061,26 +1061,26 @@ protected static function SubTest_ChangeFormattingRegular() Issue("Formatting is not changed correctly."); template = __().text.FromFormattedString( "Normal part, {#ff0000 red part}, {#00ff00 green part}!!!"); - testText = template.MutableCopy().ChangeFormatting(3, 4, greenFormatting); + testText = template.MutableCopy().ChangeFormatting(greenFormatting, 3, 4); TEST_ExpectTrue(testText.ToFormattedString() == ("Nor{rgb(0,255,0) mal }part, {rgb(255,0,0) red part}, {rgb(0,255,0)" @ "green part}!!!")); - testText = template.MutableCopy().ChangeFormatting(12, 10, greenFormatting); + testText = template.MutableCopy().ChangeFormatting(greenFormatting, 12, 10); TEST_ExpectTrue(testText.ToFormattedString() == "Normal part,{rgb(0,255,0) red part,} {rgb(0,255,0) green part}!!!"); - testText = template.MutableCopy().ChangeFormatting(12, 11, greenFormatting); + testText = template.MutableCopy().ChangeFormatting(greenFormatting, 12, 11); TEST_ExpectTrue(testText.ToFormattedString() == "Normal part,{rgb(0,255,0) red part, green part}!!!"); // This test was added because it produced `none` access errors in the // old implementation of `ChangeFormatting()` - testText = template.MutableCopy().ChangeFormatting(0, 35, greenFormatting); + testText = template.MutableCopy().ChangeFormatting(greenFormatting, 0, 35); TEST_ExpectTrue(testText.ToFormattedString() == "{rgb(0,255,0) Normal part, red part, green part!!}!"); - testText = template.MutableCopy().ChangeFormatting(3, 4, defaultFormatting); + testText = template.MutableCopy().ChangeFormatting(defaultFormatting, 3, 4); TEST_ExpectTrue(testText.ToFormattedString() == "Normal part, {rgb(255,0,0) red part}, {rgb(0,255,0) green part}!!!"); testText = template.MutableCopy() - .ChangeFormatting(16, 13, defaultFormatting); + .ChangeFormatting(defaultFormatting, 16, 13); TEST_ExpectTrue(testText.ToFormattedString() == "Normal part, {rgb(255,0,0) red} part, green {rgb(0,255,0) part}!!!"); } @@ -1095,19 +1095,19 @@ protected static function SubTest_ChangeFormattingEdgeCases() @ "near index boundaries."); template = __().text.FromFormattedString( "Normal part, {#ff0000 red part}, {#00ff00 green part}!!!"); - testText = template.MutableCopy().ChangeFormatting(33, 3, greenFormatting); + testText = template.MutableCopy().ChangeFormatting(greenFormatting, 33, 3); TEST_ExpectTrue(testText.ToFormattedString() == "Normal part, {rgb(255,0,0) red part}, {rgb(0,255,0) green part!!!}"); - testText = template.MutableCopy().ChangeFormatting(36, 5, greenFormatting); + testText = template.MutableCopy().ChangeFormatting(greenFormatting, 36, 5); TEST_ExpectTrue(testText.ToFormattedString() == "Normal part, {rgb(255,0,0) red part}, {rgb(0,255,0) green part}!!!"); testText = template.MutableCopy() - .ChangeFormatting(-10, 100, defaultFormatting); + .ChangeFormatting(defaultFormatting, -10, 100); TEST_ExpectTrue(testText.ToFormattedString() == "Normal part, red part, green part!!!"); testText = template.MutableCopy() - .ChangeFormatting(-10, 16, greenFormatting); + .ChangeFormatting(greenFormatting, -10, 16); TEST_ExpectTrue(testText.ToFormattedString() == ("{rgb(0,255,0) Normal} part, {rgb(255,0,0) red part}, {rgb(0,255,0)" @ "green part}!!!"));