func loadAvailableFormats()

in builder.go [213:259]


func loadAvailableFormats(metadata *PhoneMetadata, element *TerritoryE, nationalPrefix string,
	nationalPrefixFormattingRule string, nationalPrefixOptionalWhenFormatting bool) {
	carrierCodeFormattingRule := ""
	if element.CarrierCodeFormattingRule != "" {
		carrierCodeFormattingRule = validateRE(getDomesticCarrierCodeFormattingRule(element.CarrierCodeFormattingRule, nationalPrefix), false)
	}
	numberFormatElements := element.AvailableFormats
	hasExplicitIntlFormatDefined := false

	if len(numberFormatElements) > 0 {
		for i := 0; i < len(numberFormatElements); i++ {
			numberFormatElement := numberFormatElements[i]
			format := NumberFormat{}

			if numberFormatElement.NationalPrefixFormattingRule != "" {
				format.NationalPrefixFormattingRule = sp(getNationalPrefixFormattingRule(numberFormatElement.NationalPrefixFormattingRule, nationalPrefix))
			} else {
				format.NationalPrefixFormattingRule = sp(nationalPrefixFormattingRule)
			}

			if numberFormatElement.NationalPrefixOptionalWhenFormatting != nil {
				format.NationalPrefixOptionalWhenFormatting = numberFormatElement.NationalPrefixOptionalWhenFormatting
			} else if nationalPrefixOptionalWhenFormatting {
				format.NationalPrefixOptionalWhenFormatting = bp(nationalPrefixOptionalWhenFormatting)
			}

			if numberFormatElement.CarrierCodeFormattingRule != "" {
				format.DomesticCarrierCodeFormattingRule = sp(validateRE(getDomesticCarrierCodeFormattingRule(numberFormatElement.CarrierCodeFormattingRule, nationalPrefix), false))
			} else if carrierCodeFormattingRule != "" {
				format.DomesticCarrierCodeFormattingRule = sp(carrierCodeFormattingRule)
			}
			loadNationalFormat(metadata, &numberFormatElement, &format)
			metadata.NumberFormat = append(metadata.NumberFormat, &format)

			if loadInternationalFormat(metadata, &numberFormatElement, &format) {
				hasExplicitIntlFormatDefined = true
			}
		}
		// Only a small number of regions need to specify the intlFormats in the xml. For the majority
		// of countries the intlNumberFormat metadata is an exact copy of the national NumberFormat
		// metadata. To minimize the size of the metadata file, we only keep intlNumberFormats that
		// actually differ in some way to the national formats.
		if !hasExplicitIntlFormatDefined {
			metadata.IntlNumberFormat = nil
		}
	}
}