/* * Contacts Service Helper * * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Youngjae Shin * Donghee Ye * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include #include #include #include #include #include #include #include "internal.h" #include "cts-sqlite.h" #include "localize.h" #include "normalize.h" #include "utils.h" #define array_sizeof(a) (sizeof(a) / sizeof(a[0])) int helper_unicode_to_utf8(char *src, int src_len, char *dest, int dest_size) { int32_t size = 0; UErrorCode status = 0; UChar *unicode_src = (UChar *)src; u_strToUTF8(dest, dest_size, &size, unicode_src, -1, &status); h_retvm_if(U_FAILURE(status), CTS_ERR_ICU_FAILED, "u_strToUTF8() Failed(%s)", u_errorName(status)); dest[size]='\0'; return CTS_SUCCESS; } static inline int check_utf8(char c) { if ((c & 0xff) < (128 & 0xff)) return 1; else if ((c & (char)0xe0) == (char)0xc0) return 2; else if ((c & (char)0xf0) == (char)0xe0) return 3; else if ((c & (char)0xf8) == (char)0xf0) return 4; else if ((c & (char)0xfc) == (char)0xf8) return 5; else if ((c & (char)0xfe) == (char)0xfc) return 6; else return CTS_ERR_FAIL; } int helper_normalize_str(const char *src, char *dest, int dest_size) { int type = CTS_LANG_OTHERS; int32_t size; UErrorCode status = 0; UChar tmp_result[CTS_SQL_MAX_LEN*2]; UChar result[CTS_SQL_MAX_LEN*2]; int i = 0; int j = 0; int str_len = strlen(src); int char_len = 0; for (i=0;i