diff options
author | Daisuke Miyakawa <dmiyakawa@google.com> | 2009-05-18 14:51:52 +0900 |
---|---|---|
committer | Daisuke Miyakawa <dmiyakawa@google.com> | 2009-05-18 14:51:52 +0900 |
commit | d28cdc45c5e3f29f8904759293c813ad0a58329e (patch) | |
tree | 3a56006778b1186f6f145b08f28242279c6ecb2f /android/sqlite3_android.cpp | |
parent | 687f1165e7f61d3842e6b8f4ba28d0473fff529b (diff) |
Hand merge from cupcake_dcm from donut, part 1.
Add SQL functions "GET_PHONETICALLY_SORTABLE_STRING()" and "GET_NORMALIZED_STRING()" and its tests.
Diffstat (limited to 'android/sqlite3_android.cpp')
-rw-r--r-- | android/sqlite3_android.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/android/sqlite3_android.cpp b/android/sqlite3_android.cpp index dac93c2..b3ae28c 100644 --- a/android/sqlite3_android.cpp +++ b/android/sqlite3_android.cpp @@ -90,6 +90,25 @@ static void get_phonetically_sortable_string( } } +static void get_normalized_string( + sqlite3_context * context, int argc, sqlite3_value ** argv) +{ + if (argc != 1) { + sqlite3_result_null(context); + return; + } + char const * src = (char const *)sqlite3_value_text(argv[0]); + char * ret; + size_t len; + + if (!android::GetNormalizedString(src, &ret, &len)) { + // Probably broken string. Return 0 length string. + sqlite3_result_text(context, "", -1, SQLITE_STATIC); + } else { + sqlite3_result_text(context, ret, len, free); + } +} + static void phone_numbers_equal(sqlite3_context * context, int argc, sqlite3_value ** argv) { if (argc != 2) { @@ -465,5 +484,15 @@ extern "C" int register_android_functions(sqlite3 * handle, int utf16Storage) return err; } + // Register the GET_NORMALIZED_STRING function + err = sqlite3_create_function(handle, + "GET_NORMALIZED_STRING", + 1, SQLITE_UTF8, NULL, + get_normalized_string, + NULL, NULL); + if (err != SQLITE_OK) { + return err; + } + return SQLITE_OK; } |