GetAlternateFormatsForCountry() public static method

public static GetAlternateFormatsForCountry ( int countryCallingCode ) : PhoneMetadata
countryCallingCode int
return PhoneMetadata
コード例 #1
0
        public static bool CheckNumberGroupingIsValid(
            PhoneNumber number, String candidate, PhoneNumberUtil util, CheckGroups checker)
        {
            // TODO: Evaluate how this works for other locales (testing has been limited to NANPA regions)
            // and optimise if necessary.
            StringBuilder normalizedCandidate =
                PhoneNumberUtil.NormalizeDigits(candidate, true /* keep non-digits */);

            String[] formattedNumberGroups = PhoneNumberMatcher.GetNationalNumberGroups(util, number, null);
            if (checker(util, number, normalizedCandidate, formattedNumberGroups))
            {
                return(true);
            }
            // If this didn't pass, see if there are any alternate formats, and try them instead.
            var alternateFormats =
                MetadataManager.GetAlternateFormatsForCountry(number.CountryCode);

            if (alternateFormats != null)
            {
                foreach (var alternateFormat in alternateFormats.NumberFormatList)
                {
                    formattedNumberGroups = GetNationalNumberGroups(util, number, alternateFormat);
                    if (checker(util, number, normalizedCandidate, formattedNumberGroups))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        public bool CheckNumberGroupingIsValid(
            PhoneNumber number, string candidate, PhoneNumberUtil util, CheckGroups checker)
        {
            // TODO: Evaluate how this works for other locales (testing has been limited to NANPA regions)
            // and optimise if necessary.
            var normalizedCandidate =
                PhoneNumberUtil.NormalizeDigits(new StringBuilder(candidate), true /* keep non-digits */);
            var formattedNumberGroups = GetNationalNumberGroups(util, number);

            if (checker(util, number, normalizedCandidate, formattedNumberGroups))
            {
                return(true);
            }
            // If this didn't pass, see if there are any alternate formats that match, and try them instead.
            var alternateFormats =
                MetadataManager.GetAlternateFormatsForCountry(number.CountryCode);
            var nationalSignificantNumber = util.GetNationalSignificantNumber(number);

            if (alternateFormats != null)
            {
                foreach (var alternateFormat in alternateFormats.NumberFormatList)
                {
                    if (alternateFormat.LeadingDigitsPatternCount > 0)
                    {
                        // There is only one leading digits pattern for alternate formats.
                        var pattern =
                            regexCache.GetPatternForRegex(alternateFormat.GetLeadingDigitsPattern(0));
                        if (!pattern.IsMatchBeginning(nationalSignificantNumber))
                        {
                            // Leading digits don't match; try another one.
                            continue;
                        }
                    }
                    formattedNumberGroups = GetNationalNumberGroups(util, number, alternateFormat);
                    if (checker(util, number, normalizedCandidate, formattedNumberGroups))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }