summaryrefslogtreecommitdiff
path: root/src/libstddjb/string_quote.c
blob: e648af421aeb137a4ee01482b8aa24823cb9adde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* ISC license. */

#include <string.h>
#include <skalibs/stralloc.h>
#include <skalibs/skamisc.h>

int string_quote (stralloc *sa, char const *s, size_t len)
{
  size_t base = sa->len ;
  int wasnull = !sa->s ;
  if (!stralloc_catb(sa, "\"", 1)) return 0 ;
  if (!string_quote_nodelim(sa, s, len) || !stralloc_catb(sa, "\"", 1))
  {
    if (wasnull) stralloc_free(sa) ; else sa->len = base ;
    return 0 ;
  }
  return 1 ;
}