]> git.notmuchmail.org Git - notmuch/blobdiff - sprinter-text.c
util: Fix two corner-cases in boolean term quoting function
[notmuch] / sprinter-text.c
index dfa54b5706981293ea5cf14a91ceb28137a081fb..7779488f99a3db4c7919e93210e86acccf9c8949 100644 (file)
@@ -38,6 +38,8 @@ text_string_len (struct sprinter *sp, const char *val, size_t len)
 static void
 text_string (struct sprinter *sp, const char *val)
 {
+    if (val == NULL)
+       val = "";
     text_string_len (sp, val, strlen (val));
 }
 
@@ -65,6 +67,14 @@ text_separator (struct sprinter *sp)
     fputc ('\n', sptxt->stream);
 }
 
+static void
+text0_separator (struct sprinter *sp)
+{
+    struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+    fputc ('\0', sptxt->stream);
+}
+
 static void
 text_set_prefix (struct sprinter *sp, const char *prefix)
 {
@@ -131,3 +141,17 @@ sprinter_text_create (const void *ctx, FILE *stream)
     res->stream = stream;
     return &res->vtable;
 }
+
+struct sprinter *
+sprinter_text0_create (const void *ctx, FILE *stream)
+{
+    struct sprinter *sp;
+
+    sp = sprinter_text_create (ctx, stream);
+    if (! sp)
+       return NULL;
+
+    sp->separator = text0_separator;
+
+    return sp;
+}