diff options
author | default <nobody@localhost> | 2023-04-10 09:14:44 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-04-10 09:14:44 +0200 |
commit | 74098ec443b479ce751c28d875c53ec274fcc3a4 (patch) | |
tree | 179b5e62e3cdc2830a226de0c0669bd66823c859 /xs_encdec.h | |
parent | 578d70ddc01f05a3564fb3028d2e3cfc8da5cc64 (diff) |
Backport from xs.
Diffstat (limited to 'xs_encdec.h')
-rw-r--r-- | xs_encdec.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/xs_encdec.h b/xs_encdec.h index 5966583..b88736e 100644 --- a/xs_encdec.h +++ b/xs_encdec.h @@ -6,6 +6,7 @@ xs_str *xs_hex_enc(const xs_val *data, int size); xs_val *xs_hex_dec(const xs_str *hex, int *size); + int xs_is_hex(const char *str); xs_str *xs_base64_enc(const xs_val *data, int sz); xs_val *xs_base64_dec(const xs_str *data, int *size); xs_str *xs_utf8_enc(xs_str *str, unsigned int cpoint); @@ -65,6 +66,18 @@ xs_val *xs_hex_dec(const xs_str *hex, int *size) } +int xs_is_hex(const char *str) +/* returns 1 if str is an hex string */ +{ + while (*str) { + if (strchr("0123456789abcdefABCDEF", *str++) == NULL) + return 0; + } + + return 1; +} + + xs_str *xs_base64_enc(const xs_val *data, int sz) /* encodes data to base64 */ { |