func populatePossibleLengthSets()

in builder.go [338:382]


func populatePossibleLengthSets(data []*PhoneNumberDescE, lengths map[int32]bool, localOnlyLengths map[int32]bool) {
	for i := 0; i < len(data); i++ {
		desc := data[i]
		if desc == nil || desc.PossibleLengths == nil {
			continue
		}

		element := desc.PossibleLengths
		nationalLengths := element.National

		// We don't add to the phone metadata yet, since we want to sort length elements found under
		// different nodes first, make sure there are no duplicates between them and that the
		// localOnly lengths don't overlap with the others.
		thisElementLengths := parsePossibleLengthStringToSet(nationalLengths)
		if element.LocalOnly != "" {
			thisElementLocalOnlyLengths := parsePossibleLengthStringToSet(element.LocalOnly)

			// intersect our two maps
			intersection := make(map[int32]bool)
			for k := range thisElementLengths {
				if thisElementLocalOnlyLengths[k] {
					intersection[k] = true
				}
			}

			if len(intersection) != 0 {
				panic(fmt.Sprintf("Possible length(s) found specified as a normal and local-only length: %v", intersection))
			}

			// We check again when we set these lengths on the metadata itself in setPossibleLengths
			// that the elements in localOnly are not also in lengths. For e.g. the generalDesc, it
			// might have a local-only length for one type that is a normal length for another type. We
			// don't consider this an error, but we do want to remove the local-only lengths.
			for k := range thisElementLocalOnlyLengths {
				localOnlyLengths[k] = true
			}
		}
		// It is okay if at this time we have duplicates, because the same length might be possible
		// for e.g. fixed-line and for mobile numbers, and this method operates potentially on
		// multiple phoneNumberDesc XML elements.
		for k := range thisElementLengths {
			lengths[k] = true
		}
	}
}