diff --git a/NStack/unicode/Rune.ColumnWidth.cs b/NStack/unicode/Rune.ColumnWidth.cs
index 7e8839f..c1a4fdf 100644
--- a/NStack/unicode/Rune.ColumnWidth.cs
+++ b/NStack/unicode/Rune.ColumnWidth.cs
@@ -59,11 +59,13 @@ public partial struct Rune
{ 0xE0100, 0xE01EF }
};
- static int bisearch (uint rune, uint [,] table, int max)
+ static int bisearch (uint rune, uint [,] table)
{
int min = 0;
+ int max = table.GetLength (0) - 1;
int mid;
+
if (rune < table [0, 0] || rune > table [max, 1])
return 0;
while (max >= min) {
@@ -82,8 +84,8 @@ static int bisearch (uint rune, uint [,] table, int max)
///
/// Number of column positions of a wide-character code. This is used to measure runes as displayed by text-based terminals.
///
- /// The width in columns, 0 if the argument is the null character, -1 if the value is not printable, otherwise the number of columsn that the rune occupies.
- /// The red component.
+ /// The width in columns, 0 if the argument is the null character, -1 if the value is not printable, otherwise the number of columns that the rune occupies.
+ /// The rune to measure
public static int ColumnWidth (Rune rune)
{
uint irune = (uint)rune;
@@ -94,7 +96,7 @@ public static int ColumnWidth (Rune rune)
if (irune >= 0x7f && irune <= 0xa0)
return 0;
/* binary search in table of non-spacing characters */
- if (bisearch (irune, combining, combining.GetLength (0)-1) != 0)
+ if (bisearch (irune, combining) != 0)
return 0;
/* if we arrive here, ucs is not a combining or C0/C1 control character */
return 1 +
diff --git a/NStackTests/UnicodeTest.cs b/NStackTests/UnicodeTest.cs
index af67f4a..0f38ac2 100644
--- a/NStackTests/UnicodeTest.cs
+++ b/NStackTests/UnicodeTest.cs
@@ -376,6 +376,16 @@ public void TestIsUpper ()
};
+ [Test]
+ public void TestColumnWidth ()
+ {
+ // unicode chars taken from https://github.com/migueldeicaza/gui.cs/issues/146
+ foreach (var c in new string[] { "\u2261", "\u2302", "\u2191", "\u2193", "\u2026"}) {
+ (var rune, var size) = Utf8.DecodeRune (c);
+ Assert.AreEqual (Rune.ColumnWidth (rune), 1);
+ }
+ }
+
[Test]
public void TestTo ()
{