summaryrefslogtreecommitdiff
path: root/misc.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-13 22:05:20 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-08-14 13:44:39 -0600
commit4b00a61c33d6a448c59c5509c0a408f527308c8b (patch)
treefb38f3b53a01438054798c76c6fd471d39637d42 /misc.go
parent567beedfc8f6418e27259fa774e6c7ba1a685c22 (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.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/misc.go b/misc.go
index 132b177..a567cc7 100644
--- a/misc.go
+++ b/misc.go
@@ -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))