| 1 | const std = @import("std"); |
| 2 | const common = @import("./_common.zig"); |
| 3 | |
| 4 | pub usingnamespace common.Main(struct { |
| 5 | pub const source_file = "CaseFolding"; |
| 6 | |
| 7 | pub const dest_file = "src/case_folding.zig"; |
| 8 | |
| 9 | pub const dest_header = |
| 10 | \\pub const CaseFolding = struct { |
| 11 | \\ code: u21, |
| 12 | \\ status: Status, |
| 13 | \\ mapping: Mapping, |
| 14 | \\ |
| 15 | \\ pub const Status = enum { |
| 16 | \\ C, |
| 17 | \\ F, |
| 18 | \\ S, |
| 19 | \\ T, |
| 20 | \\ }; |
| 21 | \\ |
| 22 | \\ pub const Mapping = union(Status) { |
| 23 | \\ C: u21, |
| 24 | \\ F: []const u21, |
| 25 | \\ S: u21, |
| 26 | \\ T: u21, |
| 27 | \\ }; |
| 28 | \\}; |
| 29 | \\ |
| 30 | \\pub const data = [_]CaseFolding{ |
| 31 | \\ |
| 32 | ; |
| 33 | |
| 34 | pub const dest_footer = |
| 35 | \\}; |
| 36 | \\ |
| 37 | ; |
| 38 | |
| 39 | pub fn exec(alloc: std.mem.Allocator, line: []const u8, writer: anytype) !void { |
| 40 | _ = alloc; |
| 41 | var it = std.mem.splitSequence(u8, line, "; "); |
| 42 | const code = it.next().?; |
| 43 | const status = it.next().?; |
| 44 | try writer.print(" .{{ .code = 0x{s}, .status = .{s}, .mapping = .{{ .{s} =", .{ code, status, status }); |
| 45 | |
| 46 | switch (std.meta.stringToEnum(enum { C, F, S, T }, status) orelse @panic(status)) { |
| 47 | .C, .S, .T => { |
| 48 | const mapping = it.next().?; |
| 49 | try writer.print(" 0x{s}", .{mapping}); |
| 50 | }, |
| 51 | .F => { |
| 52 | const mapping = it.next().?; |
| 53 | var jt = std.mem.splitScalar(u8, mapping, ' '); |
| 54 | try writer.writeAll(" &[_]u21{"); |
| 55 | while (jt.next()) |jtem| { |
| 56 | try writer.print("0x{s},", .{jtem}); |
| 57 | } |
| 58 | try writer.writeAll("}"); |
| 59 | }, |
| 60 | } |
| 61 | try writer.writeAll(" } },\n"); |
| 62 | } |
| 63 | }); |