Merge "Snap for 5798008 from 39ceab0aea1636255de8f75e8b8c7c91ce41fee7 to sdk-release" into sdk-release
diff --git a/android/OldPhoneNumberUtils.cpp b/android/OldPhoneNumberUtils.cpp
index 9846a1c..3a69e0c 100644
--- a/android/OldPhoneNumberUtils.cpp
+++ b/android/OldPhoneNumberUtils.cpp
@@ -159,13 +159,13 @@
* enough for caller ID purposes.
*
* - Compares from right to left
- * - requires MIN_MATCH (7) characters to match
+ * - requires minimum characters to match
* - handles common trunk prefixes and international prefixes
* (basically, everything except the Russian trunk prefix)
*
* Tolerates nulls
*/
-bool phone_number_compare_loose(const char* a, const char* b)
+bool phone_number_compare_loose_with_minmatch(const char* a, const char* b, int min_match)
{
int ia, ib;
int matched;
@@ -216,11 +216,11 @@
}
}
- if (matched < MIN_MATCH) {
+ if (matched < min_match) {
const int effectiveALen = strlen(a) - numSeparatorCharsInA;
const int effectiveBLen = strlen(b) - numSeparatorCharsInB;
- // if the number of dialable chars in a and b match, but the matched chars < MIN_MATCH,
+ // 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;
@@ -230,7 +230,7 @@
}
// At least one string has matched completely;
- if (matched >= MIN_MATCH && (ia < 0 || ib < 0)) {
+ if (matched >= min_match && (ia < 0 || ib < 0)) {
return true;
}
@@ -274,4 +274,9 @@
return false;
}
+bool phone_number_compare_loose(const char* a, const char* b)
+{
+ return phone_number_compare_loose_with_minmatch(a, b, MIN_MATCH);
+}
+
} // namespace android
diff --git a/android/PhoneNumberUtils.h b/android/PhoneNumberUtils.h
index 58b9ab8..80776bb 100644
--- a/android/PhoneNumberUtils.h
+++ b/android/PhoneNumberUtils.h
@@ -21,6 +21,7 @@
namespace android {
bool phone_number_compare_loose(const char* a, const char* b);
+bool phone_number_compare_loose_with_minmatch(const char* a, const char* b, int min_match);
bool phone_number_compare_strict(const char* a, const char* b);
bool phone_number_stripped_reversed_inter(const char* in, char* out, const int len, int *outlen);
diff --git a/android/sqlite3_android.cpp b/android/sqlite3_android.cpp
index 659ee6c..d2f1802 100644
--- a/android/sqlite3_android.cpp
+++ b/android/sqlite3_android.cpp
@@ -79,7 +79,7 @@
static void phone_numbers_equal(sqlite3_context * context, int argc, sqlite3_value ** argv)
{
- if (argc != 2 && argc != 3) {
+ if (argc != 2 && argc != 3 && argc != 4) {
sqlite3_result_int(context, 0);
return;
}
@@ -88,8 +88,12 @@
char const * num2 = (char const *)sqlite3_value_text(argv[1]);
bool use_strict = false;
- if (argc == 3) {
+ int min_match = 0;
+ if (argc == 3 || argc == 4) {
use_strict = (sqlite3_value_int(argv[2]) != 0);
+ if (!use_strict && argc == 4) {
+ min_match = sqlite3_value_int(argv[3]);
+ }
}
if (num1 == NULL || num2 == NULL) {
@@ -98,9 +102,11 @@
}
bool equal =
- (use_strict ?
- android::phone_number_compare_strict(num1, num2) :
- android::phone_number_compare_loose(num1, num2));
+ (use_strict ? android::phone_number_compare_strict(num1, num2)
+ : ((min_match > 0)
+ ? android::phone_number_compare_loose_with_minmatch(
+ num1, num2, min_match)
+ : android::phone_number_compare_loose(num1, num2)));
if (equal) {
sqlite3_result_int(context, 1);
@@ -543,6 +549,14 @@
return err;
}
+ // Register the PHONE_NUM_EQUALS function with additional arguments "use_strict" and "min_match"
+ err = sqlite3_create_function(
+ handle, "PHONE_NUMBERS_EQUAL", 4,
+ SQLITE_UTF8, NULL, phone_numbers_equal, NULL, NULL);
+ if (err != SQLITE_OK) {
+ return err;
+ }
+
// Register the _DELETE_FILE function
err = sqlite3_create_function(handle, "_DELETE_FILE", 1, SQLITE_UTF8, NULL, delete_file, NULL, NULL);
if (err != SQLITE_OK) {