From df76a61d3b05b3b84eee8e612ceb71c702c32d16 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 21 Jan 2018 17:58:24 +0000 Subject: [PATCH] changed the need_comma function to take into account the xli->opt.cbs.pair_writable callback function --- qse/lib/xli/write-json.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qse/lib/xli/write-json.c b/qse/lib/xli/write-json.c index 8ae3232e..595255e5 100644 --- a/qse/lib/xli/write-json.c +++ b/qse/lib/xli/write-json.c @@ -83,12 +83,16 @@ static int write_indentation (qse_xli_t* xli, int depth) return 0; } -static int need_comma (qse_xli_atom_t* start) +static int need_comma (qse_xli_t* xli, qse_xli_atom_t* start) { qse_xli_atom_t* cur; for (cur = start; cur; cur = cur->next) { - if (cur->type == QSE_XLI_PAIR) return 1; + if (cur->type == QSE_XLI_PAIR) + { + if (xli->opt.cbs.pair_writable && !xli->opt.cbs.pair_writable(xli, (qse_xli_pair_t*)cur)) continue; + return 1; + } if (cur->type == QSE_XLI_EOF) return 0; /* if EOF encountered in the included file, i don't want a comma at the end of the file */ } return 0; @@ -189,7 +193,7 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth) } } - if (need_comma(curatom->next) && write_to_current_stream(xli, QSE_T(","), 1, 0) <= -1) return -1; + if (need_comma(xli, curatom->next) && write_to_current_stream(xli, QSE_T(","), 1, 0) <= -1) return -1; if (write_to_current_stream(xli, QSE_T("\n"), 1, 0) <= -1) return -1; break; } @@ -228,7 +232,7 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth) case QSE_XLI_EOF: if (qse_xli_closeactivewstream(xli, &depth) <= -1) return -1; - if (need_comma(curatom->next) && write_to_current_stream(xli, QSE_T(","), 1, 0) <= -1) return -1; + if (need_comma(xli, curatom->next) && write_to_current_stream(xli, QSE_T(","), 1, 0) <= -1) return -1; if (write_to_current_stream(xli, QSE_T("\n"), 1, 0) <= -1) return -1; break; }