blob: 2c62ed5b8e889d8ff984ad8732f3fc2d11713868 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
with open("itoa_lut.h", "w") as f:
f.write("#include <stdint.h>\n")
f.write("typedef struct { char chars[3]; uint8_t len; } LutEntry;\n")
f.write("const LutEntry itoa_lut[256] = {\n")
out = []
for i in range(0, 256):
running=len(str(i))
s = str(i)
while len(s) < 3:
s=s+chr(69)
out.append("{{"+",".join(map(lambda x: f"'{x}'", s))+"}, "+str(len(str(i)))+"}")
f.write(",\n".join(out))
f.write("\n};")
|