in builder.go [59:83]
func BuildCountryCodeToRegionMap(metadataCollection *PhoneMetadataCollection) map[int][]string {
countryCodeToRegionCodeMap := make(map[int][]string)
for _, metadata := range metadataCollection.Metadata {
regionCode := metadata.GetId()
countryCode := int(metadata.GetCountryCode())
_, present := countryCodeToRegionCodeMap[countryCode]
if present {
phoneList := countryCodeToRegionCodeMap[countryCode]
if metadata.GetMainCountryForCode() {
phoneList = append([]string{regionCode}, phoneList...)
} else {
phoneList = append(phoneList, regionCode)
}
countryCodeToRegionCodeMap[countryCode] = phoneList
} else {
// For most countries, there will be only one region code for the country calling code.
phoneList := []string{}
if regionCode != "" { // For alternate formats, there are no region codes at all.
phoneList = append(phoneList, regionCode)
}
countryCodeToRegionCodeMap[countryCode] = phoneList
}
}
return countryCodeToRegionCodeMap
}