aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pelletier/go-toml/tomltree_conversions.go')
-rw-r--r--vendor/github.com/pelletier/go-toml/tomltree_conversions.go45
1 files changed, 27 insertions, 18 deletions
diff --git a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
index bf9321b..db3da0d 100644
--- a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
+++ b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
@@ -79,11 +79,11 @@ func toTomlValue(item interface{}, indent int) string {
case time.Time:
return tab + value.Format(time.RFC3339)
case []interface{}:
- result := tab + "[\n"
+ values := []string{}
for _, item := range value {
- result += toTomlValue(item, indent+2) + ",\n"
+ values = append(values, toTomlValue(item, 0))
}
- return result + tab + "]"
+ return "[" + strings.Join(values, ",") + "]"
case nil:
return ""
default:
@@ -92,57 +92,66 @@ func toTomlValue(item interface{}, indent int) string {
}
// Recursive support function for ToString()
-// Outputs a tree, using the provided keyspace to prefix group names
+// Outputs a tree, using the provided keyspace to prefix table names
func (t *TomlTree) toToml(indent, keyspace string) string {
- result := ""
+ resultChunks := []string{}
for k, v := range t.values {
// figure out the keyspace
combinedKey := k
if keyspace != "" {
combinedKey = keyspace + "." + combinedKey
}
+ resultChunk := ""
// output based on type
switch node := v.(type) {
case []*TomlTree:
for _, item := range node {
if len(item.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[[%s]]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[[%s]]\n", indent, combinedKey)
}
- result += item.toToml(indent+" ", combinedKey)
+ resultChunk += item.toToml(indent+" ", combinedKey)
}
+ resultChunks = append(resultChunks, resultChunk)
case *TomlTree:
if len(node.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += node.toToml(indent+" ", combinedKey)
+ resultChunk += node.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case map[string]interface{}:
sub := TreeFromMap(node)
if len(sub.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += sub.toToml(indent+" ", combinedKey)
+ resultChunk += sub.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case map[string]string:
sub := TreeFromMap(convertMapStringString(node))
if len(sub.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += sub.toToml(indent+" ", combinedKey)
+ resultChunk += sub.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case map[interface{}]interface{}:
sub := TreeFromMap(convertMapInterfaceInterface(node))
if len(sub.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += sub.toToml(indent+" ", combinedKey)
+ resultChunk += sub.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case *tomlValue:
- result += fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(node.value, 0))
+ resultChunk = fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(node.value, 0))
+ resultChunks = append([]string{resultChunk}, resultChunks...)
default:
- result += fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(v, 0))
+ resultChunk = fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(v, 0))
+ resultChunks = append([]string{resultChunk}, resultChunks...)
}
+
}
- return result
+ return strings.Join(resultChunks, "")
}
func convertMapStringString(in map[string]string) map[string]interface{} {