summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLloyd Hilaiel <lloyd@hilaiel.com>2014-03-14 12:48:33 +0200
committerLloyd Hilaiel <lloyd@hilaiel.com>2014-03-14 12:48:33 +0200
commit263adf537abb02300738bb96e551f7002a8582df (patch)
tree60ce402697c9dbc8d85bdce6c511dbcc28da784e /src
parentb8f7bccab85681ad394031c29fcfd88cc43d20c9 (diff)
downloadyajl-263adf537abb02300738bb96e551f7002a8582df.tar.gz
add generator reset, and ability to verify and reformat streams
Diffstat (limited to 'src')
-rw-r--r--src/api/yajl_gen.h8
-rw-r--r--src/yajl_gen.c8
2 files changed, 16 insertions, 0 deletions
diff --git a/src/api/yajl_gen.h b/src/api/yajl_gen.h
index 4962e06..ddd1527 100644
--- a/src/api/yajl_gen.h
+++ b/src/api/yajl_gen.h
@@ -150,6 +150,14 @@ extern "C" {
* intended to enable incremental JSON outputing. */
YAJL_API void yajl_gen_clear(yajl_gen hand);
+ /** Reset the generator state. Allows a client to generate multiple
+ * json entities in a stream. The "sep" string will be inserted to
+ * separate the previously generated entity from the current,
+ * NULL means *no separation* of entites (clients beware, generating
+ * multiple JSON numbers, for instance, will result in inscrutable
+ * output) */
+ YAJL_API void yajl_gen_reset(yajl_gen hand, const char * sep);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/yajl_gen.c b/src/yajl_gen.c
index eccfa42..0f5c68e 100644
--- a/src/yajl_gen.c
+++ b/src/yajl_gen.c
@@ -126,6 +126,14 @@ yajl_gen_alloc(const yajl_alloc_funcs * afs)
}
void
+yajl_gen_reset(yajl_gen g, const char * sep)
+{
+ g->depth = 0;
+ memset((void *) &(g->state), 0, sizeof(g->state));
+ if (sep != NULL) g->print(g->ctx, sep, strlen(sep));
+}
+
+void
yajl_gen_free(yajl_gen g)
{
if (g->print == (yajl_print_t)&yajl_buf_append) yajl_buf_free((yajl_buf)g->ctx);