From 47633f86279bc1854660d95a0b02bfa5ff14ad04 Mon Sep 17 00:00:00 2001 From: Lars Dunemark Date: Mon, 8 Feb 2010 14:04:38 +0100 Subject: [PATCH] Removes dashes when locale and number is not NANP or Japan Removes all dashes if locale isn't NANP or Japan and the number don't have there country code. Use case: If adding a number starting with 1nnnnnn and then trying to add a country code before (ex +46) we will first trigger NANP formatting with +1-nnn-nnn so when we get +41-nnn-nnn we will still have the old NANP formatting. This number should be shown as +461nnnnnn. Change-Id: I5cab830350d785a58367eba79e268d9e8ee16aac --- .../android/telephony/PhoneNumberUtils.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 3f086765a8b8f..454231ff6adcf 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -1058,7 +1058,7 @@ public class PhoneNumberUtils && text.charAt(2) == '1') { formatType = FORMAT_JAPAN; } else { - return; + formatType = FORMAT_UNKNOWN; } } @@ -1069,6 +1069,9 @@ public class PhoneNumberUtils case FORMAT_JAPAN: formatJapaneseNumber(text); return; + case FORMAT_UNKNOWN: + removeDashes(text); + return; } } @@ -1104,14 +1107,7 @@ public class PhoneNumberUtils CharSequence saved = text.subSequence(0, length); // Strip the dashes first, as we're going to add them back - int p = 0; - while (p < text.length()) { - if (text.charAt(p) == '-') { - text.delete(p, p + 1); - } else { - p++; - } - } + removeDashes(text); length = text.length(); // When scanning the number we record where dashes need to be added, @@ -1215,6 +1211,22 @@ public class PhoneNumberUtils JapanesePhoneNumberFormatter.format(text); } + /** + * Removes all dashes from the number. + * + * @param text the number to clear from dashes + */ + private static void removeDashes(Editable text) { + int p = 0; + while (p < text.length()) { + if (text.charAt(p) == '-') { + text.delete(p, p + 1); + } else { + p++; + } + } + } + // Three and four digit phone numbers for either special services, // or 3-6 digit addresses from the network (eg carrier-originated SMS messages) should // not match.