mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
jv_show() should be able to display invalid values
This commit is contained in:
2
jv.h
2
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);
|
||||
|
16
jv_print.c
16
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("<invalid:", F, S);
|
||||
jvp_dump_string(msg, flags | JV_PRINT_ASCII, F, S);
|
||||
put_str(">", F, S);
|
||||
} else {
|
||||
put_str("<invalid>", 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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user