summaryrefslogtreecommitdiff
path: root/src/CombiningData.zig
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-04-30 12:58:26 -0400
committerGravatar Sam Atman2025-04-30 13:01:37 -0400
commit3c2c30bfbe861c6c48acd8d7507886787197a788 (patch)
tree875ba35c1954b201207452b18a189ebd70c0b596 /src/CombiningData.zig
parentgrapheme now Graphemes, Data files gone (diff)
downloadzg-3c2c30bfbe861c6c48acd8d7507886787197a788.tar.gz
zg-3c2c30bfbe861c6c48acd8d7507886787197a788.tar.xz
zg-3c2c30bfbe861c6c48acd8d7507886787197a788.zip
Merge NormData with Normalize
Diffstat (limited to 'src/CombiningData.zig')
-rw-r--r--src/CombiningData.zig44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/CombiningData.zig b/src/CombiningData.zig
index b5e227a..fd64a3b 100644
--- a/src/CombiningData.zig
+++ b/src/CombiningData.zig
@@ -1,14 +1,11 @@
1const std = @import("std"); 1//! Combining Class Data
2const builtin = @import("builtin");
3const compress = std.compress;
4const mem = std.mem;
5 2
6s1: []u16 = undefined, 3s1: []u16 = undefined,
7s2: []u8 = undefined, 4s2: []u8 = undefined,
8 5
9const Self = @This(); 6const CombiningData = @This();
10 7
11pub fn init(allocator: mem.Allocator) !Self { 8pub fn init(allocator: mem.Allocator) !CombiningData {
12 const decompressor = compress.flate.inflate.decompressor; 9 const decompressor = compress.flate.inflate.decompressor;
13 const in_bytes = @embedFile("ccc"); 10 const in_bytes = @embedFile("ccc");
14 var in_fbs = std.io.fixedBufferStream(in_bytes); 11 var in_fbs = std.io.fixedBufferStream(in_bytes);
@@ -17,32 +14,37 @@ pub fn init(allocator: mem.Allocator) !Self {
17 14
18 const endian = builtin.cpu.arch.endian(); 15 const endian = builtin.cpu.arch.endian();
19 16
20 var self = Self{}; 17 var cbdata = CombiningData{};
21 18
22 const stage_1_len: u16 = try reader.readInt(u16, endian); 19 const stage_1_len: u16 = try reader.readInt(u16, endian);
23 self.s1 = try allocator.alloc(u16, stage_1_len); 20 cbdata.s1 = try allocator.alloc(u16, stage_1_len);
24 errdefer allocator.free(self.s1); 21 errdefer allocator.free(cbdata.s1);
25 for (0..stage_1_len) |i| self.s1[i] = try reader.readInt(u16, endian); 22 for (0..stage_1_len) |i| cbdata.s1[i] = try reader.readInt(u16, endian);
26 23
27 const stage_2_len: u16 = try reader.readInt(u16, endian); 24 const stage_2_len: u16 = try reader.readInt(u16, endian);
28 self.s2 = try allocator.alloc(u8, stage_2_len); 25 cbdata.s2 = try allocator.alloc(u8, stage_2_len);
29 errdefer allocator.free(self.s2); 26 errdefer allocator.free(cbdata.s2);
30 _ = try reader.readAll(self.s2); 27 _ = try reader.readAll(cbdata.s2);
31 28
32 return self; 29 return cbdata;
33} 30}
34 31
35pub fn deinit(self: *const Self, allocator: mem.Allocator) void { 32pub fn deinit(cbdata: *const CombiningData, allocator: mem.Allocator) void {
36 allocator.free(self.s1); 33 allocator.free(cbdata.s1);
37 allocator.free(self.s2); 34 allocator.free(cbdata.s2);
38} 35}
39 36
40/// Returns the canonical combining class for a code point. 37/// Returns the canonical combining class for a code point.
41pub fn ccc(self: Self, cp: u21) u8 { 38pub fn ccc(cbdata: CombiningData, cp: u21) u8 {
42 return self.s2[self.s1[cp >> 8] + (cp & 0xff)]; 39 return cbdata.s2[cbdata.s1[cp >> 8] + (cp & 0xff)];
43} 40}
44 41
45/// True if `cp` is a starter code point, not a combining character. 42/// True if `cp` is a starter code point, not a combining character.
46pub fn isStarter(self: Self, cp: u21) bool { 43pub fn isStarter(cbdata: CombiningData, cp: u21) bool {
47 return self.s2[self.s1[cp >> 8] + (cp & 0xff)] == 0; 44 return cbdata.s2[cbdata.s1[cp >> 8] + (cp & 0xff)] == 0;
48} 45}
46
47const std = @import("std");
48const builtin = @import("builtin");
49const compress = std.compress;
50const mem = std.mem;