| ... | @@ -14,16 +14,13 @@ pub const Codepoints = union(enum) { | ... | @@ -14,16 +14,13 @@ pub const Codepoints = union(enum) { |
| 14 | | 14 | |
| 15 | pub const ENTITIES = @import("entities.zig").ENTITIES; | 15 | pub const ENTITIES = @import("entities.zig").ENTITIES; |
| 16 | | 16 | |
| 17 | fn order(_: void, lhs: Entity, rhs: Entity) std.math.Order { | 17 | fn compare(lhs: Entity, rhs: Entity) std.math.Order { |
| 18 | return std.mem.order(u8, lhs.entity, rhs.entity); | 18 | return std.mem.order(u8, lhs.entity, rhs.entity); |
| 19 | } | 19 | } |
| 20 | | 20 | |
| 21 | pub fn lookup(entity: []const u8) ?Entity { | 21 | pub fn lookup(entity: []const u8) ?Entity { |
| 22 | const maybe_index = std.sort.binarySearch(Entity, Entity{ | 22 | const context: Entity = .{ .entity = entity, .codepoints = .{ .Single = 0 }, .characters = "" }; |
| 23 | .entity = entity, | 23 | const maybe_index = std.sort.binarySearch(Entity, &ENTITIES, context, compare); |
| 24 | .codepoints = .{ .Single = 0 }, | | |
| 25 | .characters = "", | | |
| 26 | }, ENTITIES[0..], {}, order); | | |
| 27 | | 24 | |
| 28 | if (maybe_index) |index| { | 25 | if (maybe_index) |index| { |
| 29 | return ENTITIES[index]; | 26 | return ENTITIES[index]; |