From: Matt S Trout Date: Sun, 17 Jun 2012 23:27:31 +0000 (+0100) Subject: fix indentation code to honour deep indents X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c2a818a97f199ca851c435f563640a5b298060ac;p=scpubgit%2FTenDotTcl.git fix indentation code to honour deep indents --- diff --git a/tcvJSON.tcl b/tcvJSON.tcl index a0edff4..7b6d382 100755 --- a/tcvJSON.tcl +++ b/tcvJSON.tcl @@ -194,6 +194,11 @@ proc tcvJSON::unparse {thing args} { if {[llength $args] > 0} { set indent [lindex $args 0] + if {[llength $args] > 1} { + set indentIncr [lindex $args 1] + } else { + set indentIncr $indent + } } switch -- $type { @@ -201,7 +206,7 @@ proc tcvJSON::unparse {thing args} { append output "\[\n[string repeat " " $indent]" set tmp {} foreach element [lrange $thing 1 end] { - lappend tmp [unparse $element [expr {$indent + $indentIncr}]] + lappend tmp [unparse $element [expr {$indent + $indentIncr}] $indentIncr] } append output [join $tmp ",\n[string repeat " " $indent]"] append output "\n[string repeat " " [expr {$indent - $indentIncr}]]\]" @@ -213,7 +218,7 @@ proc tcvJSON::unparse {thing args} { for {set i 1} {$i < [llength $thing]} {incr i} { set key [lindex $thing $i] set value [lindex $thing [incr i]] - lappend tmp "\"$key\": [unparse $value [expr {$indent + $indentIncr}]]" + 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}]]\}"