summaryrefslogtreecommitdiff
path: root/misc.go
diff options
context:
space:
mode:
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))