summaryrefslogtreecommitdiff
path: root/codegen/numeric.zig
diff options
context:
space:
mode:
authorGravatar Jose Colon Rodriguez2024-03-25 20:05:36 -0400
committerGravatar Jose Colon Rodriguez2024-03-25 20:05:36 -0400
commit961d2ec2f9075f30e9264ed2db6c394cfa5967f9 (patch)
tree4c6988e2de888c17507566c9d90d1e755ec4346f /codegen/numeric.zig
parentNumericData (diff)
downloadzg-961d2ec2f9075f30e9264ed2db6c394cfa5967f9.tar.gz
zg-961d2ec2f9075f30e9264ed2db6c394cfa5967f9.tar.xz
zg-961d2ec2f9075f30e9264ed2db6c394cfa5967f9.zip
CaseData
Diffstat (limited to 'codegen/numeric.zig')
-rw-r--r--codegen/numeric.zig45
1 files changed, 20 insertions, 25 deletions
diff --git a/codegen/numeric.zig b/codegen/numeric.zig
index 80fc7c2..ad8490c 100644
--- a/codegen/numeric.zig
+++ b/codegen/numeric.zig
@@ -1,5 +1,6 @@
1const std = @import("std"); 1const std = @import("std");
2const builtin = @import("builtin"); 2const builtin = @import("builtin");
3const mem = std.mem;
3 4
4const block_size = 256; 5const block_size = 256;
5const Block = [block_size]u8; 6const Block = [block_size]u8;
@@ -15,7 +16,7 @@ const BlockMap = std.HashMap(
15 } 16 }
16 17
17 pub fn eql(_: @This(), a: Block, b: Block) bool { 18 pub fn eql(_: @This(), a: Block, b: Block) bool {
18 return std.mem.eql(u8, &a, &b); 19 return mem.eql(u8, &a, &b);
19 } 20 }
20 }, 21 },
21 std.hash_map.default_max_load_percentage, 22 std.hash_map.default_max_load_percentage,
@@ -31,17 +32,17 @@ pub fn main() !void {
31 32
32 var line_buf: [4096]u8 = undefined; 33 var line_buf: [4096]u8 = undefined;
33 34
34 // Process DerivedCombiningClass.txt 35 // Process DerivedNumericType.txt
35 var num_file = try std.fs.cwd().openFile("data/unicode/extracted/DerivedNumericType.txt", .{}); 36 var in_file = try std.fs.cwd().openFile("data/unicode/extracted/DerivedNumericType.txt", .{});
36 defer num_file.close(); 37 defer in_file.close();
37 var num_buf = std.io.bufferedReader(num_file.reader()); 38 var in_buf = std.io.bufferedReader(in_file.reader());
38 const num_reader = num_buf.reader(); 39 const in_reader = in_buf.reader();
39 40
40 while (try num_reader.readUntilDelimiterOrEof(&line_buf, '\n')) |line| { 41 while (try in_reader.readUntilDelimiterOrEof(&line_buf, '\n')) |line| {
41 if (line.len == 0 or line[0] == '#') continue; 42 if (line.len == 0 or line[0] == '#') continue;
42 const no_comment = if (std.mem.indexOfScalar(u8, line, '#')) |octo| line[0..octo] else line; 43 const no_comment = if (mem.indexOfScalar(u8, line, '#')) |octo| line[0..octo] else line;
43 44
44 var field_iter = std.mem.tokenizeAny(u8, no_comment, "; "); 45 var field_iter = mem.tokenizeAny(u8, no_comment, "; ");
45 var current_code: [2]u21 = undefined; 46 var current_code: [2]u21 = undefined;
46 47
47 var i: usize = 0; 48 var i: usize = 0;
@@ -49,7 +50,7 @@ pub fn main() !void {
49 switch (i) { 50 switch (i) {
50 0 => { 51 0 => {
51 // Code point(s) 52 // Code point(s)
52 if (std.mem.indexOf(u8, field, "..")) |dots| { 53 if (mem.indexOf(u8, field, "..")) |dots| {
53 current_code = .{ 54 current_code = .{
54 try std.fmt.parseInt(u21, field[0..dots], 16), 55 try std.fmt.parseInt(u21, field[0..dots], 16),
55 try std.fmt.parseInt(u21, field[dots + 2 ..], 16), 56 try std.fmt.parseInt(u21, field[dots + 2 ..], 16),
@@ -61,25 +62,19 @@ pub fn main() !void {
61 }, 62 },
62 1 => { 63 1 => {
63 // Numeric type 64 // Numeric type
64 if (std.mem.eql(u8, field, "Numeric")) { 65 var bit: u8 = 0;
65 for (current_code[0]..current_code[1] + 1) |cp| { 66
66 const gop = try flat_map.getOrPut(@intCast(cp)); 67 if (mem.eql(u8, field, "Numeric")) bit = 1;
67 if (!gop.found_existing) gop.value_ptr.* = 0; 68 if (mem.eql(u8, field, "Digit")) bit = 2;
68 gop.value_ptr.* |= 1; 69 if (mem.eql(u8, field, "Decimal")) bit = 4;
69 } 70
70 } else if (std.mem.eql(u8, field, "Digit")) { 71 if (bit != 0) {
71 for (current_code[0]..current_code[1] + 1) |cp| {
72 const gop = try flat_map.getOrPut(@intCast(cp));
73 if (!gop.found_existing) gop.value_ptr.* = 0;
74 gop.value_ptr.* |= 2;
75 }
76 } else if (std.mem.eql(u8, field, "Decimal")) {
77 for (current_code[0]..current_code[1] + 1) |cp| { 72 for (current_code[0]..current_code[1] + 1) |cp| {
78 const gop = try flat_map.getOrPut(@intCast(cp)); 73 const gop = try flat_map.getOrPut(@intCast(cp));
79 if (!gop.found_existing) gop.value_ptr.* = 0; 74 if (!gop.found_existing) gop.value_ptr.* = 0;
80 gop.value_ptr.* |= 4; 75 gop.value_ptr.* |= bit;
81 } 76 }
82 } else continue; 77 }
83 }, 78 },
84 else => {}, 79 else => {},
85 } 80 }