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)
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
hex_encode(const enum encoding enc, char *restrict const buf,
const size_t maxlen, const char *restrict const in,
......@@ -141,7 +124,6 @@ ssize_t
hex_decode(const enum encoding dec, char *restrict const buf,
const size_t maxlen, const char *restrict const p, va_list ap)
{
const char *next;
char *dest = buf;
unsigned char extranib = 0;
ssize_t len;
......@@ -165,14 +147,17 @@ hex_decode(const enum encoding dec, char *restrict const buf,
if (len & 1)
extranib = '0';
SKIP_EMPTY(next, ap);
assert(next != vrt_magic_string_end || (p != NULL && *p != '\0'));
if (p != NULL && *p != '\0')
decode_str(p, &dest, &extranib);
while (next != vrt_magic_string_end) {
decode_str(next, &dest, &extranib);
SKIP_EMPTY(next, ap);
for (const char *s = p; s != vrt_magic_string_end;
s = va_arg(ap, const char *)) {
if (s == NULL || *s == '\0')
continue;
if (extranib)
*dest++ = hex2byte(extranib, *s++);
while (*s && *(s+1)) {
*dest++ = hex2byte(*s, *(s+1));
s += 2;
}
extranib = *s;
}
assert(dest <= buf + maxlen);
return dest - buf;
......
......@@ -31,11 +31,6 @@
#include "parse_encoding.h"
#define SKIP_EMPTY(next, ap) \
do { \
next = va_arg((ap), const char *); \
} while ((next) == NULL || *(next) == '\0')
/*
* 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