summaryrefslogtreecommitdiff
path: root/src/GraphemeData.zig
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-04-30 11:58:19 -0400
committerGravatar Sam Atman2025-04-30 11:58:19 -0400
commit1be5e46490e061761b4b97dff5c6acb2181d6fe9 (patch)
tree77a1edcdedd7afae7428e92feba37d2bb1035b22 /src/GraphemeData.zig
parentAdd general tests step (diff)
downloadzg-1be5e46490e061761b4b97dff5c6acb2181d6fe9.tar.gz
zg-1be5e46490e061761b4b97dff5c6acb2181d6fe9.tar.xz
zg-1be5e46490e061761b4b97dff5c6acb2181d6fe9.zip
Factor out 'Data' for grapheme and DisplayWidth
In the process of refactoring the whole library, so that it doesn't expose anything called "Data" separately from user functionality.
Diffstat (limited to 'src/GraphemeData.zig')
-rw-r--r--src/GraphemeData.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/GraphemeData.zig b/src/GraphemeData.zig
index 6d3174d..df025cb 100644
--- a/src/GraphemeData.zig
+++ b/src/GraphemeData.zig
@@ -36,7 +36,7 @@ s3: []u8 = undefined,
36 36
37const Self = @This(); 37const Self = @This();
38 38
39pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self { 39pub inline fn init(allocator: mem.Allocator) mem.Allocator.Error!Self {
40 const decompressor = compress.flate.inflate.decompressor; 40 const decompressor = compress.flate.inflate.decompressor;
41 const in_bytes = @embedFile("gbp"); 41 const in_bytes = @embedFile("gbp");
42 var in_fbs = std.io.fixedBufferStream(in_bytes); 42 var in_fbs = std.io.fixedBufferStream(in_bytes);
@@ -65,23 +65,23 @@ pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self {
65 return self; 65 return self;
66} 66}
67 67
68pub fn deinit(self: *const Self, allocator: mem.Allocator) void { 68pub inline fn deinit(self: *const Self, allocator: mem.Allocator) void {
69 allocator.free(self.s1); 69 allocator.free(self.s1);
70 allocator.free(self.s2); 70 allocator.free(self.s2);
71 allocator.free(self.s3); 71 allocator.free(self.s3);
72} 72}
73 73
74/// Lookup the grapheme break property for a code point. 74/// Lookup the grapheme break property for a code point.
75pub fn gbp(self: Self, cp: u21) Gbp { 75pub inline fn gbp(self: Self, cp: u21) Gbp {
76 return @enumFromInt(self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] >> 4); 76 return @enumFromInt(self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] >> 4);
77} 77}
78 78
79/// Lookup the indic syllable type for a code point. 79/// Lookup the indic syllable type for a code point.
80pub fn indic(self: Self, cp: u21) Indic { 80pub inline fn indic(self: Self, cp: u21) Indic {
81 return @enumFromInt((self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] >> 1) & 0x7); 81 return @enumFromInt((self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] >> 1) & 0x7);
82} 82}
83 83
84/// Lookup the indic syllable type for a code point. 84/// Lookup the emoji property for a code point.
85pub fn isEmoji(self: Self, cp: u21) bool { 85pub inline fn isEmoji(self: Self, cp: u21) bool {
86 return self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] & 1 == 1; 86 return self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]] & 1 == 1;
87} 87}