skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

string_quote.c (469B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/stralloc.h>
      4 #include <skalibs/skamisc.h>
      5 
      6 int string_quote_options (stralloc *sa, char const *s, size_t len, uint32_t options)
      7 {
      8   size_t base = sa->len ;
      9   int wasnull = !sa->s ;
     10   if (!stralloc_catb(sa, "\"", 1)) return 0 ;
     11   if (!string_quote_nodelim_mustquote_options(sa, s, len, "\"", 1, options) || !stralloc_catb(sa, "\"", 1))
     12   {
     13     if (wasnull) stralloc_free(sa) ; else sa->len = base ;
     14     return 0 ;
     15   }
     16   return 1 ;
     17 }