Minor fixups to expandArray

Find the index keys by comparing the strings directly, so we don't need
to worry about the prefix value altering the regex.
pull/11042/head
James Bardin 10 years ago
parent 497010ce42
commit 85d8fba3bd

@ -2,7 +2,6 @@ package flatmap
import (
"fmt"
"regexp"
"sort"
"strconv"
"strings"
@ -44,16 +43,28 @@ func expandArray(m map[string]string, prefix string) []interface{} {
panic(err)
}
keySet := make(map[int]struct{})
listElementKey := regexp.MustCompile("^" + prefix + "\\.([0-9]+)(?:\\..*)?$")
for key := range m {
if matches := listElementKey.FindStringSubmatch(key); matches != nil {
k, err := strconv.ParseInt(matches[1], 0, 0)
if err != nil {
panic(err)
}
keySet[int(k)] = struct{}{}
keySet := map[int]bool{}
for k := range m {
if !strings.HasPrefix(k, prefix+".") {
continue
}
key := k[len(prefix)+1:]
idx := strings.Index(key, ".")
if idx != -1 {
key = key[:idx]
}
// skip the count value
if key == "#" {
continue
}
k, err := strconv.Atoi(key)
if err != nil {
panic(err)
}
keySet[int(k)] = true
}
keysList := make([]int, 0, num)

Loading…
Cancel
Save