diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-05-19 15:45:37 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-05-19 16:27:54 +0200 |
commit | 8da140fd5548cfab0a2e945091ec78416b1a0d14 (patch) | |
tree | f62000eb23addab8b505fb8bf94ce8dcd6e54926 /tests/custom/03_stdlib/57_hexenc | |
parent | 9a724238c27dec032fe2ea75c4975718b0857f98 (diff) |
lib: introduce hexenc() and hexdec()
Add two new functions to deal with encoding and decoding of hexadecimal
digit strings:
- hexenc() - convert the given input value into a lower case hex digit
string, implicitely converting the input argument to a string value
if needed
- hexdec() - decode the given input hex digit string into a byte string,
skipping whitespace or optionally specified characters in the input
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/57_hexenc')
-rw-r--r-- | tests/custom/03_stdlib/57_hexenc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/57_hexenc b/tests/custom/03_stdlib/57_hexenc new file mode 100644 index 0000000..235ad66 --- /dev/null +++ b/tests/custom/03_stdlib/57_hexenc @@ -0,0 +1,24 @@ +The `hexenc()` function encodes the given byte string into a hexadecimal +digit string, converting the input value to a string if needed. + +Returns the encoded hexadecimal digit string. + +-- Testcase -- +{% + printf("%.J\n", [ + hexenc("Hello world!\n"), // encoding a simple string + hexenc(""), // empty input -> empty output + hexenc([1, 2, 3]), // implicit stringification + hexenc(null), // null input -> null output + ]); +%} +-- End -- + +-- Expect stdout -- +[ + "48656c6c6f20776f726c64210a", + "", + "5b20312c20322c2033205d", + null +] +-- End -- |