diff options
author | Wei Huang <weih@google.com> | 2009-10-22 18:06:17 -0700 |
---|---|---|
committer | Wei Huang <weih@google.com> | 2009-10-23 01:16:05 -0700 |
commit | fd20ece0e27308d9b5e314b1cc8d5fa3a0d174ea (patch) | |
tree | 8f2479e695d1fcca1f28ebb55ffaaec6df736f51 /android/OldPhoneNumberUtils.cpp | |
parent | 468ecb9591c35466d0a89b96d205da636a6f66a1 (diff) |
bug #2180646: make comparing "404-04" and "40404" return true in the native sqlite (loose) phone number comparison method.
- when comparing two numbers whose dialable char length is less than the MIN_MATCH (7), treat them as equal if the dialable portion of the numbers match.
Diffstat (limited to 'android/OldPhoneNumberUtils.cpp')
-rw-r--r-- | android/OldPhoneNumberUtils.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/android/OldPhoneNumberUtils.cpp b/android/OldPhoneNumberUtils.cpp index baeb3fe..5f180dc 100644 --- a/android/OldPhoneNumberUtils.cpp +++ b/android/OldPhoneNumberUtils.cpp @@ -196,6 +196,8 @@ bool phone_number_compare_loose(const char* a, const char* b) { int ia, ib; int matched; + int numSeparatorCharsInA = 0; + int numSeparatorCharsInB = 0; if (a == NULL || b == NULL) { return false; @@ -222,6 +224,7 @@ bool phone_number_compare_loose(const char* a, const char* b) if (!isNonSeparator(ca)) { ia--; skipCmp = true; + numSeparatorCharsInA++; } cb = b[ib]; @@ -229,6 +232,7 @@ bool phone_number_compare_loose(const char* a, const char* b) if (!isNonSeparator(cb)) { ib--; skipCmp = true; + numSeparatorCharsInB++; } if (!skipCmp) { @@ -240,13 +244,15 @@ bool phone_number_compare_loose(const char* a, const char* b) } if (matched < MIN_MATCH) { - int aLen = strlen(a); + const int effectiveALen = strlen(a) - numSeparatorCharsInA; + const int effectiveBLen = strlen(b) - numSeparatorCharsInB; - // if the input strings match, but their lengths < MIN_MATCH, - // treat them as equal. - if (aLen == (int)strlen(b) && aLen == matched) { + // if the number of dialable chars in a and b match, but the matched chars < MIN_MATCH, + // treat them as equal (i.e. 404-04 and 40404) + if (effectiveALen == effectiveBLen && effectiveALen == matched) { return true; } + return false; } |