[ACR-1494][Unumsys] Module implementation 10/222910/4
authorHyunjee Kim <hj0426.kim@samsung.com>
Tue, 21 Jan 2020 09:55:08 +0000 (18:55 +0900)
committerHyunjee Kim <hj0426.kim@samsung.com>
Wed, 29 Jan 2020 01:49:34 +0000 (10:49 +0900)
Change-Id: Ica7385a526482e3fcd8d438412812e5e93a643bf
Signed-off-by: Hyunjee Kim <hj0426.kim@samsung.com>
src/CMakeLists.txt
src/include/utils_i18n.h
src/include/utils_i18n_private.h
src/include/utils_i18n_types.h
src/include/utils_i18n_unumsys.h [new file with mode: 0644]
src/utils_i18n_unumsys.c [new file with mode: 0644]

index 92b3655e54a4d298f70cef52f28b6f68204531b2..38e9e2f3d6452ac145033a94a25243fe59af678a 100755 (executable)
@@ -40,6 +40,7 @@ SET(BASEUTILS_SRCS
     utils_i18n_ubidi.c
     utils_i18n_uversion.c
     utils_i18n_uchar_iter.c
+    utils_i18n_unumsys.c
     utils_i18n_plural_rules.cpp
     utils_i18n_plural_format.cpp
     utils_i18n_immutable_idx.cpp
@@ -101,5 +102,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_date_interval.h
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_date_interval_format.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_simple_date_format.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_loc_disp_names.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_unumsys.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pc_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
index 956055b7de1b1f15c12d42f90a2228ba36d5e59a..b1b876107f938747361525c4001c88c753134b82 100644 (file)
@@ -52,6 +52,7 @@
 #include <utils_i18n_date_interval_format.h>
 #include <utils_i18n_simple_date_format.h>
 #include <utils_i18n_loc_disp_names.h>
+#include <utils_i18n_unumsys.h>
 
 /**
  * @file utils_i18n.h
@@ -97,6 +98,7 @@ extern "C" {
  *       - date interval format
  *       - simple date format
  *       - locale display names
+ *       - numbering system
  *
  *        This module provides flexible generation of number or date format patterns and helps you format and parse dates/number for any locale.
  * The i18n module provides various features based on data from ICU. The following table shows the version of ICU used in each Tizen platform.
@@ -254,9 +256,15 @@ extern "C" {
  * <tr>
  *     <td>@ref CAPI_BASE_UTILS_I18N_SIMPLE_DATE_FORMAT_MODULE</td>
  *     <td>The Simple Date Format module provides API for formatting and parsing dates in language-independent manner.</td>
+ * </tr>
+ * <tr>
  *     <td>@ref CAPI_BASE_UTILS_I18N_LOCALE_DISPLAY_NAMES_MODULE</td>
  *     <td>The locale display names module returns display names of Locales and components of Locales.</td>
  * </tr>
+ * <tr>
+ *     <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *     <td>Numbering System</td>
+ * </tr>
  * </table>
  *
  * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table
@@ -4181,6 +4189,46 @@ extern "C" {
  *    <td>#i18n_loc_disp_names_get_key_value_disp_name</td>
  *    <td>keyValueDisplayName</td>
  * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_create</td>
+ *    <td>unumsys_open</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_create_by_name</td>
+ *    <td>unumsys_openByName</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_destroy</td>
+ *    <td>unumsys_close</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_create_available_names</td>
+ *    <td>unumsys_openAvailableNames</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_get_name</td>
+ *    <td>unumsys_getName</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_is_algorithmic</td>
+ *    <td>unumsys_isAlgorithmic</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_get_radix</td>
+ *    <td>unumsys_getRadix</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE</td>
+ *    <td>#i18n_unumsys_get_description</td>
+ *    <td>unumsys_getDescription</td>
+ * </tr>
  * </table>
  */
 
index 9b9cd402fea592e128a570bd56bf0eaa1b6a0418..2d9c1531932f75bd6c6b31acfd15220dd00b6303 100644 (file)
@@ -85,6 +85,7 @@ extern "C" {
                                (dst)[(dst_len) - 1] = '\0';            \
 } while (0)
 
+#define I18N_UPRV_LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
 #define ERR_MAPPING(ICU_ERROR, BASE_UTILS_ERROR) BASE_UTILS_ERROR = \
                                                                                                                                        (i18n_error_code_e)_i18n_error_mapping((int)ICU_ERROR)
 int _i18n_error_mapping(int err);
index 150fa741134d45570b4eb87593a3b8506958c6e0..05596803de04e9ce8b8795935a7b1b88c123d6fd 100644 (file)
@@ -4472,6 +4472,21 @@ typedef enum {
                                                     e.g. en_GB displays as 'British English' */
 } i18n_udialect_handling_e;
 
+/**
+ * @}
+ */
+
+/**
+* @addtogroup CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE
+* @{
+*/
+
+/**
+ * @brief An i18n_unumsys_h handle.
+ * @since_tizen 6.0
+ */
+typedef void *i18n_unumsys_h;
+
 /**
  * @}
  */
diff --git a/src/include/utils_i18n_unumsys.h b/src/include/utils_i18n_unumsys.h
new file mode 100644 (file)
index 0000000..cde87d9
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *       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.
+ */
+
+#ifndef __UTILS_I18N_UNUMSYS_H__
+#define __UTILS_I18N_UNUMSYS_H__
+
+#include <utils_i18n_types.h>
+
+/**
+ * @file utils_i18n_unumsys.h
+ * @version 0.1
+ * @brief utils_i18n_unumsys
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup CAPI_BASE_UTILS_I18N_MODULE
+ * @defgroup CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE UNumsys
+ * @brief C API: UNumberingSystem, information about numbering systems.
+ * @section CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE_HEADER Required Header
+ *     \#include <utils_i18n.h>
+ *
+ * @section CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE_OVERVIEW Overview
+ * @details Defines numbering systems. A numbering system describes the scheme by which numbers are to be presented to the end user.
+ *                     In its simplest form, a numbering system describes the set of digit characters that are to be used to display numbers,
+ *                     such as Western digits, Thai digits, Arabic-Indic digits, etc.,
+ *                     in a positional numbering system with a specified radix (typically 10).
+ *                     More complicated numbering systems are algorithmic in nature, and require use of an RBNF formatter (rule based number formatter),
+ *                     in order to calculate the characters to be displayed for a given number.
+ *                     Examples of algorithmic numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
+ *                     Formatting rules for many commonly used numbering systems are included in the ICU package,
+ *                     based on the numbering system rules defined in CLDR.
+ *                     Alternate numbering systems can be specified to a locale by using the numbers locale keyword.
+ *                     Formatting numbers is done using the @ref CAPI_BASE_UTILS_I18N_UNUMBER_MODULE API.
+ *
+ */
+
+/**
+ * @addtogroup CAPI_BASE_UTILS_I18N_UNUMSYS_MODULE
+ * @{
+ */
+
+/**
+ * @brief      Creates an #i18n_unumsys_h using the numbering system for the specified locale.
+ * @since_tizen 6.0
+ * @param[in] locale   The locale for which the default numbering system should be created.
+ * @param[out] unumsys An #i18n_unumsys_h handle for the specified locale, or NULL if an error occurred.
+ * @remarks The @a unumsys should be released using i18n_unumsys_destroy().
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_NOT_SUPPORTED A locale such as "en@numbers=xyz" that specifies a numbering system unknown to ICU.
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ *
+ */
+int i18n_unumsys_create(const char *locale, i18n_unumsys_h *unumsys);
+
+/**
+ * @brief      Creates an #i18n_unumsys_h using the name of one of the predefined numbering systems specified by CLDR and known to ICU,
+ *                     such as "latn", "arabext", or "hanidec"; the full list is returned by #i18n_unumsys_create_available_names.
+ * @since_tizen 6.0
+ * @param[in] name     The name of the numbering system for which an #i18n_unumsys_h should be created.
+ * @param[out] unumsys An #i18n_unumsys_h handle for the specified name, or NULL if an error occurred.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_NOT_SUPPORTED A numbering system unknown to ICU.
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ *
+ */
+int i18n_unumsys_create_by_name(const char *name, i18n_unumsys_h *unumsys);
+
+/**
+ * @brief      Destroys an #i18n_unumsys_h.
+ * @details Once closed it may no longer be used.
+ * @since_tizen 6.0
+ * @param[in] unumsys  The #i18n_unumsys_h to destroy.
+ *
+ */
+void i18n_unumsys_destroy(i18n_unumsys_h unumsys);
+
+/**
+ * @brief      Returns an enumeration over the names of all of the predefined numbering systems known to ICU.
+ * @details The numbering system names will be in alphabetical (invariant) order.
+ * @since_tizen 6.0
+ * @param[out] uenum   A pointer to a #i18n_uenumeration_h that must be closed with #i18n_uenumeration_destroy(), or NULL if an error occurred.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ */
+int i18n_unumsys_get_available_names(i18n_uenumeration_h *uenum);
+
+/**
+ * @brief      Returns the name of the specified #i18n_unumsys_h.
+ * @since_tizen 6.0
+ * @param[in] unumsys  The #i18n_unumsys_h whose name is desired.
+ * @param[out] name            A pointer to the name of the specified #i18n_unumsys_h, or NULL if the name is not one of the ICU predefined names.
+ *                                     The pointer is only valid for the lifetime of the #i18n_unumsys_h.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ */
+int i18n_unumsys_get_name(i18n_unumsys_h unumsys, const char **name);
+
+/**
+ * @brief      Returns whether the given #i18n_unumsys_h is for an algorithmic (not purely positional) system.
+ * @since_tizen 6.0
+ * @param[in] unumsys                  The #i18n_unumsys_h whose algorithmic status is desired.
+ * @param[out] is_algorithmic  TRUE if the specified #i18n_unumsys_h is for an algorithmic system.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ */
+int i18n_unumsys_is_algorithmic(i18n_unumsys_h unumsys, i18n_ubool *is_algorithmic);
+
+/**
+ * @brief      Returns the radix of the specified #i18n_unumsys_h.
+ * @details    Simple positional numbering systems typically have radix 10, but might have a radix of e.g. 16 for hexadecimal.
+ *                     The radix is less well-defined for non-positional algorithmic systems.
+ * @since_tizen 6.0
+ * @param[in] unumsys  The #i18n_unumsys_h whose radix is desired.
+ * @param[out] radix   The radix of the specified #i18n_unumsys_h.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ */
+int i18n_unumsys_get_radix(i18n_unumsys_h unumsys, int32_t *radix);
+
+/**
+ * @brief      Gets the description string of the specified #i18n_unumsys_h.
+ * @details For simple positional systems this is the ordered string of digits (with length matching the radix),
+ *                     e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D" for "hanidec";
+ *                     it would be "0123456789ABCDEF" for hexadecimal.
+ *
+ *                     For algorithmic systems this is the name of the RBNF ruleset used for formatting,
+ *                     e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for "grek".
+ * @since_tizen 6.0
+ * @param[in] unumsys                  The #i18n_unumsys_h whose description string is desired.
+ * @param[in] result                   A pointer to a buffer to receive the description string.
+ * @param[in] result_max_len   The maximum size of result.
+ * @param[out] ulen                            The total buffer size needed; if greater than result_length, the output was truncated.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ */
+int i18n_unumsys_get_description(i18n_unumsys_h unumsys, i18n_uchar *result, int32_t result_max_len, int32_t *ulen);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ * @}
+ */
+#endif /* __UTILS_I18N_UNUMSYS_H__*/
diff --git a/src/utils_i18n_unumsys.c b/src/utils_i18n_unumsys.c
new file mode 100644 (file)
index 0000000..d206372
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+*       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 <unicode/unumsys.h>
+
+#include <utils_i18n_unumsys.h>
+#include <utils_i18n_private.h>
+
+int i18n_unumsys_create(const char *locale, i18n_unumsys_h *unumsys)
+{
+       i18n_error_code_e i18n_error;
+       UErrorCode icu_error = U_ZERO_ERROR;
+
+       *unumsys = (i18n_unumsys_h *)unumsys_open(locale, &icu_error);
+       ERR_MAPPING(icu_error, i18n_error);
+       I18N_ERR(i18n_error);
+
+       return i18n_error;
+}
+
+int i18n_unumsys_create_by_name(const char *name, i18n_unumsys_h *unumsys)
+{
+       i18n_error_code_e i18n_error;
+       UErrorCode icu_error = U_ZERO_ERROR;
+
+       *unumsys = (i18n_unumsys_h *)unumsys_openByName(name, &icu_error);
+       ERR_MAPPING(icu_error, i18n_error);
+       I18N_ERR(i18n_error);
+
+       return i18n_error;
+}
+
+void i18n_unumsys_destroy(i18n_unumsys_h unumsys)
+{
+       unumsys_close((UNumberingSystem *)unumsys);
+}
+
+int i18n_unumsys_get_available_names(i18n_uenumeration_h *uenum)
+{
+       i18n_error_code_e i18n_error;
+       UErrorCode icu_error = U_ZERO_ERROR;
+
+       *uenum = (i18n_uenumeration_h *)unumsys_openAvailableNames(&icu_error);
+       ERR_MAPPING(icu_error, i18n_error);
+       I18N_ERR(i18n_error);
+
+       return i18n_error;
+}
+
+int i18n_unumsys_get_name(i18n_unumsys_h unumsys, const char **name)
+{
+       i18n_error_code_e i18n_error;
+       UErrorCode icu_error = U_ZERO_ERROR;
+
+       *name = unumsys_getName(unumsys);
+       ERR_MAPPING(icu_error, i18n_error);
+       I18N_ERR(i18n_error);
+
+       return i18n_error;
+}
+
+int i18n_unumsys_is_algorithmic(i18n_unumsys_h unumsys, i18n_ubool *is_algorithmic)
+{
+       i18n_error_code_e i18n_error;
+       UErrorCode icu_error = U_ZERO_ERROR;
+
+       *is_algorithmic = (UBool)unumsys_isAlgorithmic(unumsys);
+       ERR_MAPPING(icu_error, i18n_error);
+       I18N_ERR(i18n_error);
+
+       return i18n_error;
+}
+
+int i18n_unumsys_get_radix(i18n_unumsys_h unumsys, int32_t *radix)
+{
+       i18n_error_code_e i18n_error;
+       UErrorCode icu_error = U_ZERO_ERROR;
+
+       *radix = unumsys_getRadix(unumsys);
+       ERR_MAPPING(icu_error, i18n_error);
+       I18N_ERR(i18n_error);
+
+       return i18n_error;
+}
+
+int i18n_unumsys_get_description(i18n_unumsys_h unumsys, i18n_uchar *result, int32_t result_max_len, int32_t *ulen)
+{
+       i18n_error_code_e i18n_error;
+       UErrorCode icu_error = U_ZERO_ERROR;
+
+       *ulen = unumsys_getDescription(unumsys, result, result_max_len, &icu_error);
+       ERR_MAPPING(icu_error, i18n_error);
+       I18N_ERR(i18n_error);
+
+       return i18n_error;
+
+}
+
+