X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=tcvJSON.tcl;h=f0e781adac84484e9470c6a2db4352948dfce8db;hb=15e006dc2024516bb80569d6b97c3b895eb9b46a;hp=7b6d38220e5a31b05ccf960bb87dca5a7946b706;hpb=c2a818a97f199ca851c435f563640a5b298060ac;p=scpubgit%2FTenDotTcl.git diff --git a/tcvJSON.tcl b/tcvJSON.tcl index 7b6d382..f0e781a 100755 --- a/tcvJSON.tcl +++ b/tcvJSON.tcl @@ -191,6 +191,7 @@ proc tcvJSON::unparse {thing args} { set type [lindex $thing 0] set indent 2 set indentIncr 2 + set nl "\n" if {[llength $args] > 0} { set indent [lindex $args 0] @@ -199,21 +200,22 @@ proc tcvJSON::unparse {thing args} { } else { set indentIncr $indent } + if {$indent == 0} { set nl "" } } switch -- $type { {list} { - append output "\[\n[string repeat " " $indent]" + append output "\[$nl[string repeat " " $indent]" set tmp {} foreach element [lrange $thing 1 end] { lappend tmp [unparse $element [expr {$indent + $indentIncr}] $indentIncr] } - append output [join $tmp ",\n[string repeat " " $indent]"] - append output "\n[string repeat " " [expr {$indent - $indentIncr}]]\]" + append output [join $tmp ",$nl[string repeat " " $indent]"] + append output "$nl[string repeat " " [expr {$indent - $indentIncr}]]\]" } {obj} { - append output "\{\n[string repeat " " $indent]" + append output "\{$nl[string repeat " " $indent]" set tmp {} for {set i 1} {$i < [llength $thing]} {incr i} { set key [lindex $thing $i] @@ -221,7 +223,7 @@ proc tcvJSON::unparse {thing args} { lappend tmp "\"$key\": [unparse $value [expr {$indent + $indentIncr}] $indentIncr]" } append output [join $tmp ",\n[string repeat " " $indent]"] - append output "\n[string repeat " " [expr {$indent - $indentIncr}]]\}" + append output "$nl[string repeat " " [expr {$indent - $indentIncr}]]\}" } {str} {