diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-13 22:05:20 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-14 13:44:39 -0600 |
commit | 4b00a61c33d6a448c59c5509c0a408f527308c8b (patch) | |
tree | fb38f3b53a01438054798c76c6fd471d39637d42 /misc.go | |
parent | 567beedfc8f6418e27259fa774e6c7ba1a685c22 (diff) |
parse: Rework to avoid passing around function pointers
"Ignore whitespace" is probably essential for viewing this patch.
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)) |