diff options
Diffstat (limited to 'src/WidthData.zig')
| -rw-r--r-- | src/WidthData.zig | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/WidthData.zig b/src/WidthData.zig index 1b7fb2e..d77879e 100644 --- a/src/WidthData.zig +++ b/src/WidthData.zig | |||
| @@ -9,7 +9,7 @@ const GraphemeData = @import("GraphemeData"); | |||
| 9 | allocator: mem.Allocator, | 9 | allocator: mem.Allocator, |
| 10 | g_data: GraphemeData, | 10 | g_data: GraphemeData, |
| 11 | s1: []u16 = undefined, | 11 | s1: []u16 = undefined, |
| 12 | s2: []i3 = undefined, | 12 | s2: []i4 = undefined, |
| 13 | 13 | ||
| 14 | const Self = @This(); | 14 | const Self = @This(); |
| 15 | 15 | ||
| @@ -34,7 +34,7 @@ pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self { | |||
| 34 | for (0..stage_1_len) |i| self.s1[i] = reader.readInt(u16, endian) catch unreachable; | 34 | for (0..stage_1_len) |i| self.s1[i] = reader.readInt(u16, endian) catch unreachable; |
| 35 | 35 | ||
| 36 | const stage_2_len: u16 = reader.readInt(u16, endian) catch unreachable; | 36 | const stage_2_len: u16 = reader.readInt(u16, endian) catch unreachable; |
| 37 | self.s2 = try allocator.alloc(i3, stage_2_len); | 37 | self.s2 = try allocator.alloc(i4, stage_2_len); |
| 38 | errdefer allocator.free(self.s2); | 38 | errdefer allocator.free(self.s2); |
| 39 | for (0..stage_2_len) |i| self.s2[i] = @intCast(reader.readInt(i8, endian) catch unreachable); | 39 | for (0..stage_2_len) |i| self.s2[i] = @intCast(reader.readInt(i8, endian) catch unreachable); |
| 40 | 40 | ||
| @@ -52,33 +52,33 @@ pub fn deinit(self: *const Self) void { | |||
| 52 | /// 3, where BACKSPACE and DELETE return -1 and 3-em-dash returns 3. C0/C1 | 52 | /// 3, where BACKSPACE and DELETE return -1 and 3-em-dash returns 3. C0/C1 |
| 53 | /// control codes return 0. If `cjk` is true, ambiguous code points return 2, | 53 | /// control codes return 0. If `cjk` is true, ambiguous code points return 2, |
| 54 | /// otherwise they return 1. | 54 | /// otherwise they return 1. |
| 55 | pub fn codePointWidth(self: Self, cp: u21) i3 { | 55 | pub fn codePointWidth(self: Self, cp: u21) i4 { |
| 56 | return self.s2[self.s1[cp >> 8] + (cp & 0xff)]; | 56 | return self.s2[self.s1[cp >> 8] + (cp & 0xff)]; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | test "codePointWidth" { | 59 | test "codePointWidth" { |
| 60 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x0000)); // null | 60 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x0000)); // null |
| 61 | try testing.expectEqual(@as(i3, -1), codePointWidth(0x8)); // \b | 61 | try testing.expectEqual(@as(i4, -1), codePointWidth(0x8)); // \b |
| 62 | try testing.expectEqual(@as(i3, -1), codePointWidth(0x7f)); // DEL | 62 | try testing.expectEqual(@as(i4, -1), codePointWidth(0x7f)); // DEL |
| 63 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x0005)); // Cf | 63 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x0005)); // Cf |
| 64 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x0007)); // \a BEL | 64 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x0007)); // \a BEL |
| 65 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x000A)); // \n LF | 65 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000A)); // \n LF |
| 66 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x000B)); // \v VT | 66 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000B)); // \v VT |
| 67 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x000C)); // \f FF | 67 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000C)); // \f FF |
| 68 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x000D)); // \r CR | 68 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000D)); // \r CR |
| 69 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x000E)); // SQ | 69 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000E)); // SQ |
| 70 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x000F)); // SI | 70 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000F)); // SI |
| 71 | 71 | ||
| 72 | try testing.expectEqual(@as(i3, 0), codePointWidth(0x070F)); // Cf | 72 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x070F)); // Cf |
| 73 | try testing.expectEqual(@as(i3, 1), codePointWidth(0x0603)); // Cf Arabic | 73 | try testing.expectEqual(@as(i4, 1), codePointWidth(0x0603)); // Cf Arabic |
| 74 | 74 | ||
| 75 | try testing.expectEqual(@as(i3, 1), codePointWidth(0x00AD)); // soft-hyphen | 75 | try testing.expectEqual(@as(i4, 1), codePointWidth(0x00AD)); // soft-hyphen |
| 76 | try testing.expectEqual(@as(i3, 2), codePointWidth(0x2E3A)); // two-em dash | 76 | try testing.expectEqual(@as(i4, 2), codePointWidth(0x2E3A)); // two-em dash |
| 77 | try testing.expectEqual(@as(i3, 3), codePointWidth(0x2E3B)); // three-em dash | 77 | try testing.expectEqual(@as(i4, 3), codePointWidth(0x2E3B)); // three-em dash |
| 78 | 78 | ||
| 79 | try testing.expectEqual(@as(i3, 1), codePointWidth(0x00BD)); // ambiguous halfwidth | 79 | try testing.expectEqual(@as(i4, 1), codePointWidth(0x00BD)); // ambiguous halfwidth |
| 80 | 80 | ||
| 81 | try testing.expectEqual(@as(i3, 1), codePointWidth('é')); | 81 | try testing.expectEqual(@as(i4, 1), codePointWidth('é')); |
| 82 | try testing.expectEqual(@as(i3, 2), codePointWidth('😊')); | 82 | try testing.expectEqual(@as(i4, 2), codePointWidth('😊')); |
| 83 | try testing.expectEqual(@as(i3, 2), codePointWidth('统')); | 83 | try testing.expectEqual(@as(i4, 2), codePointWidth('统')); |
| 84 | } | 84 | } |