Merge change I808651dc into eclair-mr2
* changes: bug #2180646: make comparing "404-04" and "40404" return true in PhoneNumberUtils.compare().
This commit is contained in:
@@ -378,6 +378,8 @@ public class PhoneNumberUtils
|
|||||||
compareLoosely(String a, String b) {
|
compareLoosely(String a, String b) {
|
||||||
int ia, ib;
|
int ia, ib;
|
||||||
int matched;
|
int matched;
|
||||||
|
int numNonDialableCharsInA = 0;
|
||||||
|
int numNonDialableCharsInB = 0;
|
||||||
|
|
||||||
if (a == null || b == null) return a == b;
|
if (a == null || b == null) return a == b;
|
||||||
|
|
||||||
@@ -398,6 +400,7 @@ public class PhoneNumberUtils
|
|||||||
if (!isDialable(ca)) {
|
if (!isDialable(ca)) {
|
||||||
ia--;
|
ia--;
|
||||||
skipCmp = true;
|
skipCmp = true;
|
||||||
|
numNonDialableCharsInA++;
|
||||||
}
|
}
|
||||||
|
|
||||||
cb = b.charAt(ib);
|
cb = b.charAt(ib);
|
||||||
@@ -405,6 +408,7 @@ public class PhoneNumberUtils
|
|||||||
if (!isDialable(cb)) {
|
if (!isDialable(cb)) {
|
||||||
ib--;
|
ib--;
|
||||||
skipCmp = true;
|
skipCmp = true;
|
||||||
|
numNonDialableCharsInB++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipCmp) {
|
if (!skipCmp) {
|
||||||
@@ -416,13 +420,16 @@ public class PhoneNumberUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (matched < MIN_MATCH) {
|
if (matched < MIN_MATCH) {
|
||||||
int aLen = a.length();
|
int effectiveALen = a.length() - numNonDialableCharsInA;
|
||||||
|
int effectiveBLen = b.length() - numNonDialableCharsInB;
|
||||||
|
|
||||||
// if the input strings match, but their lengths < MIN_MATCH,
|
|
||||||
// treat them as equal.
|
// if the number of dialable chars in a and b match, but the matched chars < MIN_MATCH,
|
||||||
if (aLen == b.length() && aLen == matched) {
|
// treat them as equal (i.e. 404-04 and 40404)
|
||||||
|
if (effectiveALen == effectiveBLen && effectiveALen == matched) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -314,6 +314,9 @@ public class PhoneNumberUtilsTest extends TestCase {
|
|||||||
// 444 is not a valid country code, but
|
// 444 is not a valid country code, but
|
||||||
// matchIntlPrefixAndCC doesnt know this
|
// matchIntlPrefixAndCC doesnt know this
|
||||||
assertTrue(PhoneNumberUtils.compare("+444 207 792 3490", "0 207 792 3490"));
|
assertTrue(PhoneNumberUtils.compare("+444 207 792 3490", "0 207 792 3490"));
|
||||||
|
|
||||||
|
// compare SMS short code
|
||||||
|
assertTrue(PhoneNumberUtils.compare("404-04", "40404"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user