diff options
Diffstat (limited to 'misc.go')
-rw-r--r-- | misc.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -15,6 +15,19 @@ const Tab = "\t" const hex = "0123456789abcdef" +func hex2int[T interface{ byte | rune }](c T) (byte, bool) { + switch { + case '0' <= c && c <= '9': + return byte(c) - '0', true + case 'a' <= c && c <= 'f': + return byte(c) - 'a' + 10, true + case 'A' <= c && c <= 'F': + return byte(c) - 'A' + 10, true + default: + return 0, false + } +} + var ( numberType = reflect.TypeOf(json.Number("")) byteType = reflect.TypeOf(byte(0)) |