Add hex encoding/decoding

This commit is contained in:
2026-08-11 23:36:48 +02:00
parent 141220aecb
commit 86d2648cca
3 changed files with 113 additions and 1 deletions
+28
View File
@@ -533,6 +533,33 @@ void string_test_utf8(void)
TRACEF("str4:\n");
print_runes(str4); // this should be a valid code point
}
void string_test_hex(void)
{
MArena arena;
U8 data[4096];
marena_init(&arena, data, sizeof data);
Allocator allocator = marena_allocator(&arena);
Str str1 = S("Hello World ☺");
Str str1_encoded = str_hex_encode_alloc(&allocator, str1);
printf("str1_encoded: '%.*s'\n", str1_encoded.len, str1_encoded.str);
Str str1_decoded = str_hex_decode_alloc(&allocator, str1_encoded);
printf("str1_decoded: '%.*s'\n", str1_decoded.len, str1_decoded.str);
Str str2 = S("");
Str str2_encoded = str_hex_encode_alloc(&allocator, str2);
printf("str2_encoded: '%.*s'\n", str2_encoded.len, str2_encoded.str);
Str str2_decoded = str_hex_decode_alloc(&allocator, str2_encoded);
printf("str2_decoded: '%.*s'\n", str2_decoded.len, str2_decoded.str);
}
int main(int argc, char *argv[])
@@ -552,6 +579,7 @@ int main(int argc, char *argv[])
string_test_misc();
string_test_join();
string_test_utf8();
string_test_hex();
}