| author | |
| committer | |
| log | 0b8ecc8d7a29012845ad62e13be3d0db294fb3b4 |
| tree | 8454871d0da847e6519654026831c2f88f88fc7e |
| parent | aec4e3409674faa31562989f0cbc98f3e74e3960 |
| signature |
3 files changed, 20 insertions(+), 25 deletions(-)
README.md+1-1| ... | @@ -3,7 +3,7 @@ | ... | @@ -3,7 +3,7 @@ |
| 3 |  | 3 |  |
| 4 | [](https://github.com/nektro/zig-unicode-ucd/blob/master/LICENSE) | 4 | [](https://github.com/nektro/zig-unicode-ucd/blob/master/LICENSE) |
| 5 | [](https://github.com/sponsors/nektro) | 5 | [](https://github.com/sponsors/nektro) |
| 6 | [](https://ziglang.org/) | 6 | [](https://ziglang.org/) |
| 7 | [](https://github.com/nektro/zigmod) | 7 | [](https://github.com/nektro/zigmod) |
| 8 | 8 | ||
| 9 | Zig bindings for the Unicode Character Database | 9 | Zig bindings for the Unicode Character Database |
src/lib.zig+13-23| ... | @@ -50,39 +50,29 @@ pub const LineBreak = DerivedPropertyEnum("lb"); | ... | @@ -50,39 +50,29 @@ pub const LineBreak = DerivedPropertyEnum("lb"); |
| 50 | pub const IndicPositionalCategory = DerivedPropertyEnum("InPC"); | 50 | pub const IndicPositionalCategory = DerivedPropertyEnum("InPC"); |
| 51 | 51 | ||
| 52 | fn DerivedPropertyEnum(comptime prop: []const u8) type { | 52 | fn DerivedPropertyEnum(comptime prop: []const u8) type { |
| 53 | var fields: []const std.builtin.Type.EnumField = &.{}; | 53 | var len: usize = 0; |
| 54 | var names: []const []const u8 = &.{}; | ||
| 54 | @setEvalBranchQuota(10_000); | 55 | @setEvalBranchQuota(10_000); |
| 55 | for (property_value_aliases.data) |item| { | 56 | for (property_value_aliases.data) |item| { |
| 56 | if (std.mem.eql(u8, item[0], prop)) { | 57 | if (std.mem.eql(u8, item[0], prop)) { |
| 57 | fields = fields ++ &[_]std.builtin.Type.EnumField{.{ | 58 | len += 1; |
| 58 | .name = item[1], | 59 | names = names ++ &[_][]const u8{item[1]}; |
| 59 | .value = fields.len, | ||
| 60 | }}; | ||
| 61 | } | 60 | } |
| 62 | } | 61 | } |
| 63 | return @Type(.{ .@"enum" = .{ | 62 | const Tag = std.math.IntFittingRange(0, names.len - 1); |
| 64 | .tag_type = std.math.IntFittingRange(0, fields.len - 1), | 63 | return @Enum(Tag, .exhaustive, names, &std.simd.iota(Tag, names.len)); |
| 65 | .fields = fields, | ||
| 66 | .decls = &.{}, | ||
| 67 | .is_exhaustive = true, | ||
| 68 | } }); | ||
| 69 | } | 64 | } |
| 70 | 65 | ||
| 71 | fn DerivedPropertyLongEnum(comptime prop: []const u8) type { | 66 | fn DerivedPropertyLongEnum(comptime prop: []const u8) type { |
| 72 | var fields: []const std.builtin.Type.EnumField = &.{}; | 67 | var len: usize = 0; |
| 68 | var names: []const []const u8 = &.{}; | ||
| 73 | @setEvalBranchQuota(10_000); | 69 | @setEvalBranchQuota(10_000); |
| 74 | for (property_value_aliases.data) |item| { | 70 | for (property_value_aliases.data) |item| { |
| 75 | if (!std.mem.eql(u8, item[0], prop)) continue; | 71 | if (!std.mem.eql(u8, item[0], prop)) continue; |
| 76 | if (fields.len > 0 and std.mem.eql(u8, fields[fields.len - 1].name, item[2])) continue; | 72 | if (len > 0 and std.mem.eql(u8, names[len - 1], item[2])) continue; |
| 77 | fields = fields ++ &[_]std.builtin.Type.EnumField{.{ | 73 | len += 1; |
| 78 | .name = item[2], | 74 | names = names ++ &[_][]const u8{item[2]}; |
| 79 | .value = fields.len, | ||
| 80 | }}; | ||
| 81 | } | 75 | } |
| 82 | return @Type(.{ .@"enum" = .{ | 76 | const Tag = std.math.IntFittingRange(0, names.len - 1); |
| 83 | .tag_type = std.math.IntFittingRange(0, fields.len - 1), | 77 | return @Enum(Tag, .exhaustive, names, &std.simd.iota(Tag, names.len)); |
| 84 | .fields = fields, | ||
| 85 | .decls = &.{}, | ||
| 86 | .is_exhaustive = true, | ||
| 87 | } }); | ||
| 88 | } | 78 | } |
test.zig+6-1| ... | @@ -11,7 +11,12 @@ test { | ... | @@ -11,7 +11,12 @@ test { |
| 11 | _ = &ucd.composition_exclusions.data; | 11 | _ = &ucd.composition_exclusions.data; |
| 12 | _ = &ucd.derived_age.data; | 12 | _ = &ucd.derived_age.data; |
| 13 | _ = &ucd.derived_core_properties.data; | 13 | _ = &ucd.derived_core_properties.data; |
| 14 | std.testing.refAllDeclsRecursive(ucd.derived_normalization_props); | 14 | inline for (@typeInfo(ucd.derived_normalization_props).@"struct".decls) |d| { |
| 15 | const f = @field(ucd.derived_normalization_props, d.name); | ||
| 16 | if (@typeInfo(f).@"struct".decls.len == 0) _ = &f; | ||
| 17 | if (@typeInfo(f).@"struct".decls.len > 0) _ = &f.data; | ||
| 18 | if (@typeInfo(f).@"struct".decls.len > 0) _ = &f.data_range; | ||
| 19 | } | ||
| 15 | _ = &ucd.east_asian_width.data; | 20 | _ = &ucd.east_asian_width.data; |
| 16 | _ = &ucd.emoji_sources.data; | 21 | _ = &ucd.emoji_sources.data; |
| 17 | _ = &ucd.equivalent_unified_ideograph.data; | 22 | _ = &ucd.equivalent_unified_ideograph.data; |