Skip to content

Commit 3fc024f

Browse files
committed
New API, and bug fix
1 parent 2c06c4f commit 3fc024f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

NStack/unicode/Rune.ColumnWidth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static int ColumnWidth (Rune rune)
9494
if (irune >= 0x7f && irune <= 0xa0)
9595
return 0;
9696
/* binary search in table of non-spacing characters */
97-
if (bisearch (irune, combining, combining.GetLength (0)) != 0)
97+
if (bisearch (irune, combining, combining.GetLength (0)-1) != 0)
9898
return 0;
9999
/* if we arrive here, ucs is not a combining or C0/C1 control character */
100100
return 1 +

NStack/unicode/Rune.extensions.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,21 @@ public static bool Valid (ustring str)
272272
return InvalidIndex (str) == -1;
273273
}
274274

275-
275+
/// <summary>
276+
/// Given one byte from a utf8 string, return the number of expected bytes that make up the sequence.
277+
/// </summary>
278+
/// <returns>The number of UTF8 bytes expected given the first prefix.</returns>
279+
/// <param name="firstByte">Is the first byte of a UTF8 sequence.</param>
280+
public static int ExpectedSizeFromFirstByte (byte firstByte)
281+
{
282+
var x = first [firstByte];
283+
284+
// Invalid runes, just return 1 for byte, and let higher level pass to print
285+
if (x == xx)
286+
return -1;
287+
if (x == a1)
288+
return 1;
289+
return x & 0xf;
290+
}
276291
}
277292
}

0 commit comments

Comments
 (0)