]> git.notmuchmail.org Git - notmuch/blobdiff - sprinter-text.c
test: Test upgrade to ghost messages feature
[notmuch] / sprinter-text.c
index b208840be72df7d0b2431737abb0f0c28b760eac..7779488f99a3db4c7919e93210e86acccf9c8949 100644 (file)
@@ -25,14 +25,22 @@ struct sprinter_text {
 };
 
 static void
-text_string (struct sprinter *sp, const char *val)
+text_string_len (struct sprinter *sp, const char *val, size_t len)
 {
     struct sprinter_text *sptxt = (struct sprinter_text *) sp;
 
     if (sptxt->current_prefix != NULL)
        fprintf (sptxt->stream, "%s:", sptxt->current_prefix);
 
-    fputs(val, sptxt->stream);
+    fwrite (val, len, 1, sptxt->stream);
+}
+
+static void
+text_string (struct sprinter *sp, const char *val)
+{
+    if (val == NULL)
+       val = "";
+    text_string_len (sp, val, strlen (val));
 }
 
 static void
@@ -59,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)
 {
@@ -105,6 +121,7 @@ sprinter_text_create (const void *ctx, FILE *stream)
            .begin_list = text_begin_list,
            .end = text_end,
            .string = text_string,
+           .string_len = text_string_len,
            .integer = text_integer,
            .boolean = text_boolean,
            .null = text_null,
@@ -124,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;
+}