working hostname call
[scpubgit/TenDotTcl.git] / tcvJSON.tcl
index a0edff4..f0e781a 100755 (executable)
@@ -191,32 +191,39 @@ 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]
+        if {[llength $args] > 1} {
+          set indentIncr [lindex $args 1]
+        } 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}]]
+                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]
                 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}]]\}"
+            append output "$nl[string repeat " " [expr {$indent - $indentIncr}]]\}"
         }
 
         {str} {