Commit b469b6e7 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Teach VSB_quote() to hexdump. All zero bits will be elided to "0x0...0"

parent 655aadea
......@@ -78,7 +78,8 @@ void VSB_delete(struct vsb *);
void VSB_destroy(struct vsb **);
#define VSB_QUOTE_NONL 1
#define VSB_QUOTE_JSON 2
void VSB_quote(struct vsb *s, const char *p, int len, int how);
#define VSB_QUOTE_HEX 4
void VSB_quote(struct vsb *, const void *, int len, int how);
void VSB_indent(struct vsb *, int);
#ifdef __cplusplus
};
......
......@@ -500,13 +500,32 @@ VSB_destroy(struct vsb **s)
* Quote a string
*/
void
VSB_quote(struct vsb *s, const char *p, int len, int how)
VSB_quote(struct vsb *s, const void *v, int len, int how)
{
const char *p;
const char *q;
int quote = 0;
const unsigned char *u, *w;
assert(v != NULL);
if (len == -1)
len = strlen(p);
len = strlen(v);
if (how & VSB_QUOTE_HEX) {
u = v;
for (w = u; w < u + len; w++)
if (*w != 0x00)
break;
VSB_printf(s, "0x");
if (w == u + len) {
VSB_printf(s, "0...0");
} else {
for (w = u; w < u + len; w++)
VSB_printf(s, "%02x", *w);
}
return;
}
p = v;
for (q = p; q < p + len; q++) {
if (!isgraph(*q) || *q == '"' || *q == '\\') {
......
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