aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/pelletier/go-toml
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pelletier/go-toml')
-rw-r--r--vendor/github.com/pelletier/go-toml/keysparsing.go16
-rw-r--r--vendor/github.com/pelletier/go-toml/toml.go3
-rw-r--r--vendor/github.com/pelletier/go-toml/tomltree_conversions.go54
3 files changed, 67 insertions, 6 deletions
diff --git a/vendor/github.com/pelletier/go-toml/keysparsing.go b/vendor/github.com/pelletier/go-toml/keysparsing.go
index 4deed81..b67664f 100644
--- a/vendor/github.com/pelletier/go-toml/keysparsing.go
+++ b/vendor/github.com/pelletier/go-toml/keysparsing.go
@@ -12,6 +12,7 @@ func parseKey(key string) ([]string, error) {
groups := []string{}
var buffer bytes.Buffer
inQuotes := false
+ wasInQuotes := false
escapeNext := false
ignoreSpace := true
expectDot := false
@@ -33,16 +34,27 @@ func parseKey(key string) ([]string, error) {
escapeNext = true
continue
case '"':
+ if inQuotes {
+ groups = append(groups, buffer.String())
+ buffer.Reset()
+ wasInQuotes = true
+ }
inQuotes = !inQuotes
expectDot = false
case '.':
if inQuotes {
buffer.WriteRune(char)
} else {
- groups = append(groups, buffer.String())
- buffer.Reset()
+ if !wasInQuotes {
+ if buffer.Len() == 0 {
+ return nil, fmt.Errorf("empty key group")
+ }
+ groups = append(groups, buffer.String())
+ buffer.Reset()
+ }
ignoreSpace = true
expectDot = false
+ wasInQuotes = false
}
case ' ':
if inQuotes {
diff --git a/vendor/github.com/pelletier/go-toml/toml.go b/vendor/github.com/pelletier/go-toml/toml.go
index c0e1ad2..ad23fe8 100644
--- a/vendor/github.com/pelletier/go-toml/toml.go
+++ b/vendor/github.com/pelletier/go-toml/toml.go
@@ -222,9 +222,6 @@ func (t *TomlTree) SetPath(keys []string, value interface{}) {
func (t *TomlTree) createSubTree(keys []string, pos Position) error {
subtree := t
for _, intermediateKey := range keys {
- if intermediateKey == "" {
- return fmt.Errorf("empty intermediate table")
- }
nextTree, exists := subtree.values[intermediateKey]
if !exists {
tree := newTomlTree()
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))
}
}
@@ -100,6 +122,20 @@ func (t *TomlTree) toToml(indent, keyspace string) string {
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)
+ }
+ result += sub.toToml(indent+" ", combinedKey)
case *tomlValue:
result += fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(node.value, 0))
default:
@@ -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()