diff options
Diffstat (limited to 'src/libstddjb/string_quote_nodelim_mustquote.c')
-rw-r--r-- | src/libstddjb/string_quote_nodelim_mustquote.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/libstddjb/string_quote_nodelim_mustquote.c b/src/libstddjb/string_quote_nodelim_mustquote.c index 535628d..c25d483 100644 --- a/src/libstddjb/string_quote_nodelim_mustquote.c +++ b/src/libstddjb/string_quote_nodelim_mustquote.c @@ -1,21 +1,25 @@ /* ISC license. */ +#include <stdint.h> #include <string.h> #include <errno.h> + #include <skalibs/fmtscan.h> #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> -int string_quote_nodelim_mustquote (stralloc *sa, char const *s, size_t len, char const *delim, size_t delimlen) +int string_quote_nodelim_mustquote_options (stralloc *sa, char const *s, size_t len, char const *delim, size_t delimlen, uint32_t options) { char class[256] = "dddddddaaaaaaaddddddddddddddddddcccccccccccccccceeeeeeeeeeccccccccccccccccccccccccccccccccccbcccceeeeeecccccccecccececececcccccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" ; size_t base = sa->len ; size_t i = 0 ; int wasnull = !sa->s ; + if (options & 1) class[' '] = 'f' ; + for (; i < delimlen ; i++) - if (class[(unsigned char)delim[i]] == 'c') - class[(unsigned char)delim[i]] = 'b' ; + if (class[(uint8_t)delim[i]] == 'c' || class[(uint8_t)delim[i]] == 'b') + class[(uint8_t)delim[i]] = 'b' ; else return (errno = EINVAL, 0) ; for (i = 0 ; i < len ; i++) @@ -39,10 +43,8 @@ int string_quote_nodelim_mustquote (stralloc *sa, char const *s, size_t len, cha } case 'c' : case 'e' : - { if (!stralloc_catb(sa, s+i, 1)) goto err ; break ; - } case 'd' : { char fmt[5] = "\\0x" ; @@ -50,6 +52,9 @@ int string_quote_nodelim_mustquote (stralloc *sa, char const *s, size_t len, cha if (!stralloc_catb(sa, fmt, 5)) goto err ; break ; } + case 'f' : + if (!stralloc_catb(sa, "\\s", 2)) goto err ; + break ; default : errno = EFAULT ; goto err ; /* can't happen */ } } |