From 6fab4d7598d0be4908e54d469171a1715e57cda2 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Mon, 22 Jun 2009 20:03:16 +0200 Subject: Add a parameter to quote() to specify which characters to quote --- include/misc.h | 2 +- libmisc/quote.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/misc.h b/include/misc.h index 58c2640..0c5fdcc 100644 --- a/include/misc.h +++ b/include/misc.h @@ -17,7 +17,7 @@ extern int high_water_alloc(void **buf, size_t *bufsize, size_t newsize); -extern const char *quote(const char *str); +extern const char *quote(const char *str, const char *quote_chars); extern char *unquote(char *str); extern char *next_line(FILE *file); diff --git a/libmisc/quote.c b/libmisc/quote.c index 4fb7035..f98c887 100644 --- a/libmisc/quote.c +++ b/libmisc/quote.c @@ -22,7 +22,7 @@ #include #include "misc.h" -const char *quote(const char *str) +const char *quote(const char *str, const char *quote_chars) { static char *quoted_str; static size_t quoted_str_len; @@ -34,7 +34,7 @@ const char *quote(const char *str) return str; for (nonpr = 0, s = (unsigned char *)str; *s != '\0'; s++) - if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=') + if (*s == '\\' || strchr(quote_chars, *s)) nonpr++; if (nonpr == 0) return str; @@ -43,7 +43,7 @@ const char *quote(const char *str) (s - (unsigned char *)str) + nonpr * 3 + 1)) return NULL; for (s = (unsigned char *)str, q = quoted_str; *s != '\0'; s++) { - if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=') { + if (*s == '\\' || strchr(quote_chars, *s)) { *q++ = '\\'; *q++ = '0' + ((*s >> 6) ); *q++ = '0' + ((*s >> 3) & 7); -- cgit v1.2.3