summaryrefslogtreecommitdiff
path: root/internal/hex.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-26 00:07:39 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-26 00:08:56 -0700
commit4148776399cb7ea5e10c74dc465e4e1e682cb399 (patch)
treedaf8a3aa6521d3d56aa986f10c3d23ea1b016f4b /internal/hex.go
parente483afa206686ce748ad270140f99fad9d713aad (diff)
Move the Parser to the internal package
Diffstat (limited to 'internal/hex.go')
-rw-r--r--internal/hex.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/hex.go b/internal/hex.go
new file mode 100644
index 0000000..9ef78eb
--- /dev/null
+++ b/internal/hex.go
@@ -0,0 +1,20 @@
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package internal
+
+const Hex = "0123456789abcdef"
+
+func HexToInt[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
+ }
+}