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.
This commit is contained in:
parent
497010ce42
commit
85d8fba3bd
|
@ -2,7 +2,6 @@ package flatmap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -44,16 +43,28 @@ func expandArray(m map[string]string, prefix string) []interface{} {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keySet := make(map[int]struct{})
|
keySet := map[int]bool{}
|
||||||
listElementKey := regexp.MustCompile("^" + prefix + "\\.([0-9]+)(?:\\..*)?$")
|
for k := range m {
|
||||||
for key := range m {
|
if !strings.HasPrefix(k, prefix+".") {
|
||||||
if matches := listElementKey.FindStringSubmatch(key); matches != nil {
|
continue
|
||||||
k, err := strconv.ParseInt(matches[1], 0, 0)
|
}
|
||||||
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
keySet[int(k)] = struct{}{}
|
keySet[int(k)] = true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keysList := make([]int, 0, num)
|
keysList := make([]int, 0, num)
|
||||||
|
|
Loading…
Reference in New Issue