diff options
Diffstat (limited to 'src/util/util.c')
-rw-r--r-- | src/util/util.c | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/src/util/util.c b/src/util/util.c index cb84c9e..5c0f282 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -19,6 +19,7 @@ #include <app_control.h> #include <app_debug.h> #include <app_contents.h> +#include <unicode/ustring.h> #include "define.h" #include "util/util.h" @@ -456,42 +457,64 @@ Elm_Image_Orient util_get_orient(media_content_orientation_e orient) return o; } -i18n_uchar* util_convert_to_UTF16_string(const char *source_string) +UChar* util_convert_to_UTF16_string(const char *source_string) { int buffer_length = 0; - i18n_error_code_e error_from_i18n; - i18n_uchar *converted_string = NULL; + UErrorCode error_from_icu = 0; + UChar *converted_string = NULL; /* Calc buffer size for converted UTF16 string */ - i18n_ustring_from_UTF8(NULL, 0, &buffer_length, source_string, -1, &error_from_i18n); - - converted_string = malloc((buffer_length + 2) * sizeof(i18n_uchar)); + u_strFromUTF8(NULL, 0, &buffer_length, source_string, -1, &error_from_icu); + if (buffer_length == 0) { + _ERR("error form icu[%d][%s]", error_from_icu, u_errorName(error_from_icu)); + goto OUT; + } + /* NOTE: + * Calling u_strFromUTF8 with 0 capacity always causes U_BUFFER_OVERFLOW_ERROR. + * When u_strFromUTF8 is succeeded, u_strFromUTF8 doesn't change error_from_icu. + * It means error_from_icu have U_BUFFER_OVERFLOW_ERROR even though there is no problem. + * So, error_from_icu should be reset as U_ZERO_ERROR here*/ + error_from_icu = U_ZERO_ERROR; + + converted_string = malloc((buffer_length + 2) * sizeof(UChar)); if (converted_string == NULL) { _ERR("malloc failed"); goto OUT; } /* Convert to i18n(UTF16) string */ - i18n_ustring_from_UTF8(converted_string, buffer_length + 1, &buffer_length, source_string, -1, &error_from_i18n); - if (error_from_i18n != I18N_ERROR_NONE) { - _ERR("i18n_ustring_from_UTF8 returns [%d]", error_from_i18n); + u_strFromUTF8(converted_string, buffer_length + 1, &buffer_length, source_string, -1, &error_from_icu); + if (U_FAILURE(error_from_icu)) { + _ERR("error form icu[%d][%s]", error_from_icu, u_errorName(error_from_icu)); free(converted_string); + converted_string = NULL; goto OUT; } - converted_string[buffer_length] = (i18n_uchar)0; + + converted_string[buffer_length] = (UChar)0; OUT: return converted_string; } -char* util_convert_to_UTF8_string(i18n_uchar *sourct_string) +char* util_convert_to_UTF8_string(UChar *source_string) { int buffer_length = 0; - i18n_error_code_e error_from_i18n; + UErrorCode error_from_icu; char *converted_string = NULL; - i18n_ustring_to_UTF8(NULL, 0, &buffer_length, sourct_string, -1, &error_from_i18n); + u_strToUTF8(NULL, 0, &buffer_length, source_string, -1, &error_from_icu); + if (buffer_length == 0) { + _ERR("error form icu[%d][%s]", error_from_icu, u_errorName(error_from_icu)); + goto OUT; + } + /* NOTE: + * Calling u_strToUTF8 with 0 capacity always causes U_BUFFER_OVERFLOW_ERROR. + * When u_strFromUTF8 is succeeded, u_strFromUTF8 doesn't change error_from_icu. + * It means error_from_icu have U_BUFFER_OVERFLOW_ERROR even though there is no problem. + * So, error_from_icu should be reset as U_ZERO_ERROR here */ + error_from_icu = U_ZERO_ERROR; converted_string = malloc((buffer_length + 2) * sizeof(char)); if (converted_string == NULL) { @@ -500,13 +523,14 @@ char* util_convert_to_UTF8_string(i18n_uchar *sourct_string) } /* Convert to UTF8 */ - i18n_ustring_to_UTF8(converted_string, buffer_length + 1, &buffer_length, sourct_string, -1, &error_from_i18n); - if (error_from_i18n != I18N_ERROR_NONE) { - _ERR("i18n_ustring_to_UTF8 returns [%d]", error_from_i18n); + u_strToUTF8(converted_string, buffer_length + 1, &buffer_length, source_string, -1, &error_from_icu); + if (U_FAILURE(error_from_icu)) { + _ERR("error form icu[%d][%s]", error_from_icu, u_errorName(error_from_icu)); free(converted_string); converted_string = NULL; goto OUT; } + converted_string[buffer_length] = '\0'; OUT: |