in phonenumbers.go [1400:1463]
func FormatOutOfCountryCallingNumber(
number *PhoneNumber,
regionCallingFrom string) string {
if !isValidRegionCode(regionCallingFrom) {
return Format(number, INTERNATIONAL)
}
countryCallingCode := int(number.GetCountryCode())
nationalSignificantNumber := GetNationalSignificantNumber(number)
if !hasValidCountryCallingCode(countryCallingCode) {
return nationalSignificantNumber
}
if countryCallingCode == NANPA_COUNTRY_CODE {
if IsNANPACountry(regionCallingFrom) {
// For NANPA regions, return the national format for these
// regions but prefix it with the country calling code.
return strconv.Itoa(countryCallingCode) + " " + Format(number, NATIONAL)
}
} else if countryCallingCode == getCountryCodeForValidRegion(regionCallingFrom) {
// If regions share a country calling code, the country calling
// code need not be dialled. This also applies when dialling
// within a region, so this if clause covers both these cases.
// Technically this is the case for dialling from La Reunion to
// other overseas departments of France (French Guiana, Martinique,
// Guadeloupe), but not vice versa - so we don't cover this edge
// case for now and for those cases return the version including
// country calling code.
// Details here: http://www.petitfute.com/voyage/225-info-pratiques-reunion
return Format(number, NATIONAL)
}
// Metadata cannot be null because we checked 'isValidRegionCode()' above.
metadataForRegionCallingFrom := getMetadataForRegion(regionCallingFrom)
internationalPrefix := metadataForRegionCallingFrom.GetInternationalPrefix()
// For regions that have multiple international prefixes, the
// international format of the number is returned, unless there is
// a preferred international prefix.
internationalPrefixForFormatting := ""
metPref := metadataForRegionCallingFrom.GetPreferredInternationalPrefix()
if UNIQUE_INTERNATIONAL_PREFIX.MatchString(internationalPrefix) {
internationalPrefixForFormatting = internationalPrefix
} else if metPref != "" {
internationalPrefixForFormatting = metPref
}
regionCode := GetRegionCodeForCountryCode(countryCallingCode)
// Metadata cannot be null because the country calling code is valid.
metadataForRegion :=
getMetadataForRegionOrCallingCode(countryCallingCode, regionCode)
formattedNationalNumber :=
formatNsn(
nationalSignificantNumber, metadataForRegion, INTERNATIONAL)
formattedNumber := NewBuilder([]byte(formattedNationalNumber))
maybeAppendFormattedExtension(number, metadataForRegion, INTERNATIONAL,
formattedNumber)
if len(internationalPrefixForFormatting) > 0 {
formattedNumber.InsertString(0, internationalPrefixForFormatting+" "+
strconv.Itoa(countryCallingCode)+" ")
} else {
prefixNumberWithCountryCallingCode(
countryCallingCode, INTERNATIONAL, formattedNumber)
}
return formattedNumber.String()
}