From baf7141d1dd0f99d561a2197a909c66dd389809d Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Sat, 8 Oct 2016 16:02:50 -0500 Subject: Update dependencies --- .../pelletier/go-toml/tomltree_conversions.go | 54 +++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'vendor/github.com/pelletier/go-toml/tomltree_conversions.go') diff --git a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go index c9c6f95..bf9321b 100644 --- a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go +++ b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go @@ -45,8 +45,28 @@ func encodeTomlString(value string) string { func toTomlValue(item interface{}, indent int) string { tab := strings.Repeat(" ", indent) switch value := item.(type) { + case int: + return tab + strconv.FormatInt(int64(value), 10) + case int8: + return tab + strconv.FormatInt(int64(value), 10) + case int16: + return tab + strconv.FormatInt(int64(value), 10) + case int32: + return tab + strconv.FormatInt(int64(value), 10) case int64: return tab + strconv.FormatInt(value, 10) + case uint: + return tab + strconv.FormatUint(uint64(value), 10) + case uint8: + return tab + strconv.FormatUint(uint64(value), 10) + case uint16: + return tab + strconv.FormatUint(uint64(value), 10) + case uint32: + return tab + strconv.FormatUint(uint64(value), 10) + case uint64: + return tab + strconv.FormatUint(value, 10) + case float32: + return tab + strconv.FormatFloat(float64(value), 'f', -1, 32) case float64: return tab + strconv.FormatFloat(value, 'f', -1, 64) case string: @@ -64,8 +84,10 @@ func toTomlValue(item interface{}, indent int) string { result += toTomlValue(item, indent+2) + ",\n" } return result + tab + "]" + case nil: + return "" default: - panic(fmt.Sprintf("unsupported value type: %v", value)) + panic(fmt.Sprintf("unsupported value type %T: %v", value, value)) } } @@ -96,6 +118,20 @@ func (t *TomlTree) toToml(indent, keyspace string) string { case map[string]interface{}: sub := TreeFromMap(node) + if len(sub.Keys()) > 0 { + result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey) + } + result += sub.toToml(indent+" ", combinedKey) + case map[string]string: + sub := TreeFromMap(convertMapStringString(node)) + + if len(sub.Keys()) > 0 { + result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey) + } + result += sub.toToml(indent+" ", combinedKey) + case map[interface{}]interface{}: + sub := TreeFromMap(convertMapInterfaceInterface(node)) + if len(sub.Keys()) > 0 { result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey) } @@ -109,6 +145,22 @@ func (t *TomlTree) toToml(indent, keyspace string) string { return result } +func convertMapStringString(in map[string]string) map[string]interface{} { + result := make(map[string]interface{}, len(in)) + for k, v := range in { + result[k] = v + } + return result +} + +func convertMapInterfaceInterface(in map[interface{}]interface{}) map[string]interface{} { + result := make(map[string]interface{}, len(in)) + for k, v := range in { + result[k.(string)] = v + } + return result +} + // ToString is an alias for String func (t *TomlTree) ToString() string { return t.String() -- cgit v1.2.3