summaryrefslogtreecommitdiff
path: root/src/gbp.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gbp.zig')
-rw-r--r--src/gbp.zig67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/gbp.zig b/src/gbp.zig
new file mode 100644
index 0000000..fa4ad54
--- /dev/null
+++ b/src/gbp.zig
@@ -0,0 +1,67 @@
1const std = @import("std");
2const mem = std.mem;
3
4const gbp = @import("ziglyph").grapheme_break;
5const Trie = @import("trie.zig").Trie;
6const Prop = @import("trie.zig").Prop;
7
8var trie: Trie = undefined;
9
10pub fn init(allocator: mem.Allocator) !void {
11 trie = .{ .allocator = allocator, .root = .{} };
12
13 for ('\u{0}'..'\u{10ffff}') |i| {
14 const cp: u21 = @intCast(i);
15 const prop = Prop.forCodePoint(cp);
16 if (prop == .none) continue;
17 try trie.put(cp, prop);
18 }
19
20 const prop = Prop.forCodePoint('\u{10ffff}');
21 if (prop == .none) return;
22 try trie.put('\u{10ffff}', prop);
23}
24
25inline fn getProp(cp: u21) Prop {
26 return if (trie.get(cp)) |prop| prop else .none;
27}
28
29pub inline fn isControl(cp: u21) bool {
30 return getProp(cp) == .control;
31}
32
33pub inline fn isExtend(cp: u21) bool {
34 return getProp(cp) == .extend;
35}
36
37pub inline fn isL(cp: u21) bool {
38 return getProp(cp) == .hangul_l;
39}
40pub inline fn isLv(cp: u21) bool {
41 return getProp(cp) == .hangul_lv;
42}
43pub inline fn isLvt(cp: u21) bool {
44 return getProp(cp) == .hangul_lvt;
45}
46pub inline fn isV(cp: u21) bool {
47 return getProp(cp) == .hangul_v;
48}
49pub inline fn isT(cp: u21) bool {
50 return getProp(cp) == .hangul_t;
51}
52
53pub inline fn isPrepend(cp: u21) bool {
54 return getProp(cp) == .prepend;
55}
56
57pub inline fn isRegionalIndicator(cp: u21) bool {
58 return getProp(cp) == .regional;
59}
60
61pub inline fn isSpacingmark(cp: u21) bool {
62 return getProp(cp) == .spacing;
63}
64
65pub inline fn isZwj(cp: u21) bool {
66 return getProp(cp) == .zwj;
67}