From 90b74eb35d36dd898053b051a221352b7dd5f4ec Mon Sep 17 00:00:00 2001 From: Tiago Salem Herrmann Date: Tue, 6 Sep 2016 12:46:46 -0300 Subject: [PATCH 1/4] Add hash as a diallable char. --- cpp/src/phonenumbers/phonenumberutil.cc | 1 + cpp/test/phonenumbers/phonenumberutil_test.cc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/src/phonenumbers/phonenumberutil.cc b/cpp/src/phonenumbers/phonenumberutil.cc index 7aefd3d78..51e825a6c 100644 --- a/cpp/src/phonenumbers/phonenumberutil.cc +++ b/cpp/src/phonenumbers/phonenumberutil.cc @@ -288,6 +288,7 @@ class PhoneNumberRegExpsAndMappings { void InitializeMapsAndSets() { diallable_char_mappings_.insert(std::make_pair('+', '+')); diallable_char_mappings_.insert(std::make_pair('*', '*')); + diallable_char_mappings_.insert(std::make_pair('#', '#')); // Here we insert all punctuation symbols that we wish to respect when // formatting alpha numbers, as they show the intended number groupings. all_plus_number_grouping_symbols_.insert( diff --git a/cpp/test/phonenumbers/phonenumberutil_test.cc b/cpp/test/phonenumbers/phonenumberutil_test.cc index bf56f65c5..a59fd0f44 100644 --- a/cpp/test/phonenumbers/phonenumberutil_test.cc +++ b/cpp/test/phonenumbers/phonenumberutil_test.cc @@ -2500,9 +2500,9 @@ TEST_F(PhoneNumberUtilTest, NormaliseStripAlphaCharacters) { } TEST_F(PhoneNumberUtilTest, NormaliseStripNonDiallableCharacters) { - string input_number("03*4-56&+a#234"); + string input_number("03*4-56&+1a#234"); NormalizeDiallableCharsOnly(&input_number); - static const string kExpectedOutput("03*456+234"); + static const string kExpectedOutput("03*456+1#234"); EXPECT_EQ(kExpectedOutput, input_number) << "Conversion did not correctly remove non-diallable characters"; } From 1bbbcf9b5147db63cfabb86cd6f49c4cb35ea7d7 Mon Sep 17 00:00:00 2001 From: Tiago Salem Herrmann Date: Fri, 28 Oct 2016 19:12:28 -0200 Subject: [PATCH 2/4] Add hash as diallable character to java and javascript implementations --- .../src/com/google/i18n/phonenumbers/PhoneNumberUtil.java | 1 + .../test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java | 2 +- java/pending_code_changes.txt | 1 + javascript/i18n/phonenumbers/phonenumberutil.js | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index ddb26f7cb..af1b803ac 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -197,6 +197,7 @@ public class PhoneNumberUtil { diallableCharMap.putAll(asciiDigitMappings); diallableCharMap.put(PLUS_SIGN, PLUS_SIGN); diallableCharMap.put('*', '*'); + diallableCharMap.put('#', '#'); DIALLABLE_CHAR_MAPPINGS = Collections.unmodifiableMap(diallableCharMap); HashMap allPlusNumberGroupings = new HashMap(); diff --git a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index ce3c28c1a..864f117c2 100644 --- a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -427,7 +427,7 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase { public void testNormaliseStripNonDiallableCharacters() { String inputNumber = "03*4-56&+a#234"; - String expectedOutput = "03*456+234"; + String expectedOutput = "03*456+#234"; assertEquals("Conversion did not correctly remove non-diallable characters", expectedOutput, PhoneNumberUtil.normalizeDiallableCharsOnly(inputNumber)); diff --git a/java/pending_code_changes.txt b/java/pending_code_changes.txt index c9ffb5d12..57e401849 100644 --- a/java/pending_code_changes.txt +++ b/java/pending_code_changes.txt @@ -3,3 +3,4 @@ Code changes: length or not. This could result in more specific results; whereas before, a number from length 3 to length 6 may have been deemed possible, now we may exclude a number of length 5. + - Add hash (#) as a diallable character. diff --git a/javascript/i18n/phonenumbers/phonenumberutil.js b/javascript/i18n/phonenumbers/phonenumberutil.js index 5ca14d1b4..b42989915 100644 --- a/javascript/i18n/phonenumbers/phonenumberutil.js +++ b/javascript/i18n/phonenumbers/phonenumberutil.js @@ -314,7 +314,8 @@ i18n.phonenumbers.PhoneNumberUtil.DIALLABLE_CHAR_MAPPINGS_ = { '8': '8', '9': '9', '+': i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN, - '*': '*' + '*': '*', + '#': '#' }; From 80f2e2e1cfcf251b5ffeed5c46776e456d27eb22 Mon Sep 17 00:00:00 2001 From: Tiago Salem Herrmann Date: Wed, 2 Nov 2016 06:28:28 -0200 Subject: [PATCH 3/4] Use same string for tests in the java implementation --- .../com/google/i18n/phonenumbers/PhoneNumberUtilTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index 864f117c2..76245ce73 100644 --- a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -426,8 +426,8 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase { } public void testNormaliseStripNonDiallableCharacters() { - String inputNumber = "03*4-56&+a#234"; - String expectedOutput = "03*456+#234"; + String inputNumber = "03*4-56&+1a#234"; + String expectedOutput = "03*456+1#234"; assertEquals("Conversion did not correctly remove non-diallable characters", expectedOutput, PhoneNumberUtil.normalizeDiallableCharsOnly(inputNumber)); From e81f51b63df9c0bfc1355e9476591cba6b96b2cc Mon Sep 17 00:00:00 2001 From: Tiago Salem Herrmann Date: Wed, 2 Nov 2016 06:29:42 -0200 Subject: [PATCH 4/4] improve change description --- java/pending_code_changes.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/pending_code_changes.txt b/java/pending_code_changes.txt index 57e401849..ef2c9706f 100644 --- a/java/pending_code_changes.txt +++ b/java/pending_code_changes.txt @@ -3,4 +3,6 @@ Code changes: length or not. This could result in more specific results; whereas before, a number from length 3 to length 6 may have been deemed possible, now we may exclude a number of length 5. - - Add hash (#) as a diallable character. + - Add hash (#) as a diallable character. Numbers with # in them will no longer + have formatting applied in formatInOriginalFormat, and + normalizeDiallableCharsOnly now retains the # symbol.