format phone number in E123 national format with cursor position handling.

@param pphoneNumber phone number as String to format with cursor position
@param pcountryCode iso code of country
@return formated phone number as String with new cursor position
1359
public final ValueWithPos<String> formatE123NationalWithPos(
      final ValueWithPos<String> pphoneNumber, final String pcountryCode) {
    return valueWithPosDefaults(
        this.formatE123NationalWithPos(this.parsePhoneNumber(pphoneNumber, pcountryCode)),
        pphoneNumber);
  }
228022
public final Long formatIndex(final PhoneNumberInterface pphoneNumberData) {
    if (isPhoneNumberNotEmpty(pphoneNumberData)) {
      return Long.valueOf(StringUtils.defaultString(pphoneNumberData.getCountryCode())
          + StringUtils.defaultString(pphoneNumberData.getAreaCode())
          + StringUtils.defaultString(pphoneNumberData.getLineNumber())
          + StringUtils.defaultString(pphoneNumberData.getExtension()));
    }
    return null;
  }
25860
@SuppressWarnings("unused")
    public Phonenumber.PhoneNumber getPhoneNumber() {
        try {
            String iso = null;
            if (mSelectedCountry != null) {
                iso = mSelectedCountry.getIso();
            }
            return mPhoneUtil.parse(mPhoneEdit.getText().toString(), iso);
        } catch (NumberParseException ignored) {
            return null;
        }
    }
69825
public final ValueWithPos<String> formatCommonWithPos(
      final ValueWithPos<PhoneNumberData> pphoneNumberData, final PhoneCountryData pcountryData) {
    if (pphoneNumberData != null && pcountryData != null
        && StringUtils.equals(pcountryData.getCountryCodeData().getCountryCode(),
            pphoneNumberData.getValue().getCountryCode())) {
      return this.formatCommonNationalWithPos(pphoneNumberData);
    } else {
      return this.formatCommonInternationalWithPos(pphoneNumberData);
    }
  }
831969
public static function getExampleNumber(string $regionCode, int $phoneNumberType = PhoneNumberType::FIXED_LINE) : PhoneNumber
    {
        $phoneNumber = PhoneNumberUtil::getInstance()->getExampleNumberForType($regionCode, $phoneNumberType);

        if ($phoneNumber === null) {
            throw new PhoneNumberException('No example number is available for the given region and type.');
        }

        return new PhoneNumber($phoneNumber);
    }
367568
public final boolean isPhoneNumberEmpty(final PhoneNumberInterface pphoneNumberData) {
    return pphoneNumberData == null || StringUtils.isBlank(pphoneNumberData.getCountryCode())
        || StringUtils.isBlank(pphoneNumberData.getLineNumber());
  }
521250
def _format_nsn(number, metadata, num_format, carrier_code=None):
    """"""
    # Note in some regions, the national number can be written in two
    # completely different ways depending on whether it forms part of the
    # NATIONAL format or INTERNATIONAL format. The num_format parameter here
    # is used to specify which format to use for those cases. If a carrier_code
    # is specified, this will be inserted into the formatted string to replace
    # $CC.
    intl_number_formats = metadata.intl_number_format

    # When the intl_number_formats exists, we use that to format national
    # number for the INTERNATIONAL format instead of using the
    # number_desc.number_formats.
    if (len(intl_number_formats) == 0 or
        num_format == PhoneNumberFormat.NATIONAL):
        available_formats = metadata.number_format
    else:
        available_formats = metadata.intl_number_format
    formatting_pattern = _choose_formatting_pattern_for_number(available_formats, number)
    if formatting_pattern is None:
        return number
    else:
        return _format_nsn_using_pattern(number, formatting_pattern, num_format, carrier_code)
1200950
public final ValueWithPos<String> formatDin5008International(
      final ValueWithPos<String> pphoneNumber) {
    return valueWithPosDefaults(
        this.formatDin5008InternationalWithPos(this.parsePhoneNumber(pphoneNumber)), pphoneNumber);
  }
1043984
public function phoneFormatByCountry($phone, $country = 'BR', $format = 'n')
    {
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $phoneParse = $phoneUtil->parse($phone, $country);
        } catch (\libphonenumber\NumberParseException $e) {
            return null;
        }

        if ($format == 'n') {
            $method = PhoneNumberFormat::NATIONAL;
        } elseif ($format == 'i') {
            $method = PhoneNumberFormat::INTERNATIONAL;
        } else {
            $method = PhoneNumberFormat::E164;
        }

        return $phoneUtil->format($phoneParse, $method);
    }
452059
def number_type(numobj):
    
    region_code = region_code_for_number(numobj)
    metadata = PhoneMetadata.metadata_for_region_or_calling_code(numobj.country_code, region_code)
    if metadata is None:
        return PhoneNumberType.UNKNOWN
    national_number = national_significant_number(numobj)
    return _number_type_helper(national_number, metadata)
1053377
public Phonenumber.PhoneNumber getUnderlyingPhoneNumber() {
        
    	Phonenumber.PhoneNumber copy;
    	
        StringBuilder e164Builder = new StringBuilder();
        PHONE_NUMBER_UTIL.format(number, PhoneNumberFormat.E164, e164Builder);
        
    	try {
            copy = PHONE_NUMBER_UTIL.parse(e164Builder.toString(), "GB");
        } catch (NumberParseException e) {
            throw new PhoneNumberParseException(
                    EX_PARSE_MSG_PREFIX + number.getNationalNumber() +"}", e);
        }
    	
    	if (number.hasExtension()) {
    		copy.setExtension(number.getExtension());
    	}
    	return copy;
    }
1360824
@Override
    public StringBuffer format(Object number,
                               StringBuffer toAppendTo,
                               FieldPosition pos) {
        if (number instanceof Long) {
            return format(((Long)number).longValue(), toAppendTo, pos);
        } else if (number instanceof BigInteger) {
            return format((BigInteger) number, toAppendTo, pos);
        } else if (number instanceof java.math.BigDecimal) {
            return format((java.math.BigDecimal) number, toAppendTo, pos);
        } else if (number instanceof android.icu.math.BigDecimal) {
            return format((android.icu.math.BigDecimal) number, toAppendTo, pos);
        } else if (number instanceof CurrencyAmount) {
            return format((CurrencyAmount)number, toAppendTo, pos);
        } else if (number instanceof Number) {
            return format(((Number)number).doubleValue(), toAppendTo, pos);
        } else {
            throw new IllegalArgumentException("Cannot format given Object as a Number");
        }
    }
1062041
private String formatPhoneNumber() {

    StringBuilder buffer = new StringBuilder();
    buffer.append(this.countryCode);
    buffer.append(' ');
    buffer.append(this.areaCode);
    buffer.append(' ');
    buffer.append(this.localNumber);
    if ((this.extension != null) && (this.extension.length() > 0)) {
      buffer.append('-');
      buffer.append(this.extension);
    }
    return buffer.toString();
  }
636445
public final ValueWithPos<String> formatE123National(final ValueWithPos<String> pphoneNumber) {
    return valueWithPosDefaults(this.formatE123NationalWithPos(this.parsePhoneNumber(pphoneNumber)),
        pphoneNumber);
  }
623535
def _region_code_for_short_number_from_region_list(numobj, region_codes):
    
    if len(region_codes) == 0:
        return None
    elif len(region_codes) == 1:
        return region_codes[0]
    national_number = national_significant_number(numobj)
    for region_code in region_codes:
        metadata = PhoneMetadata.short_metadata_for_region(region_code)
        if metadata is not None and _matches_possible_number_and_national_number(national_number, metadata.short_code):
            # The number is valid for this region.
            return region_code
    return None
708817
@Override
  public final void initialize(final PhoneNumberValueRest pconstraintAnnotation) {
    message = pconstraintAnnotation.message();
    fieldPhoneNumber = pconstraintAnnotation.fieldPhoneNumber();
    fieldCountryCode = pconstraintAnnotation.fieldCountryCode();
    allowDin5008 = pconstraintAnnotation.allowDin5008();
    allowE123 = pconstraintAnnotation.allowE123();
    allowUri = pconstraintAnnotation.allowUri();
    allowMs = pconstraintAnnotation.allowMs();
    allowCommon = pconstraintAnnotation.allowCommon();
  }
142671
public static ValueWithPos<String> isbn13FormatWithPos(final ValueWithPos<String> pentry) {
    if (pentry == null) {
      return null;
    }
    if (StringUtils.isNotEmpty(pentry.getValue())) {
      final StringBuilder ibanSb = new StringBuilder(Isbn13FormatedValidator.ISBN13_LENGTH);
      int pos = 0;
      int posformated = 0;
      for (final char charCode : pentry.getValue().toCharArray()) {
        if (CharUtils.isAsciiNumeric(charCode)) {
          if (pos == 3 || pos == 4 || pos == 6 || pos == 12) {
            ibanSb.append(SEPARATOR);
            if (posformated <= pentry.getPos()) {
              pentry.setPos(pentry.getPos() + 1);
            }
            posformated++;
          }
          ibanSb.append(charCode);
          pos++;
          posformated++;
        } else {
          if (posformated < pentry.getPos()) {
            pentry.setPos(pentry.getPos() - 1);
          }
        }
      }
      pentry.setValue(ibanSb.toString());
      if (pentry.getPos() < 0) {
        pentry.setPos(0);
      } else if (pentry.getPos() >= ibanSb.length()) {
        pentry.setPos(ibanSb.length());
      }
    }
    return pentry;
  }