2022-03-29 16:13:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func stringify(v interface{}) string {
|
|
|
|
switch v.(type) {
|
|
|
|
case nil:
|
|
|
|
return "null"
|
|
|
|
|
|
|
|
case bool:
|
|
|
|
if v.(bool) {
|
|
|
|
return "true"
|
|
|
|
} else {
|
|
|
|
return "false"
|
|
|
|
}
|
|
|
|
|
|
|
|
case number:
|
|
|
|
return v.(number).String()
|
|
|
|
|
|
|
|
case string:
|
|
|
|
return fmt.Sprintf("%q", v)
|
|
|
|
|
|
|
|
case *dict:
|
|
|
|
result := "{"
|
|
|
|
for i, key := range v.(*dict).keys {
|
|
|
|
line := fmt.Sprintf("%q", key) + ": " + stringify(v.(*dict).values[key])
|
|
|
|
if i < len(v.(*dict).keys)-1 {
|
2022-04-14 12:30:36 +00:00
|
|
|
line += ","
|
2022-03-29 16:13:41 +00:00
|
|
|
}
|
|
|
|
result += line
|
|
|
|
}
|
|
|
|
return result + "}"
|
|
|
|
|
|
|
|
case array:
|
|
|
|
result := "["
|
|
|
|
for i, value := range v.(array) {
|
|
|
|
line := stringify(value)
|
|
|
|
if i < len(v.(array))-1 {
|
2022-04-14 12:30:36 +00:00
|
|
|
line += ","
|
2022-03-29 16:13:41 +00:00
|
|
|
}
|
|
|
|
result += line
|
|
|
|
}
|
|
|
|
return result + "]"
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "unknown type"
|
|
|
|
}
|
|
|
|
}
|