summaryrefslogtreecommitdiff
path: root/android/OldPhoneNumberUtils.cpp
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2018-08-06 16:50:45 -0700
committerXin Li <delphij@google.com>2018-08-06 16:50:45 -0700
commiteeeee16d3c32de2d94d1224f9db444e499b813d4 (patch)
tree3b102567981ab07a3e25a39229a7a835f5e3972d /android/OldPhoneNumberUtils.cpp
parent9c66bf8830f54f2ffab3fbe0bac62571cd1dc668 (diff)
parent55dc5685785e6eee396a1cbead0ee1fe14a9d45a (diff)
Merge Android Pie into master
Bug: 112104996 Change-Id: Ic2bc822c2597ad48e81bb018d215b784b18f76fe
Diffstat (limited to 'android/OldPhoneNumberUtils.cpp')
-rw-r--r--android/OldPhoneNumberUtils.cpp37
1 files changed, 6 insertions, 31 deletions
diff --git a/android/OldPhoneNumberUtils.cpp b/android/OldPhoneNumberUtils.cpp
index 9c2f20e..9846a1c 100644
--- a/android/OldPhoneNumberUtils.cpp
+++ b/android/OldPhoneNumberUtils.cpp
@@ -154,33 +154,6 @@ static bool matchIntlPrefixAndCC(const char* a, int len)
return state == 6 || state == 7 || state == 8;
}
-/** or -1 if both are negative */
-static int minPositive(int a, int b)
-{
- if (a >= 0 && b >= 0) {
- return (a < b) ? a : b;
- } else if (a >= 0) { /* && b < 0 */
- return a;
- } else if (b >= 0) { /* && a < 0 */
- return b;
- } else { /* a < 0 && b < 0 */
- return -1;
- }
-}
-
-/**
- * Return the offset into a of the first appearance of b, or -1 if there
- * is no such character in a.
- */
-static int indexOf(const char *a, char b) {
- const char *ix = strchr(a, b);
-
- if (ix == NULL)
- return -1;
- else
- return ix - a;
-}
-
/**
* Compare phone numbers a and b, return true if they're identical
* enough for caller ID purposes.
@@ -270,15 +243,15 @@ bool phone_number_compare_loose(const char* a, const char* b)
* (for this, a '0' and a '00' prefix would have succeeded above)
*/
- if (matchIntlPrefix(a, ia + 1) && matchIntlPrefix(b, ib +1)) {
+ if (matchIntlPrefix(a, ia + 1) && matchIntlPrefix(b, ib + 1)) {
return true;
}
- if (matchTrunkPrefix(a, ia + 1) && matchIntlPrefixAndCC(b, ib +1)) {
+ if (matchTrunkPrefix(a, ia + 1) && matchIntlPrefixAndCC(b, ib + 1)) {
return true;
}
- if (matchTrunkPrefix(b, ib + 1) && matchIntlPrefixAndCC(a, ia +1)) {
+ if (matchTrunkPrefix(b, ib + 1) && matchIntlPrefixAndCC(a, ia + 1)) {
return true;
}
@@ -292,7 +265,9 @@ bool phone_number_compare_loose(const char* a, const char* b)
*/
bool aPlusFirst = (*a == '+');
bool bPlusFirst = (*b == '+');
- if (ia < 4 && ib < 4 && (aPlusFirst || bPlusFirst) && !(aPlusFirst && bPlusFirst)) {
+ bool aIgnoreUnmatched = aPlusFirst && (ia - ib) >= 0 && (ia - ib) <= 1;
+ bool bIgnoreUnmatched = bPlusFirst && (ib - ia) >= 0 && (ib - ia) <= 1;
+ if (ia < 4 && ib < 4 && (aIgnoreUnmatched || bIgnoreUnmatched) && !(aPlusFirst && bPlusFirst)) {
return true;
}