fix hex.encode and add tests for the package

This commit is contained in:
Laytan Laats
2023-05-15 20:40:47 +02:00
parent 6e4fab19a2
commit 2ab6de8ee4
2 changed files with 97 additions and 4 deletions
+4 -4
View File
@@ -4,11 +4,11 @@ import "core:strings"
encode :: proc(src: []byte, allocator := context.allocator) -> []byte #no_bounds_check {
dst := make([]byte, len(src) * 2, allocator)
for i := 0; i < len(src); i += 1 {
for i, j := 0, 0; i < len(src); i += 1 {
v := src[i]
dst[i] = HEXTABLE[v>>4]
dst[i+1] = HEXTABLE[v&0x0f]
i += 2
dst[j] = HEXTABLE[v>>4]
dst[j+1] = HEXTABLE[v&0x0f]
j += 2
}
return dst