[Base-utils][Uchar][ACR-974] i18n_uchar_get_numeric_value() function added 37/129937/11
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Thu, 18 May 2017 11:09:03 +0000 (13:09 +0200)
committerDamian Pietruchowski <d.pietruchow@samsung.com>
Fri, 9 Jun 2017 10:52:19 +0000 (12:52 +0200)
Change-Id: Ie4c0195e849711ad840925210edb9ab2994c6d4b
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
src/include/utils_i18n.h
src/include/utils_i18n_types.h
src/include/utils_i18n_uchar.h
src/utils_i18n_uchar.c

index dbc4994..9b3280c 100644 (file)
@@ -712,6 +712,11 @@ extern "C" {
  *       <td>ublock_getCode</td>
  * </tr>
  * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_UCHAR_MODULE</td>
+ *       <td>#i18n_uchar_get_numeric_value</td>
+ *       <td>u_getNumericValue</td>
+ * </tr>
+ * <tr>
  *       <td>@ref CAPI_BASE_UTILS_I18N_UCOLLATOR_MODULE</td>
  *       <td>#i18n_ucollator_create</td>
  *       <td>ucol_open</td>
index 23a3e11..660e904 100644 (file)
@@ -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)       /**<Mask constant for multiple #i18n_uchar_category_e bits (P Punctuation). @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif*/
 #define I18N_U_GC_S_MASK                                         (I18N_U_GC_SM_MASK|I18N_U_GC_SC_MASK|I18N_U_GC_SK_MASK|I18N_U_GC_SO_MASK)                     /**<Mask constant for multiple #i18n_uchar_category_e bits (S Symbols). @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif       */
 
-#define I18N_U_NO_NUMERIC_VALUE                                  ((double)-123456789.)                 /**< Special value that is returned by i18n_uchar_get_numeric_value()(not implemented yet) when no numeric value is defined for a code point. @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif  */
+#define I18N_U_NO_NUMERIC_VALUE                                  ((double)-123456789.)                 /**< Special value that is returned by i18n_uchar_get_numeric_value() when no numeric value is defined for a code point. @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif       */
 
 #define I18N_U_GET_GC_MASK(c)                            I18N_U_MASK(u_charType(c))    /**< Get a single-bit bit set for the general category of a character. @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif  */
 
index c104e23..0b746a6 100644 (file)
@@ -134,19 +134,22 @@ extern "C" {
  *        </code>
  * @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
+ *                          <code>#I18N_UCHAR_BINARY_START <= @a which < #I18N_UCHAR_BINARY_LIMIT</code>
+ *                          or <code>#I18N_UCHAR_INT_START <= @a which < #I18N_UCHAR_INT_LIMIT</code>
+ *                          or <code>#I18N_UCHAR_MASK_START <= @a which < #I18N_UCHAR_MASK_LIMIT</code>.
  * @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
index 7f299a0..25144e2 100644 (file)
@@ -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;
+}
+