diff --git a/README.md b/README.md index 49a9b63ecd3dac35c3a58c9ecc3198e2ea0e3093..ea075b1c39425693cbc7e47ddfc4443855e455e5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![loc](https://sloc.xyz/github/nektro/zig-unicode-ucd) [![license](https://img.shields.io/github/license/nektro/zig-unicode-ucd.svg)](https://github.com/nektro/zig-unicode-ucd/blob/master/LICENSE) [![nektro @ github sponsors](https://img.shields.io/badge/sponsors-nektro-purple?logo=github)](https://github.com/sponsors/nektro) -[![Zig](https://img.shields.io/badge/Zig-0.14-f7a41d)](https://ziglang.org/) +[![Zig](https://img.shields.io/badge/Zig-0.16-f7a41d)](https://ziglang.org/) [![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod) Zig bindings for the Unicode Character Database diff --git a/src/lib.zig b/src/lib.zig index bcc280aac50d001973a5377b8d9fa5ecf4f59bc9..1545b8899cccf99bcd0d73c49f6862bb9c202ccb 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -50,39 +50,29 @@ pub const LineBreak = DerivedPropertyEnum("lb"); pub const IndicPositionalCategory = DerivedPropertyEnum("InPC"); fn DerivedPropertyEnum(comptime prop: []const u8) type { - var fields: []const std.builtin.Type.EnumField = &.{}; + var len: usize = 0; + var names: []const []const u8 = &.{}; @setEvalBranchQuota(10_000); for (property_value_aliases.data) |item| { if (std.mem.eql(u8, item[0], prop)) { - fields = fields ++ &[_]std.builtin.Type.EnumField{.{ - .name = item[1], - .value = fields.len, - }}; + len += 1; + names = names ++ &[_][]const u8{item[1]}; } } - return @Type(.{ .@"enum" = .{ - .tag_type = std.math.IntFittingRange(0, fields.len - 1), - .fields = fields, - .decls = &.{}, - .is_exhaustive = true, - } }); + const Tag = std.math.IntFittingRange(0, names.len - 1); + return @Enum(Tag, .exhaustive, names, &std.simd.iota(Tag, names.len)); } fn DerivedPropertyLongEnum(comptime prop: []const u8) type { - var fields: []const std.builtin.Type.EnumField = &.{}; + var len: usize = 0; + var names: []const []const u8 = &.{}; @setEvalBranchQuota(10_000); for (property_value_aliases.data) |item| { if (!std.mem.eql(u8, item[0], prop)) continue; - if (fields.len > 0 and std.mem.eql(u8, fields[fields.len - 1].name, item[2])) continue; - fields = fields ++ &[_]std.builtin.Type.EnumField{.{ - .name = item[2], - .value = fields.len, - }}; + if (len > 0 and std.mem.eql(u8, names[len - 1], item[2])) continue; + len += 1; + names = names ++ &[_][]const u8{item[2]}; } - return @Type(.{ .@"enum" = .{ - .tag_type = std.math.IntFittingRange(0, fields.len - 1), - .fields = fields, - .decls = &.{}, - .is_exhaustive = true, - } }); + const Tag = std.math.IntFittingRange(0, names.len - 1); + return @Enum(Tag, .exhaustive, names, &std.simd.iota(Tag, names.len)); } diff --git a/test.zig b/test.zig index 075ed1953e15de1ca2381eca9b9dc9e3711dccf8..69c4252580fdc841dc9eeacdfa72a66e5683ed39 100644 --- a/test.zig +++ b/test.zig @@ -11,7 +11,12 @@ test { _ = &ucd.composition_exclusions.data; _ = &ucd.derived_age.data; _ = &ucd.derived_core_properties.data; - std.testing.refAllDeclsRecursive(ucd.derived_normalization_props); + inline for (@typeInfo(ucd.derived_normalization_props).@"struct".decls) |d| { + const f = @field(ucd.derived_normalization_props, d.name); + if (@typeInfo(f).@"struct".decls.len == 0) _ = &f; + if (@typeInfo(f).@"struct".decls.len > 0) _ = &f.data; + if (@typeInfo(f).@"struct".decls.len > 0) _ = &f.data_range; + } _ = &ucd.east_asian_width.data; _ = &ucd.emoji_sources.data; _ = &ucd.equivalent_unified_ideograph.data;