summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-29 08:33:41 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-29 08:33:41 -0700
commit12800700f93639c259757f0f9def1546d215ee95 (patch)
tree8d1c58396447148dec418f3dc9c5819083404d4a /lib.c
parentb3a49b161a6192d4b8c574f0cd7f9b16567cd834 (diff)
downloadtxr-12800700f93639c259757f0f9def1546d215ee95.tar.gz
txr-12800700f93639c259757f0f9def1546d215ee95.tar.bz2
txr-12800700f93639c259757f0f9def1546d215ee95.zip
json: tojson must not add #J prefix.
* lib.c (out_json_rec): In the CONS case, if ctx is null bail and report and invalid object. This lets us call the function with a null context. (tojson): Do not support (json ...) syntax. Instead of obj_print, pass the object directly to out_json_rec. * txr.1: Do not mention handling json macro syntax. Common leading text factored out of bulleted paragraphs section.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/lib.c b/lib.c
index aafc933a..1d2c65b7 100644
--- a/lib.c
+++ b/lib.c
@@ -12644,7 +12644,7 @@ static void out_json_rec(val obj, val out, struct strm_ctx *ctx)
}
break;
case CONS:
- {
+ if (ctx != 0) {
val sym = car(obj);
if (sym == hash_lit_s) {
val save_indent;
@@ -13461,23 +13461,11 @@ val tostringp(val obj)
val tojson(val obj, val flat)
{
- if (consp(obj) && eq(car(obj), json_s)) {
- val ss = make_string_output_stream();
- if (default_null_arg(flat))
- set_indent_mode(ss, num_fast(indent_foff));
- obj_print(obj, ss, nil);
- return get_string_from_stream(ss);
- } else {
- val json = cons(json_s, cons(quote_s, cons(obj, nil)));
- val ss = make_string_output_stream();
- if (default_null_arg(flat))
- set_indent_mode(ss, num_fast(indent_foff));
- obj_print(json, ss, nil);
- rcyc_pop(&json);
- rcyc_pop(&json);
- rcyc_pop(&json);
- return get_string_from_stream(ss);
- }
+ 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);
+ return get_string_from_stream(ss);
}
val display_width(val obj)