diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-31 23:48:31 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-31 23:48:31 -0700 |
commit | 9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0 (patch) | |
tree | 5dd966f97b24e689e01c7301f378823eef73c008 /lib.c | |
parent | f311b6ca089954675e745ad9212209ca8cf23be2 (diff) | |
download | txr-9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0.tar.gz txr-9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0.tar.bz2 txr-9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0.zip |
json: turn on indentation.
* lib.c (put_json): Turn on indentation if the flat argument
doesn't suppress it, and the stream is not in forced-off
indentation mode.
(tojson): Retarget to put_json, so we don't have to
repeat this logic.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -13473,15 +13473,12 @@ val tostringp(val obj) val put_json(val obj, val stream_in, val flat) { val stream = default_arg(stream_in, std_output); - - if (default_null_arg(flat)) { - out_json_rec(obj, stream, 0); - } else { - val imode = set_indent_mode(stream, num_fast(indent_foff)); - out_json_rec(obj, stream, 0); - set_indent_mode(stream, imode); - } - + val imode = if3(default_null_arg(flat), + set_indent_mode(stream, num_fast(indent_foff)), + test_set_indent_mode(stream, num_fast(indent_off), + num_fast(indent_data))); + out_json_rec(obj, stream, 0); + set_indent_mode(stream, imode); return t; } @@ -13495,9 +13492,7 @@ val put_jsonl(val obj, val stream, val flat) val tojson(val obj, val flat) { val ss = make_string_output_stream(); - if (default_null_arg(flat)) - set_indent_mode(ss, num_fast(indent_foff)); - out_json_rec(obj, ss, 0); + put_json(obj, ss, flat); return get_string_from_stream(ss); } |