From eb4537241406f3f333c0da7a2975e040c8fb807c Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Tue, 31 Dec 2013 23:25:20 -0600 Subject: [PATCH] jv_show() should be able to display invalid values --- jv.h | 2 +- jv_print.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jv.h b/jv.h index b8087adb..7323c32c 100644 --- a/jv.h +++ b/jv.h @@ -126,7 +126,7 @@ jv jv_object_iter_value(jv, int); int jv_get_refcnt(jv); -enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8 }; +enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8, JV_PRINT_INVALID = 16 }; void jv_dumpf(jv, FILE *f, int flags); void jv_dump(jv, int flags); void jv_show(jv, int flags); diff --git a/jv_print.c b/jv_print.c index 1d38de8b..f01d6a16 100644 --- a/jv_print.c +++ b/jv_print.c @@ -127,7 +127,18 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI switch (jv_get_kind(x)) { default: case JV_KIND_INVALID: - assert(0 && "Invalid value"); + if (flags & JV_PRINT_INVALID) { + jv msg = jv_invalid_get_msg(jv_copy(x)); + if (jv_get_kind(msg) == JV_KIND_STRING) { + put_str("", F, S); + } else { + put_str("", F, S); + } + } else { + assert(0 && "Invalid value"); + } break; case JV_KIND_NULL: put_str("null", F, S); @@ -271,10 +282,11 @@ void jv_dump(jv x, int flags) { jv_dumpf(x, stdout, flags); } +/* This one is nice for use in debuggers */ void jv_show(jv x, int flags) { if (flags == -1) flags = JV_PRINT_PRETTY | JV_PRINT_COLOUR; - jv_dumpf(jv_copy(x), stderr, flags); + jv_dumpf(jv_copy(x), stderr, flags | JV_PRINT_INVALID); fflush(stderr); }