in matcher.go [47:85]
func IsNationalPrefixPresentIfRequired(number *PhoneNumber) bool {
// First, check how we deduced the country code. If it was written
// in international format, then the national prefix is not required.
if number.GetCountryCodeSource() != PhoneNumber_FROM_DEFAULT_COUNTRY {
return true
}
var phoneNumberRegion = GetRegionCodeForCountryCode(int(number.GetCountryCode()))
var metadata = getMetadataForRegion(phoneNumberRegion)
if metadata == nil {
return true
}
// Check if a national prefix should be present when formatting this number.
var nationalNumber = GetNationalSignificantNumber(number)
var formatRule = chooseFormattingPatternForNumber(
metadata.GetNumberFormat(), nationalNumber)
// To do this, we check that a national prefix formatting rule was
// present and that it wasn't just the first-group symbol ($1) with
// punctuation.
if (formatRule != nil) && len(formatRule.GetNationalPrefixFormattingRule()) > 0 {
if formatRule.GetNationalPrefixOptionalWhenFormatting() {
// The national-prefix is optional in these cases, so we
// don't need to check if it was present.
return true
}
if formattingRuleHasFirstGroupOnly(
formatRule.GetNationalPrefixFormattingRule()) {
// National Prefix not needed for this number.
return true
}
// Normalize the remainder.
var rawInputCopy = NormalizeDigitsOnly(number.GetRawInput())
var rawInput = NewBuilderString(rawInputCopy)
// Check if we found a national prefix and/or carrier code at
// the start of the raw input, and return the result.
return maybeStripNationalPrefixAndCarrierCode(
rawInput, metadata, NewBuilder(nil))
}
return true
}