def rust_hex(e):
return "\\u{{{}}}".format(hex(ord(e))[2:])
import html
entities5 = html.entities.html5
entities = list(sorted([(k[:-1], entities5[k]) for k in entities5.keys() if k[-1] == ';']))
print("""// Autogenerated by script/make_entity_data.py
pub const MIN_LENGTH: usize = {};
pub const MAX_LENGTH: usize = {};
pub static ENTITIES: [(&'static str, &'static str); {}] =
[""".format(
min(map(lambda e: len(e[0]), entities)),
max(map(lambda e: len(e[0]), entities)),
len(entities)), end='')
for (i, (ent, bs)) in enumerate(entities):
if i > 0:
print(' ', end='')
print('("{}", "{}")'.format(ent, ''.join(map(rust_hex, bs))), end='')
if i < len(entities) - 1:
print(',')
print("];")