diff options
author | Elad <theman@elad.im> | 2018-06-05 18:40:21 +0800 |
---|---|---|
committer | Balint Gabor <balint.g@gmail.com> | 2018-06-05 18:40:21 +0800 |
commit | 5bee5d69d743e2c91e8aa0f322e4de3834bb6664 (patch) | |
tree | 7157caf164b1882ed04eabc492f311a663a3fb0f /vendor/github.com/naoina/toml/parse.go | |
parent | cbfb40b0aab093e1b612f3b16834894b2cc67882 (diff) | |
download | go-tangerine-5bee5d69d743e2c91e8aa0f322e4de3834bb6664.tar go-tangerine-5bee5d69d743e2c91e8aa0f322e4de3834bb6664.tar.gz go-tangerine-5bee5d69d743e2c91e8aa0f322e4de3834bb6664.tar.bz2 go-tangerine-5bee5d69d743e2c91e8aa0f322e4de3834bb6664.tar.lz go-tangerine-5bee5d69d743e2c91e8aa0f322e4de3834bb6664.tar.xz go-tangerine-5bee5d69d743e2c91e8aa0f322e4de3834bb6664.tar.zst go-tangerine-5bee5d69d743e2c91e8aa0f322e4de3834bb6664.zip |
vendor: added vendor packages necessary for the swarm-network-rewrite merge (#16792)
* vendor: added vendor packages necessary for the swarm-network-rewrite merge into ethereum master
* vendor: removed multihash deps
Diffstat (limited to 'vendor/github.com/naoina/toml/parse.go')
-rw-r--r-- | vendor/github.com/naoina/toml/parse.go | 52 |
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 -} |