Skip to content

Commit a8a307b

Browse files
authored
Merge pull request #84 from BDisp/consolewidth-negative-fix
Fixes #83. Ustring ConsoleWidth must return the exactly character size or zero and not the Rune.ColumnWidth if it's negative.
2 parents 84d41bd + 48db6e0 commit a8a307b

File tree

2 files changed

+660
-654
lines changed

2 files changed

+660
-654
lines changed

NStack/strings/ustring.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,8 @@ public ustring RuneSubstring (int runeStart, int length = 0)
10561056
public int RuneCount => Utf8.RuneCount (this);
10571057

10581058
/// <summary>
1059-
/// Returns the number of columns used by the unicode string on console applications. This is done by calling the Rune.ColumnWidth on each rune.
1059+
/// Returns the number of columns used by the unicode string on console applications.
1060+
/// This is done by calling the Rune.ColumnWidth or zero, if it's negative, on each rune.
10601061
/// </summary>
10611062
public int ConsoleWidth {
10621063
get {
@@ -1065,7 +1066,7 @@ public int ConsoleWidth {
10651066
for (int i = 0; i < blen;) {
10661067
(var rune, var size) = Utf8.DecodeRune (this, i, i - blen);
10671068
i += size;
1068-
total += Rune.ColumnWidth (rune);
1069+
total += Math.Max (Rune.ColumnWidth (rune), 0);
10691070
}
10701071
return total;
10711072
}

0 commit comments

Comments
 (0)