diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-07 14:06:12 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-07 14:06:12 -0700 |
commit | 480ccfd05a13ac36516c536a71203280a31b4d28 (patch) | |
tree | 4ae21bf95c9f3b4cce97a0a0473fe622fdb393eb /internal/jsonparse/hex.go | |
parent | 87013d526ea1b0647ef6e08758fe587cee11d854 (diff) | |
parent | 47549aa3d10808c063d45dcaa598887dadde59c5 (diff) |
Merge branch 'lukeshu/fixup'
Diffstat (limited to 'internal/jsonparse/hex.go')
-rw-r--r-- | internal/jsonparse/hex.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/jsonparse/hex.go b/internal/jsonparse/hex.go new file mode 100644 index 0000000..3ed5f01 --- /dev/null +++ b/internal/jsonparse/hex.go @@ -0,0 +1,20 @@ +// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> +// +// SPDX-License-Identifier: GPL-2.0-or-later + +package jsonparse + +const Hex = "0123456789abcdef" + +func HexToInt(c rune) (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 + } +} |