internal static boolean allNumberGroupsRemainGrouped(PhoneNumberUtil util, PhoneNumber number, StringBuilder normalizedCandidate, String[] formattedNumberGroups) { int fromIndex = 0; // Check each group of consecutive digits are not broken into separate groupings in the // {@code normalizedCandidate} string. for (int i = 0; i < formattedNumberGroups.length(); i++) { // Fails if the substring of {@code normalizedCandidate} starting from {@code fromIndex} // doesn't contain the consecutive digits in formattedNumberGroups[i]. fromIndex = normalizedCandidate.indexOf(formattedNumberGroups[i], fromIndex); if (fromIndex < 0) { return(false); } // Moves {@code fromIndex} forward. fromIndex += formattedNumberGroups[i].length(); if (i == 0 && fromIndex < normalizedCandidate.length()) { // We are at the position right after the NDC. We get the region used for formatting // information based on the country code in the phone number, rather than the number itself, // as we do not need to distinguish between different countries with the same country // calling code and this is faster. String region = util.getRegionCodeForCountryCode(number.getCountryCode()); if (util.getNddPrefixForRegion(region, true) != null && Character.isDigit(normalizedCandidate.charAt(fromIndex))) { // This means there is no formatting symbol after the NDC. In this case, we only // accept the number if there is no formatting symbol at all in the number, except // for extensions. This is only important for countries with national prefixes. String nationalSignificantNumber = util.getNationalSignificantNumber(number); return(normalizedCandidate.substring(fromIndex - formattedNumberGroups[i].length()) .startsWith(nationalSignificantNumber)); } } } // The check here makes sure that we haven't mistakenly already used the extension to // match the last group of the subscriber number. Note the extension cannot have // formatting in-between digits. return(normalizedCandidate.substring(fromIndex).contains(number.getExtension())); }
private void transformA (StringBuilder result) { if ((arg is float) || (arg is double)) { result.append (String.Format ("{0:x}", arg)); } else { throw badArgumentType (); } if (!formatToken.isPrecisionSet ()) { return; } int precision = formatToken.getPrecision (); if (precision == 0) { precision = 1; } int indexOfFirstFractionalDigit = result.indexOf (".") + 1; int indexOfP = result.indexOf ("p"); int fractionalLength = indexOfP - indexOfFirstFractionalDigit; if (fractionalLength == precision) { return; } if (fractionalLength < precision) { char[] zeros = new char[precision - fractionalLength]; java.util.Arrays.fill (zeros, '0'); // %a shouldn't be localized. result.insert (indexOfP, zeros); return; } result.delete (indexOfFirstFractionalDigit + precision, indexOfP); }
// BigDecimal can't represent NaN or infinities, but its doubleValue method will return // infinities if the BigDecimal is too big for a double. private void transformE (StringBuilder result) { // All zeros in this method are *pattern* characters, so no localization. int precision = formatToken.getPrecision (); string pattern = "0E+00"; if (precision > 0) { StringBuilder sb = new StringBuilder ("0."); char[] zeros = new char[precision]; java.util.Arrays.fill (zeros, '0'); sb.append (zeros); sb.append ("E+00"); pattern = sb.ToString (); } result.append (arg.ToString ().Replace ('E', 'e')); // The # flag requires that we always output a decimal separator. if (formatToken.flagSharp && precision == 0) { int indexOfE = result.indexOf ("e"); result.insert (indexOfE, localeData.decimalSeparator); } }