summaryrefslogtreecommitdiff
path: root/src/gbp.zig
blob: fa4ad54dcd1cd4ca3ecae195854ea2cfbfab844b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const std = @import("std");
const mem = std.mem;

const gbp = @import("ziglyph").grapheme_break;
const Trie = @import("trie.zig").Trie;
const Prop = @import("trie.zig").Prop;

var trie: Trie = undefined;

pub fn init(allocator: mem.Allocator) !void {
    trie = .{ .allocator = allocator, .root = .{} };

    for ('\u{0}'..'\u{10ffff}') |i| {
        const cp: u21 = @intCast(i);
        const prop = Prop.forCodePoint(cp);
        if (prop == .none) continue;
        try trie.put(cp, prop);
    }

    const prop = Prop.forCodePoint('\u{10ffff}');
    if (prop == .none) return;
    try trie.put('\u{10ffff}', prop);
}

inline fn getProp(cp: u21) Prop {
    return if (trie.get(cp)) |prop| prop else .none;
}

pub inline fn isControl(cp: u21) bool {
    return getProp(cp) == .control;
}

pub inline fn isExtend(cp: u21) bool {
    return getProp(cp) == .extend;
}

pub inline fn isL(cp: u21) bool {
    return getProp(cp) == .hangul_l;
}
pub inline fn isLv(cp: u21) bool {
    return getProp(cp) == .hangul_lv;
}
pub inline fn isLvt(cp: u21) bool {
    return getProp(cp) == .hangul_lvt;
}
pub inline fn isV(cp: u21) bool {
    return getProp(cp) == .hangul_v;
}
pub inline fn isT(cp: u21) bool {
    return getProp(cp) == .hangul_t;
}

pub inline fn isPrepend(cp: u21) bool {
    return getProp(cp) == .prepend;
}

pub inline fn isRegionalIndicator(cp: u21) bool {
    return getProp(cp) == .regional;
}

pub inline fn isSpacingmark(cp: u21) bool {
    return getProp(cp) == .spacing;
}

pub inline fn isZwj(cp: u21) bool {
    return getProp(cp) == .zwj;
}