diff options
Diffstat (limited to 'src/FoldData.zig')
| -rw-r--r-- | src/FoldData.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/FoldData.zig b/src/FoldData.zig index 139c677..2a9a1f5 100644 --- a/src/FoldData.zig +++ b/src/FoldData.zig | |||
| @@ -5,6 +5,7 @@ const mem = std.mem; | |||
| 5 | 5 | ||
| 6 | allocator: mem.Allocator, | 6 | allocator: mem.Allocator, |
| 7 | fold: [][]u21 = undefined, | 7 | fold: [][]u21 = undefined, |
| 8 | cwcf: []bool = undefined, | ||
| 8 | 9 | ||
| 9 | const Self = @This(); | 10 | const Self = @This(); |
| 10 | 11 | ||
| @@ -20,18 +21,21 @@ pub fn init(allocator: mem.Allocator) !Self { | |||
| 20 | var self = Self{ | 21 | var self = Self{ |
| 21 | .allocator = allocator, | 22 | .allocator = allocator, |
| 22 | .fold = try allocator.alloc([]u21, 0x110000), | 23 | .fold = try allocator.alloc([]u21, 0x110000), |
| 24 | .cwcf = try allocator.alloc(bool, 0x110000), | ||
| 23 | }; | 25 | }; |
| 24 | 26 | ||
| 25 | @memset(self.fold, &.{}); | 27 | @memset(self.fold, &.{}); |
| 28 | @memset(self.cwcf, false); | ||
| 26 | 29 | ||
| 27 | while (true) { | 30 | while (true) { |
| 28 | const len: u8 = try reader.readInt(u8, endian); | 31 | const len: u8 = try reader.readInt(u8, endian); |
| 29 | if (len == 0) break; | 32 | if (len == 0) break; |
| 30 | const cp = try reader.readInt(u24, endian); | 33 | const cp = try reader.readInt(u24, endian); |
| 31 | self.fold[cp] = try allocator.alloc(u21, len - 1); | 34 | self.fold[cp >> 1] = try allocator.alloc(u21, len - 1); |
| 32 | for (0..len - 1) |i| { | 35 | for (0..len - 1) |i| { |
| 33 | self.fold[cp][i] = @intCast(try reader.readInt(u24, endian)); | 36 | self.fold[cp >> 1][i] = @intCast(try reader.readInt(u24, endian)); |
| 34 | } | 37 | } |
| 38 | self.cwcf[cp >> 1] = cp & 1 == 1; | ||
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | return self; | 41 | return self; |
| @@ -40,9 +44,15 @@ pub fn init(allocator: mem.Allocator) !Self { | |||
| 40 | pub fn deinit(self: *Self) void { | 44 | pub fn deinit(self: *Self) void { |
| 41 | for (self.fold) |slice| self.allocator.free(slice); | 45 | for (self.fold) |slice| self.allocator.free(slice); |
| 42 | self.allocator.free(self.fold); | 46 | self.allocator.free(self.fold); |
| 47 | self.allocator.free(self.cwcf); | ||
| 43 | } | 48 | } |
| 44 | 49 | ||
| 45 | /// Returns the case fold for `cp`. | 50 | /// Returns the case fold for `cp`. |
| 46 | pub inline fn caseFold(self: Self, cp: u21) []const u21 { | 51 | pub inline fn caseFold(self: Self, cp: u21) []const u21 { |
| 47 | return self.fold[cp]; | 52 | return self.fold[cp]; |
| 48 | } | 53 | } |
| 54 | |||
| 55 | /// Returns true when caseFold(NFD(`cp`)) != NFD(`cp`). | ||
| 56 | pub inline fn changesWhenCaseFolded(self: Self, cp: u21) bool { | ||
| 57 | return self.cwcf[cp]; | ||
| 58 | } | ||