aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/naoina/toml/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/naoina/toml/parse.go')
-rw-r--r--vendor/github.com/naoina/toml/parse.go52
1 files changed, 19 insertions, 33 deletions
diff --git a/vendor/github.com/naoina/toml/parse.go b/vendor/github.com/naoina/toml/parse.go
index e6f95001e..de9108566 100644
--- a/vendor/github.com/naoina/toml/parse.go
+++ b/vendor/github.com/naoina/toml/parse.go
@@ -97,6 +97,7 @@ type toml struct {
currentTable *ast.Table
s string
key string
+ tableKeys []string
val ast.Value
arr *array
stack []*stack
@@ -180,12 +181,12 @@ func (p *tomlParser) SetArray(begin, end int) {
}
func (p *toml) SetTable(buf []rune, begin, end int) {
- p.setTable(p.table, buf, begin, end)
+ rawName := string(buf[begin:end])
+ p.setTable(p.table, rawName, p.tableKeys)
+ p.tableKeys = nil
}
-func (p *toml) setTable(parent *ast.Table, buf []rune, begin, end int) {
- name := string(buf[begin:end])
- names := splitTableKey(name)
+func (p *toml) setTable(parent *ast.Table, name string, names []string) {
parent, err := p.lookupTable(parent, names[:len(names)-1])
if err != nil {
p.Error(err)
@@ -230,12 +231,12 @@ func (p *tomlParser) SetTableString(begin, end int) {
}
func (p *toml) SetArrayTable(buf []rune, begin, end int) {
- p.setArrayTable(p.table, buf, begin, end)
+ rawName := string(buf[begin:end])
+ p.setArrayTable(p.table, rawName, p.tableKeys)
+ p.tableKeys = nil
}
-func (p *toml) setArrayTable(parent *ast.Table, buf []rune, begin, end int) {
- name := string(buf[begin:end])
- names := splitTableKey(name)
+func (p *toml) setArrayTable(parent *ast.Table, name string, names []string) {
parent, err := p.lookupTable(parent, names[:len(names)-1])
if err != nil {
p.Error(err)
@@ -260,11 +261,11 @@ func (p *toml) setArrayTable(parent *ast.Table, buf []rune, begin, end int) {
func (p *toml) StartInlineTable() {
p.skip = false
p.stack = append(p.stack, &stack{p.key, p.currentTable})
- buf := []rune(p.key)
+ names := []string{p.key}
if p.arr == nil {
- p.setTable(p.currentTable, buf, 0, len(buf))
+ p.setTable(p.currentTable, names[0], names)
} else {
- p.setArrayTable(p.currentTable, buf, 0, len(buf))
+ p.setArrayTable(p.currentTable, names[0], names)
}
}
@@ -282,6 +283,13 @@ func (p *toml) AddLineCount(i int) {
func (p *toml) SetKey(buf []rune, begin, end int) {
p.key = string(buf[begin:end])
+ if len(p.key) > 0 && p.key[0] == '"' {
+ p.key = p.unquote(p.key)
+ }
+}
+
+func (p *toml) AddTableKey() {
+ p.tableKeys = append(p.tableKeys, p.key)
}
func (p *toml) AddKeyValue() {
@@ -352,25 +360,3 @@ func (p *toml) lookupTable(t *ast.Table, keys []string) (*ast.Table, error) {
}
return t, nil
}
-
-func splitTableKey(tk string) []string {
- key := make([]byte, 0, 1)
- keys := make([]string, 0, 1)
- inQuote := false
- for i := 0; i < len(tk); i++ {
- k := tk[i]
- switch {
- case k == tableSeparator && !inQuote:
- keys = append(keys, string(key))
- key = key[:0] // reuse buffer.
- case k == '"':
- inQuote = !inQuote
- case (k == ' ' || k == '\t') && !inQuote:
- // skip.
- default:
- key = append(key, k)
- }
- }
- keys = append(keys, string(key))
- return keys
-}