Пример #1
0
 /**
  * Helper method to get the national-number part of a number, formatted without any national
  * prefix, and return it as a set of digit blocks that would be formatted together.
  */
 private static String[] getNationalNumberGroups(PhoneNumberUtil util, PhoneNumber number,
                                                 NumberFormat formattingRegex)
 {
     if (formattingRegex == null)
     {
         // This will be in the format +CC-DG;ext=EXT where DG represents groups of digits.
         String rfc3966Format = util.format(number, PhoneNumberUtil.PhoneNumberFormat.RFC3966);
         // We remove the extension part from the formatted string before splitting it into different
         // groups.
         int endIndex = rfc3966Format.IndexOf(';');
         if (endIndex < 0)
         {
             endIndex = rfc3966Format.Length;
         }
         // The country-code will have a '-' following it.
         int startIndex = rfc3966Format.IndexOf('-') + 1;
         return(rfc3966Format.Substring(startIndex, endIndex - startIndex).Split('-'));
     }
     else
     {
         // We format the NSN only, and split that according to the separator.
         String nationalSignificantNumber = util.getNationalSignificantNumber(number);
         return(util.formatNsnUsingRegex(nationalSignificantNumber,
                                         formattingRegex, PhoneNumberUtil.PhoneNumberFormat.RFC3966).Split('-'));
     }
 }
Пример #2
0
 public PhoneMetadata addIntlNumberFormat(NumberFormat value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     intlNumberFormat_.Add(value);
     return(this);
 }
Пример #3
0
        internal static bool isNationalPrefixPresentIfRequired(PhoneNumber number, PhoneNumberUtil util)
        {
            // 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.CountryCodeSource.FROM_DEFAULT_COUNTRY)
            {
                return(true);
            }
            String phoneNumberRegion =
                util.getRegionCodeForCountryCode(number.getCountryCode());
            PhoneMetadata metadata = util.getMetadataForRegion(phoneNumberRegion);

            if (metadata == null)
            {
                return(true);
            }
            // Check if a national prefix should be present when formatting this number.
            String       nationalNumber = util.getNationalSignificantNumber(number);
            NumberFormat formatRule     =
                util.chooseFormattingRegexForNumber(metadata.numberFormats(), 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 != null) && formatRule.getNationalPrefixFormattingRule().Length > 0)
            {
                if (formatRule.isNationalPrefixOptionalWhenFormatting())
                {
                    // The national-prefix is optional in these cases, so we don't need to check if it was
                    // present.
                    return(true);
                }
                if (PhoneNumberUtil.formattingRuleHasFirstGroupOnly(
                        formatRule.getNationalPrefixFormattingRule()))
                {
                    // National Prefix not needed for this number.
                    return(true);
                }
                // Normalize the remainder.
                String        rawInputCopy = PhoneNumberUtil.normalizeDigitsOnly(number.getRawInput());
                StringBuilder rawInput     = new StringBuilder(rawInputCopy);
                // Check if we found a national prefix and/or carrier code at the start of the raw input, and
                // return the result.
                return(util.maybeStripNationalPrefixAndCarrierCode(rawInput, metadata, null));
            }
            return(true);
        }
Пример #4
0
//
        public void readExternal(BinaryReader objectInput)
        {
            bool hasDesc = objectInput.readBoolean();

            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setGeneralDesc(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setFixedLine(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setMobile(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setTollFree(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setPremiumRate(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setSharedCost(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setPersonalNumber(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setVoip(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setPager(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setUan(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setEmergency(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setVoicemail(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setShortCode(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setStandardRate(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setCarrierSpecific(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setNoInternationalDialling(desc);
            }

            setId(objectInput.readUTF());
            setCountryCode(objectInput.readInt());
            setInternationalPrefix(objectInput.readUTF());

            bool hasString = objectInput.readBoolean();

            if (hasString)
            {
                setPreferredInternationalPrefix(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setNationalPrefix(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setPreferredExtnPrefix(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setNationalPrefixForParsing(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setNationalPrefixTransformRule(objectInput.readUTF());
            }

            setSameMobileAndFixedLinePattern(objectInput.readBoolean());

            int nationalFormatSize = objectInput.readInt();

            for (int i = 0; i < nationalFormatSize; i++)
            {
                NumberFormat numFormat = new NumberFormat();
                numFormat.readExternal(objectInput);
                numberFormat_.Add(numFormat);
            }

            int intlNumberFormatSize = objectInput.readInt();

            for (int i = 0; i < intlNumberFormatSize; i++)
            {
                NumberFormat numFormat = new NumberFormat();
                numFormat.readExternal(objectInput);
                intlNumberFormat_.Add(numFormat);
            }

            setMainCountryForCode(objectInput.readBoolean());

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setLeadingDigits(objectInput.readUTF());
            }

            setLeadingZeroPossible(objectInput.readBoolean());

            setMobileNumberPortableRegion(objectInput.readBoolean());
        }