1const std = @import("std");
2const testing = std.testing;
3
4pub const Entity = struct {
5 entity: []const u8,
6 codepoints: Codepoints,
7 characters: []const u8,
8};
9
10pub const Codepoints = union(enum) {
11 Single: u32,
12 Double: [2]u32,
13};
14
15pub const ENTITIES = @import("entities.zig").ENTITIES;
16
17fn compare(lhs: Entity, rhs: Entity) std.math.Order {
18 return std.mem.order(u8, lhs.entity, rhs.entity);
19}
20
21pub fn lookup(entity: []const u8) ?Entity {
22 const context: Entity = .{ .entity = entity, .codepoints = .{ .Single = 0 }, .characters = "" };
23 const maybe_index = std.sort.binarySearch(Entity, &ENTITIES, context, compare);
24
25 if (maybe_index) |index| {
26 return ENTITIES[index];
27 }
28 return null;
29}