From 3c2c30bfbe861c6c48acd8d7507886787197a788 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Wed, 30 Apr 2025 12:58:26 -0400 Subject: Merge NormData with Normalize --- src/HangulData.zig | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/HangulData.zig') diff --git a/src/HangulData.zig b/src/HangulData.zig index 4bccbe6..8c5f3ad 100644 --- a/src/HangulData.zig +++ b/src/HangulData.zig @@ -1,8 +1,4 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const compress = std.compress; -const mem = std.mem; -const testing = std.testing; +//! Hangul Data pub const Syllable = enum { none, @@ -16,9 +12,9 @@ pub const Syllable = enum { s1: []u16 = undefined, s2: []u3 = undefined, -const Self = @This(); +const Hangul = @This(); -pub fn init(allocator: mem.Allocator) !Self { +pub fn init(allocator: mem.Allocator) !Hangul { const decompressor = compress.flate.inflate.decompressor; const in_bytes = @embedFile("hangul"); var in_fbs = std.io.fixedBufferStream(in_bytes); @@ -26,27 +22,33 @@ pub fn init(allocator: mem.Allocator) !Self { var reader = in_decomp.reader(); const endian = builtin.cpu.arch.endian(); - var self = Self{}; + var hangul = Hangul{}; const stage_1_len: u16 = try reader.readInt(u16, endian); - self.s1 = try allocator.alloc(u16, stage_1_len); - errdefer allocator.free(self.s1); - for (0..stage_1_len) |i| self.s1[i] = try reader.readInt(u16, endian); + hangul.s1 = try allocator.alloc(u16, stage_1_len); + errdefer allocator.free(hangul.s1); + for (0..stage_1_len) |i| hangul.s1[i] = try reader.readInt(u16, endian); const stage_2_len: u16 = try reader.readInt(u16, endian); - self.s2 = try allocator.alloc(u3, stage_2_len); - errdefer allocator.free(self.s2); - for (0..stage_2_len) |i| self.s2[i] = @intCast(try reader.readInt(u8, endian)); + hangul.s2 = try allocator.alloc(u3, stage_2_len); + errdefer allocator.free(hangul.s2); + for (0..stage_2_len) |i| hangul.s2[i] = @intCast(try reader.readInt(u8, endian)); - return self; + return hangul; } -pub fn deinit(self: *const Self, allocator: mem.Allocator) void { - allocator.free(self.s1); - allocator.free(self.s2); +pub fn deinit(hangul: *const Hangul, allocator: mem.Allocator) void { + allocator.free(hangul.s1); + allocator.free(hangul.s2); } /// Returns the Hangul syllable type for `cp`. -pub fn syllable(self: Self, cp: u21) Syllable { - return @enumFromInt(self.s2[self.s1[cp >> 8] + (cp & 0xff)]); +pub fn syllable(hangul: *const Hangul, cp: u21) Syllable { + return @enumFromInt(hangul.s2[hangul.s1[cp >> 8] + (cp & 0xff)]); } + +const std = @import("std"); +const builtin = @import("builtin"); +const compress = std.compress; +const mem = std.mem; +const testing = std.testing; -- cgit v1.2.3