From 7a212f5ec5aabf016d17d3ed28649e7982b810ef Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Wed, 30 Apr 2025 12:02:17 -0400 Subject: grapheme now Graphemes, Data files gone --- src/GraphemeData.zig | 87 ---------------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 src/GraphemeData.zig (limited to 'src/GraphemeData.zig') diff --git a/src/GraphemeData.zig b/src/GraphemeData.zig deleted file mode 100644 index df025cb..0000000 --- a/src/GraphemeData.zig +++ /dev/null @@ -1,87 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const compress = std.compress; -const mem = std.mem; - -/// Indic syllable type. -pub const Indic = enum { - none, - - Consonant, - Extend, - Linker, -}; - -/// Grapheme break property. -pub const Gbp = enum { - none, - Control, - CR, - Extend, - L, - LF, - LV, - LVT, - Prepend, - Regional_Indicator, - SpacingMark, - T, - V, - ZWJ, -}; - -s1: []u16 = undefined, -s2: []u16 = undefined, -s3: []u8 = undefined, - -const Self = @This(); - -pub inline fn init(allocator: mem.Allocator) mem.Allocator.Error!Self { - const decompressor = compress.flate.inflate.decompressor; - const in_bytes = @embedFile("gbp"); - var in_fbs = std.io.fixedBufferStream(in_bytes); - var in_decomp = decompressor(.raw, in_fbs.reader()); - var reader = in_decomp.reader(); - - const endian = builtin.cpu.arch.endian(); - - var self = Self{}; - - const s1_len: u16 = reader.readInt(u16, endian) catch unreachable; - self.s1 = try allocator.alloc(u16, s1_len); - errdefer allocator.free(self.s1); - for (0..s1_len) |i| self.s1[i] = reader.readInt(u16, endian) catch unreachable; - - const s2_len: u16 = reader.readInt(u16, endian) catch unreachable; - self.s2 = try allocator.alloc(u16, s2_len); - errdefer allocator.free(self.s2); - for (0..s2_len) |i| self.s2[i] = reader.readInt(u16, endian) catch unreachable; - - const s3_len: u16 = reader.readInt(u16, endian) catch unreachable; - self.s3 = try allocator.alloc(u8, s3_len); - errdefer allocator.free(self.s3); - _ = reader.readAll(self.s3) catch unreachable; - - return self; -} - -pub inline fn deinit(self: *const Self, allocator: mem.Allocator) void { - allocator.free(self.s1); - allocator.free(self.s2); - allocator.free(self.s3); -} - -/// Lookup the grapheme break property for a code point. -pub inline fn gbp(self: Self, cp: u21) Gbp { - return @enumFromInt(self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] >> 4); -} - -/// Lookup the indic syllable type for a code point. -pub inline fn indic(self: Self, cp: u21) Indic { - return @enumFromInt((self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] >> 1) & 0x7); -} - -/// Lookup the emoji property for a code point. -pub inline fn isEmoji(self: Self, cp: u21) bool { - return self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] & 1 == 1; -} -- cgit v1.2.3