public NumberFormat mergeFrom(NumberFormat other) { if (other.HasPattern()) { setPattern(other.getPattern()); } if (other.HasFormat()) { setFormat(other.getFormat()); } int leadingDigitsPatternSize = other.leadingDigitsPatternSize(); for (int i = 0; i < leadingDigitsPatternSize; i++) { addLeadingDigitsPattern(other.getLeadingDigitsPattern(i)); } if (other.HasNationalPrefixFormattingRule()) { setNationalPrefixFormattingRule(other.getNationalPrefixFormattingRule()); } if (other.HasDomesticCarrierCodeFormattingRule()) { setDomesticCarrierCodeFormattingRule(other.getDomesticCarrierCodeFormattingRule()); } setNationalPrefixOptionalWhenFormatting(other.isNationalPrefixOptionalWhenFormatting()); return(this); }
private bool createFormattingTemplate(NumberFormat format) { String numberRegex = format.getPattern(); // The formatter doesn't format numbers when numberRegex contains "|", e.g. // (20|3)\d{4}. In those cases we quickly return. if (numberRegex.IndexOf('|') != -1) { return(false); } // Replace anything in the form of [..] with \d numberRegex = CHARACTER_CLASS_PATTERN.Replace(numberRegex, "\\d"); // Replace any standalone digit (not the one in d{}) with \d numberRegex = STANDALONE_DIGIT_PATTERN.Replace(numberRegex, "\\d"); formattingTemplate.Clear(); String tempTemplate = getFormattingTemplate(numberRegex, format.getFormat()); if (tempTemplate.Length > 0) { formattingTemplate.Append(tempTemplate); return(true); } return(false); }