in builder.go [289:327]
func parsePossibleLengthStringToSet(possibleLengthString string) map[int32]bool {
if possibleLengthString == "" {
panic("Empty possibleLength string found.")
}
lengths := strings.Split(possibleLengthString, ",")
lengthSet := make(map[int32]bool)
for i := 0; i < len(lengths); i++ {
lengthSubstring := lengths[i]
if lengthSubstring == "" {
panic("Leading, trailing or adjacent commas in possible length string %s, these should only separate numbers or ranges.")
} else if lengthSubstring[0] == '[' {
if lengthSubstring[len(lengthSubstring)-1] != ']' {
panic(fmt.Sprintf("Missing end of range character in possible length string %s.", possibleLengthString))
}
// Strip the leading and trailing [], and split on the -.
minMax := strings.Split(lengthSubstring[1:len(lengthSubstring)-1], "-")
if len(minMax) != 2 {
panic(fmt.Sprintf("Ranges must have exactly one - character: missing for %s.", possibleLengthString))
}
min, _ := strconv.Atoi(minMax[0])
max, _ := strconv.Atoi(minMax[1])
// We don't even accept [6-7] since we prefer the shorter 6,7 variant; for a range to be in
// use the hyphen needs to replace at least one digit.
if max-min < 2 {
panic(fmt.Sprintf("The first number in a range should be two or more digits lower than the second. Culprit possibleLength string: %s", possibleLengthString))
}
for j := min; j <= max; j++ {
lengthSet[int32(j)] = true
}
} else {
length, _ := strconv.Atoi(lengthSubstring)
lengthSet[int32(length)] = true
}
}
return lengthSet
}