Skip to content

Commit

Permalink
Quote numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Apr 18, 2014
1 parent f2c521f commit ee0ecb3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"strings"
)

var re = regexp.MustCompile("^([^0-9\\s\\[][^\\s\\[]*)?(\\[[0-9]+\\])?$")
var re1 = regexp.MustCompile("^([^0-9\\s\\[][^\\s\\[]*|\"[^\"]+\")?(\\[[0-9]+\\])?$")
var re2 = regexp.MustCompile("^\"[^\"]+\"$")

var t1 = reflect.TypeOf((map[string]interface{})(nil))
var t2 = reflect.TypeOf((map[interface{}]interface{})(nil))
Expand Down Expand Up @@ -74,12 +75,15 @@ func ScanTree(v interface{}, p string, t interface{}) (err error) {
}
var ok bool
for _, token := range strings.Split(p, "/") {
sl := re.FindAllStringSubmatch(token, -1)
sl := re1.FindAllStringSubmatch(token, -1)
if len(sl) == 0 {
return errors.New("invalid path")
}
ss := sl[0]
if ss[1] != "" {
if re2.MatchString(ss[1]) {
ss[1] = ss[1][1:len(ss[1])-1]
}
rv := reflect.ValueOf(v)
rt := rv.Type()
if rt != t1 && rv.Type().ConvertibleTo(t1) {
Expand Down

0 comments on commit ee0ecb3

Please sign in to comment.