blob: f58e0de52ac1bdac3a8c928e17f3c52cd6a8839d (
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
|
//! Combining Class Data
s1: []u16 = undefined,
s2: []u8 = undefined,
const CombiningData = @This();
pub fn init(allocator: mem.Allocator) !CombiningData {
const in_bytes = @embedFile("ccc");
var in_fbs = std.io.fixedBufferStream(in_bytes);
var reader = in_fbs.reader();
const endian = builtin.cpu.arch.endian();
var cbdata = CombiningData{};
const stage_1_len: u16 = try reader.readInt(u16, endian);
cbdata.s1 = try allocator.alloc(u16, stage_1_len);
errdefer allocator.free(cbdata.s1);
for (0..stage_1_len) |i| cbdata.s1[i] = try reader.readInt(u16, endian);
const stage_2_len: u16 = try reader.readInt(u16, endian);
cbdata.s2 = try allocator.alloc(u8, stage_2_len);
errdefer allocator.free(cbdata.s2);
_ = try reader.readAll(cbdata.s2);
return cbdata;
}
pub fn deinit(cbdata: *const CombiningData, allocator: mem.Allocator) void {
allocator.free(cbdata.s1);
allocator.free(cbdata.s2);
}
/// Returns the canonical combining class for a code point.
pub fn ccc(cbdata: CombiningData, cp: u21) u8 {
return cbdata.s2[cbdata.s1[cp >> 8] + (cp & 0xff)];
}
/// True if `cp` is a starter code point, not a combining character.
pub fn isStarter(cbdata: CombiningData, cp: u21) bool {
return cbdata.s2[cbdata.s1[cp >> 8] + (cp & 0xff)] == 0;
}
const std = @import("std");
const builtin = @import("builtin");
const mem = std.mem;
|