Commit 1f7aa1db authored by Geoff Simmons's avatar Geoff Simmons

tweak hex_decode()

parent 48de3054
...@@ -94,23 +94,6 @@ hex2byte(const unsigned char hi, const unsigned char lo) ...@@ -94,23 +94,6 @@ hex2byte(const unsigned char hi, const unsigned char lo)
return (nibble[hi - '0'] << 4) | nibble[lo - '0']; return (nibble[hi - '0'] << 4) | nibble[lo - '0'];
} }
static inline void
decode_str(const char *restrict const p, char *restrict *restrict dest,
unsigned char *restrict extranib)
{
const unsigned char *s = (unsigned char *) p;
char *d = *dest;
if (*extranib)
*d++ = hex2byte(*extranib, *s++);
while (*s && *(s+1)) {
*d++ = hex2byte(*s, *(s+1));
s += 2;
}
*extranib = *s;
*dest += d - *dest;
}
ssize_t ssize_t
hex_encode(const enum encoding enc, char *restrict const buf, hex_encode(const enum encoding enc, char *restrict const buf,
const size_t maxlen, const char *restrict const in, const size_t maxlen, const char *restrict const in,
...@@ -141,7 +124,6 @@ ssize_t ...@@ -141,7 +124,6 @@ ssize_t
hex_decode(const enum encoding dec, char *restrict const buf, hex_decode(const enum encoding dec, char *restrict const buf,
const size_t maxlen, const char *restrict const p, va_list ap) const size_t maxlen, const char *restrict const p, va_list ap)
{ {
const char *next;
char *dest = buf; char *dest = buf;
unsigned char extranib = 0; unsigned char extranib = 0;
ssize_t len; ssize_t len;
...@@ -165,14 +147,17 @@ hex_decode(const enum encoding dec, char *restrict const buf, ...@@ -165,14 +147,17 @@ hex_decode(const enum encoding dec, char *restrict const buf,
if (len & 1) if (len & 1)
extranib = '0'; extranib = '0';
SKIP_EMPTY(next, ap); for (const char *s = p; s != vrt_magic_string_end;
assert(next != vrt_magic_string_end || (p != NULL && *p != '\0')); s = va_arg(ap, const char *)) {
if (s == NULL || *s == '\0')
if (p != NULL && *p != '\0') continue;
decode_str(p, &dest, &extranib); if (extranib)
while (next != vrt_magic_string_end) { *dest++ = hex2byte(extranib, *s++);
decode_str(next, &dest, &extranib); while (*s && *(s+1)) {
SKIP_EMPTY(next, ap); *dest++ = hex2byte(*s, *(s+1));
s += 2;
}
extranib = *s;
} }
assert(dest <= buf + maxlen); assert(dest <= buf + maxlen);
return dest - buf; return dest - buf;
......
...@@ -31,11 +31,6 @@ ...@@ -31,11 +31,6 @@
#include "parse_encoding.h" #include "parse_encoding.h"
#define SKIP_EMPTY(next, ap) \
do { \
next = va_arg((ap), const char *); \
} while ((next) == NULL || *(next) == '\0')
/* /*
* SAFE LENGTH ESTIMATES * SAFE LENGTH ESTIMATES
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment