//go:build ignore

package main

import (
	"fmt"
	"log"
	"os"
)

const template = `// Code generated by go run tables_gen.go; DO NOT EDIT.

package hex

const HexToIntTable = %q
`

func main() {
	var HexToIntTable [256]byte

	for i := 0; i < 256; i++ {
		c := byte(16)

		if i >= '0' && i <= '9' {
			c = byte(i) - '0'
		} else if i >= 'a' && i <= 'f' {
			c = byte(i) - 'a' + 10
		} else if i >= 'A' && i <= 'F' {
			c = byte(i) - 'A' + 10
		}

		HexToIntTable[i] = c
	}

	data := fmt.Sprintf(template, HexToIntTable)

	err := os.WriteFile("tables.go", []byte(data), 0o660)
	if err != nil {
		log.Fatal(err)
	}
}
