From ceb4b2d3f78bc9570fb06f0e1fbec4fa19828338 Mon Sep 17 00:00:00 2001 From: Damian Pietruchowski Date: Thu, 18 May 2017 13:09:03 +0200 Subject: [PATCH] [Base-utils][Uchar][ACR-974] i18n_uchar_get_numeric_value() function added Change-Id: Ie4c0195e849711ad840925210edb9ab2994c6d4b Signed-off-by: Damian Pietruchowski --- src/include/utils_i18n.h | 5 ++++ src/include/utils_i18n_types.h | 2 +- src/include/utils_i18n_uchar.h | 53 +++++++++++++++++++++++++++++++----------- src/utils_i18n_uchar.c | 9 +++++++ 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/include/utils_i18n.h b/src/include/utils_i18n.h index dbc4994..9b3280c 100644 --- a/src/include/utils_i18n.h +++ b/src/include/utils_i18n.h @@ -712,6 +712,11 @@ extern "C" { * ublock_getCode * * + * @ref CAPI_BASE_UTILS_I18N_UCHAR_MODULE + * #i18n_uchar_get_numeric_value + * u_getNumericValue + * + * * @ref CAPI_BASE_UTILS_I18N_UCOLLATOR_MODULE * #i18n_ucollator_create * ucol_open diff --git a/src/include/utils_i18n_types.h b/src/include/utils_i18n_types.h index 23a3e11..660e904 100644 --- a/src/include/utils_i18n_types.h +++ b/src/include/utils_i18n_types.h @@ -146,7 +146,7 @@ i18n_error_code_e; #define I18N_U_GC_P_MASK (I18N_U_GC_PD_MASK|I18N_U_GC_PS_MASK|I18N_U_GC_PE_MASK|I18N_U_GC_PC_MASK|I18N_U_GC_PO_MASK|I18N_U_GC_PI_MASK|I18N_U_GC_PF_MASK) /** * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * - * @param[in] c The code point to test. - * @param[in] which The #i18n_uchar_uproperty_e selector constant, identifies which property to check \n - * Must be #I18N_UCHAR_BINARY_START<=which<#I18N_UCHAR_BINARY_LIMIT - * or #I18N_UCHAR_INT_START<=which<#I18N_UCHAR_INT_LIMIT - * or #I18N_UCHAR_MASK_START<=which<#I18N_UCHAR_MASK_LIMIT. + * @param[in] c The code point to test. + * @param[in] which The #i18n_uchar_uproperty_e selector constant, identifies which property + * to check. \n Must be + * #I18N_UCHAR_BINARY_START <= @a which < #I18N_UCHAR_BINARY_LIMIT + * or #I18N_UCHAR_INT_START <= @a which < #I18N_UCHAR_INT_LIMIT + * or #I18N_UCHAR_MASK_START <= @a which < #I18N_UCHAR_MASK_LIMIT. * @param[out] property_val The numeric value that is directly the property value or, - * for enumerated properties, corresponds to the numeric value of the enumerated - * constant of the respective property value enumeration type (cast to enum type if necessary)\n - * Returns @c 0 or @c 1 (for false/true) for binary Unicode properties\n - * Returns a bit-mask for mask properties \n - * Returns @c 0 if 'which' is out of bounds or if the Unicode version does not have data for the property at all, or not for this code point. + * for enumerated properties, corresponds to the numeric value of the + * enumerated constant of the respective property value enumeration type + * (cast to enum type if necessary)\n + * Returns @c 0 or @c 1 (for false/true) for binary Unicode properties\n + * Returns a bit-mask for mask properties \n + * Returns @c 0 if @a which is out of bounds or if the Unicode version does + * not have data for the property at all, or not for this code point. * - * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_NONE Successful * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter */ int i18n_uchar_get_int_property_value(i18n_uchar32 c, i18n_uchar_uproperty_e which, int32_t *property_val); @@ -155,14 +158,36 @@ int i18n_uchar_get_int_property_value(i18n_uchar32 c, i18n_uchar_uproperty_e whi * @brief Gets the Unicode allocation block that contains the character. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * - * @param[in] c The code point to test - * @param[out] block_val The block value for the code point + * @param[in] c The code point to test + * @param[out] block_val The block value for the code point * - * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_NONE Successful * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter */ int i18n_uchar_get_ublock_code(i18n_uchar32 c, i18n_uchar_ublock_code_e *block_val); +/** + * @brief Gets the numeric value for a Unicode code point as defined in the Unicode Character Database. + * @details A "double" param type is necessary because some numeric values are fractions, negative, + * or too large for int32_t. For characters without any numeric values in the Unicode + * Character Database, @a numeric_val will be equal to #I18N_U_NO_NUMERIC_VALUE. + * Note: This is different from the Unicode Standard which specifies NaN as the default + * value. (NaN is not available on all platforms) This function is similar to + * java.lang.Character.getNumericValue(), but i18n_uchar_get_numeric_value() also supports + * negative values, large values, and fractions, while Java's getNumericValue() returns + * values 10..35 for ASCII letters. + * @since_tizen 4.0 + * + * @param[in] c The code point to get the numeric value for + * @param[out] numeric_val The numeric value of @a c or #I18N_U_NO_NUMERIC_VALUE if none is defined + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @see #I18N_U_NO_NUMERIC_VALUE + */ +int i18n_uchar_get_numeric_value(i18n_uchar32 c, double *numeric_val); + #ifdef __cplusplus } #endif diff --git a/src/utils_i18n_uchar.c b/src/utils_i18n_uchar.c index 7f299a0..25144e2 100644 --- a/src/utils_i18n_uchar.c +++ b/src/utils_i18n_uchar.c @@ -34,3 +34,12 @@ int i18n_uchar_get_ublock_code(i18n_uchar32 c, i18n_uchar_ublock_code_e *block_v return I18N_ERROR_NONE; } + +int i18n_uchar_get_numeric_value(i18n_uchar32 c, double *numeric_val) +{ + retv_if(numeric_val == NULL, I18N_ERROR_INVALID_PARAMETER); + *numeric_val = u_getNumericValue(c); + + return I18N_ERROR_NONE; +} + -- 2.7.4