set type [lindex $thing 0]
set indent 2
set indentIncr 2
+ set nl "\n"
if {[llength $args] > 0} {
set indent [lindex $args 0]
} 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]
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} {