--- json-stream-printer.sml.orig 2020-04-08 19:00:10.000000000 +0200 +++ json-stream-printer.sml 2020-07-03 15:23:14.218708000 +0200 @@ -70,7 +70,7 @@ then TextIO.output(strm, String.extract(tenSpaces, 10-n, NONE)) else (TextIO.output(strm, tenSpaces); prIndent(n-10)) in - prIndent ((!indent+offset) * 2) + prIndent (!indent+offset) end fun incIndent (P{indent, ...}, n) = indent := !indent + n; @@ -108,14 +108,14 @@ fun tr (i, chrs) = (case getWChar i of SOME(wchr, i) => if (wchr <= 0w126) then (case UTF8.toAscii wchr - of #"\"" => "\\\"" - | #"\\" => "\\\\" - | #"/" => "\\/" - | #"\b" => "\\b" - | #"\f" => "\\f" - | #"\n" => "\\n" - | #"\r" => "\\r" - | #"\t" => "\\t" + of #"\"" => tr(i, "\\\"" :: chrs) + | #"\\" => tr(i, "\\\\" :: chrs) + | #"/" => tr(i, "\\/" :: chrs) + | #"\b" => tr(i, "\\b" :: chrs) + | #"\f" => tr(i, "\\f" :: chrs) + | #"\n" => tr(i, "\\n" :: chrs) + | #"\r" => tr(i, "\\r" :: chrs) + | #"\t" => tr(i, "\\t" :: chrs) | c => if (wchr < 0w32) then tr(i, F.format "\\u%04x" [F.WORD wchr] :: chrs) else tr(i, str c :: chrs) @@ -131,7 +131,7 @@ of CLOSED => raise Fail "closed printer" | _ => ( optComma p; - pr (p, "{"); incIndent(p, 2); nl p; + pr (p, "{"); incIndent(p, 1); nl p; ctx := FIRST(OBJECT(!ctx))) (* end case *)) @@ -148,7 +148,7 @@ fun endObject (p as P{ctx, ...}) = let fun prEnd ctx' = ( ctx := ctx'; - indent(p, ~1); pr(p, "}"); decIndent (p, 2)) + decIndent (p, 1); indent(p, 0); pr(p, "}")) in case !ctx of CLOSED => raise Fail "closed printer" @@ -163,14 +163,14 @@ of CLOSED => raise Fail "closed printer" | _ => ( optComma p; - pr (p, "["); incIndent(p, 2); nl p; + pr (p, "["); incIndent(p, 1); nl p; ctx := FIRST(ARRAY(!ctx))) (* end case *)) fun endArray (p as P{ctx, ...}) = let fun prEnd ctx' = ( ctx := ctx'; - indent(p, ~1); pr(p, "]"); decIndent (p, 2)) + decIndent (p, 1); indent(p, 0); pr(p, "]")) in case !ctx of CLOSED => raise Fail "closed printer"