1const std = @import("std");
2const common = @import("./_common.zig");
3
4pub usingnamespace common.Main(struct {
5 pub const source_file = "ScriptExtensions";
6
7 pub const dest_file = "src/script_extensions.zig";
8
9 pub const dest_header =
10 \\const ucd = @import("./lib.zig");
11 \\
12 \\pub const ScriptExtension = struct {
13 \\ code: u21,
14 \\ scripts: []const ucd.Script,
15 \\};
16 \\
17 \\pub const data = [_]ScriptExtension{
18 \\
19 ;
20
21 pub const dest_footer =
22 \\};
23 \\
24 ;
25
26 pub fn exec(alloc: std.mem.Allocator, line: []const u8, writer: anytype) !void {
27 _ = alloc;
28 var it = std.mem.tokenizeAny(u8, line, "; ");
29
30 const first = it.next().?;
31
32 if (std.mem.indexOf(u8, first, "..")) |index| {
33 const start = try std.fmt.parseInt(u21, first[0..index], 16);
34 const end = try std.fmt.parseInt(u21, first[index + 2 ..], 16);
35 var i = start;
36 while (i <= end) : (i += 1) {
37 try writer.print(" .{{ .code = 0x{X}, .scripts = {} }},\n", .{ i, fmtScripts(it.rest()) });
38 }
39 } else {
40 try writer.print(" .{{ .code = 0x{s}, .scripts = {} }},\n", .{ first, fmtScripts(it.rest()) });
41 }
42 }
43});
44
45fn fmtScripts(bytes: []const u8) std.fmt.Formatter(formatScripts) {
46 return .{ .data = bytes };
47}
48
49fn formatScripts(bytes: []const u8, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
50 _ = fmt;
51 _ = options;
52 try writer.writeAll("&.{");
53 var it = std.mem.splitScalar(u8, bytes, ' ');
54 while (it.next()) |item| {
55 if (item.len == 0) continue;
56 try writer.print(" .{s},", .{item});
57 }
58 try writer.writeAll(" }");
59}