[Base-utils][Uversion][ACR-824] Module implementation added. 29/94229/16
authorTomasz Bochenski <t.bochenski@samsung.com>
Thu, 27 Oct 2016 15:08:29 +0000 (17:08 +0200)
committerTomasz Bochenski <t.bochenski@samsung.com>
Mon, 23 Jan 2017 12:07:23 +0000 (13:07 +0100)
Change-Id: I25710b75d6145ff1874143bac52969ee42dc7d24
Signed-off-by: Tomasz Bochenski <t.bochenski@samsung.com>
packaging/capi-base-utils.spec
src/CMakeLists.txt
src/include/utils_i18n.h
src/include/utils_i18n_types.h
src/include/utils_i18n_uversion.h [new file with mode: 0644]
src/utils_i18n_ubidi.c
src/utils_i18n_uversion.c [new file with mode: 0644]

index 2d501ed..cb89430 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-base-utils
 Summary:    Base Utils
-Version:    2.0.0
+Version:    2.0.1
 Release:    1
 Group:      Base
 License:    Apache-2.0 and ICU
index 48fd25d..c635129 100755 (executable)
@@ -38,6 +38,7 @@ SET(BASEUTILS_SRCS
     utils_i18n_ushape.c
     utils_i18n_utmscale.c
     utils_i18n_ubidi.c
+    utils_i18n_uversion.c
 )
 
 ADD_LIBRARY(${target_name} SHARED ${BASEUTILS_SRCS}
@@ -83,5 +84,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_parse_position.h
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ushape.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_utmscale.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ubidi.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_uversion.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 8694d84..4767ae8 100644 (file)
@@ -43,6 +43,7 @@
 #include <utils_i18n_ushape.h>
 #include <utils_i18n_utmscale.h>
 #include <utils_i18n_ubidi.h>
+#include <utils_i18n_uversion.h>
 
 /**
  * @file utils_i18n.h
@@ -58,27 +59,28 @@ extern "C" {
  * @ingroup CAPI_BASE_UTILS_MODULE
  * @defgroup CAPI_BASE_UTILS_I18N_MODULE i18n
  * @brief The i18n module contains:
- *              - uchar
- *              - ucollator
- *              - unormalization
- *              - usearch
- *              - ustring
- *              - ucalendar
- *              - udate
- *              - udatepg
- *              - ulocale
- *              - unumber
- *              - alpha_idx
- *              - formattable
- *              - measure unit
- *              - measure
- *              - format
- *              - measure format
- *              - field position
- *              - parse position
- *              - ushape
- *              - utmscale
- *              - ubidi
+ *       - uchar
+ *       - ucollator
+ *       - unormalization
+ *       - usearch
+ *       - ustring
+ *       - ucalendar
+ *       - udate
+ *       - udatepg
+ *       - ulocale
+ *       - unumber
+ *       - alpha_idx
+ *       - formattable
+ *       - measure unit
+ *       - measure
+ *       - format
+ *       - measure format
+ *       - field position
+ *       - parse position
+ *       - ushape
+ *       - utmscale
+ *       - ubidi
+ *       - uversion
  *
  *        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.
@@ -205,6 +207,10 @@ extern "C" {
  *       <td>@ref CAPI_BASE_UTILS_I18N_UBIDI_MODULE</td>
  *       <td>Ubidi module provides implementation of the Unicode Bidirectional Algorithm.</td>
  * </tr>
+ * <tr>
+ *     <td>@ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE</td>
+ *     <td>Uversion module provides API for accessing ICU version numbers.</td>
+ * </tr>
  * </table>
  *
  * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table
@@ -3170,6 +3176,26 @@ extern "C" {
  *       <td>#i18n_ubidi_write_reverse</td>
  *       <td>ubidi_writeReverse</td>
  * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE</td>
+ *    <td>#i18n_uversion_get_version</td>
+ *    <td>u_getVersion</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE</td>
+ *    <td>#i18n_uversion_from_string</td>
+ *    <td>u_versionFromString</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE</td>
+ *    <td>#i18n_uversion_from_ustring</td>
+ *    <td>u_versionFromUString</td>
+ * </tr>
+ * <tr>
+ *    <td>@ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE</td>
+ *    <td>#i18n_uversion_to_string</td>
+ *    <td>u_versionToString</td>
+ * </tr>
  * </table>
  */
 
index fccb2c6..0f85c3b 100644 (file)
@@ -3919,6 +3919,48 @@ typedef enum {
  * @}
  */
 
+
+/**
+ * @addtogroup CAPI_BASE_UTILS_I18N_UVERSION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Maximum length of the copyright string.
+ * @since_tizen 4.0
+ */
+#define I18N_UVERSION_COPYRIGHT_STRING_LENGTH 128
+
+/**
+ * @brief Maximum number of numbers ICU version consists of.
+ * @details Each number has value from 0 to 255.
+ * @since_tizen 4.0
+ */
+#define I18N_UVERSION_MAX_VERSION_LENGTH 4
+
+/**
+ * @brief The maximum length of an ICU version string.
+ * @since_tizen 4.0
+ */
+#define I18N_UVERSION_MAX_VERSION_STRING_LENGTH 20
+
+/**
+ * @brief Delimiter used to delimit ICU version fields in a string.
+ * @since_tizen 4.0
+ */
+#define I18N_UVERSION_DELIMITER '.'
+
+/**
+ * @brief The binary form of a version on ICU APIs.
+ * @details To compare two versions, use memcmp(v1,v2,sizeof(i18n_uversion_info)).
+ * @since_tizen 4.0
+ */
+typedef uint8_t i18n_uversion_info[I18N_UVERSION_MAX_VERSION_LENGTH];
+
+/**
+ * @}
+ */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/include/utils_i18n_uversion.h b/src/include/utils_i18n_uversion.h
new file mode 100644 (file)
index 0000000..916ce35
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2016 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_UVERSION_H__
+#define __UTILS_I18N_UVERSION_H__
+
+#include <utils_i18n_types.h>
+
+/**
+ * @file utils_i18n_uversion.h
+ * @version 0.1
+ * @brief utils_i18n_uversion
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup CAPI_BASE_UTILS_I18N_MODULE
+ * @defgroup CAPI_BASE_UTILS_I18N_UVERSION_MODULE Uversion
+ * @brief Uversion module provides API for accessing ICU version numbers.
+ *
+ * @section CAPI_BASE_UTILS_I18N_UVERSION_MODULE_HEADER Required Header
+ *  \#include <utils_i18n.h>
+ *
+ * @section CAPI_BASE_UTILS_I18N_UVERSION_MODULE_OVERVIEW Overview
+ * @details Uversion module provides API for accessing ICU version numbers.
+ */
+
+/**
+ * @addtogroup CAPI_BASE_UTILS_I18N_UVERSION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Gets the ICU release version.
+ * @details The version array stores the version information for ICU. For example, release
+ *          "1.3.31.2" is then represented as 0x01031F02.
+ * @since_tizen 4.0
+ *
+ * @param[out]   version_array    An array which will contain the version
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_uversion_get_version(i18n_uversion_info version_array);
+
+/**
+ * @brief Parses a string with dotted-decimal version information and fills in an #i18n_uversion_info
+ *        array with the result.
+ * @since_tizen 4.0
+ *
+ * @param[in]     version_string    A string with dotted-decimal version information, with up to
+ *                                  #I18N_UVERSION_MAX_VERSION_LENGTH non-negative number fields
+ *                                  with values of up to 255 each
+ * @param[out]    version_array     An array which will contain the version
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_uversion_from_string(const char *version_string, i18n_uversion_info version_array);
+
+/**
+ * @brief Parses a Unicode string with dotted-decimal version information and fills in
+ *        an #i18n_uversion_info array with the result.
+ * @since_tizen 4.0
+ *
+ * @param[in]     version_string    A Unicode string with dotted-decimal version information,
+ *                                  with up to #I18N_UVERSION_MAX_VERSION_LENGTH non-negative
+ *                                  number fields with values of up to 255 each
+ * @param[out]    version_array     An array which will contain the version
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_uversion_from_ustring(const i18n_uchar *version_string, i18n_uversion_info version_array);
+
+/**
+ * @brief Writes a string with dotted-decimal version information according to the input
+ *        #i18n_uversion_info object.
+ * @since_tizen 4.0
+ *
+ * @param[in]     version_array     The version information to be written as a string.
+ * @param[out]    version_string    A string buffer that will be filled in with a string
+ *                                  corresponding to the numeric version information in
+ *                                  @a version_array. The buffer size must be at least
+ *                                  #I18N_UVERSION_MAX_VERSION_STRING_LENGTH.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_uversion_to_string(const i18n_uversion_info version_array, char *version_string);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UTILS_I18N_UVERSION_H__ */
index 03449b7..806f0c3 100644 (file)
@@ -263,11 +263,8 @@ int i18n_ubidi_get_text(const i18n_ubidi_h ubidi, char **text)
         * UTF-16 uses at least two bytes, growing up to four bytes as necessary,
         * that is why we multiply UChar by 4.
         */
-       char *_text = NULL;
-       _text = (char *)malloc(4 * ulen + 1);
-       retv_if(_text == NULL, I18N_ERROR_OUT_OF_MEMORY);
-       memset(_text, 0x0, 4 * ulen + 1);
-
+       char _text[4*ulen+4];
+       memset(_text, 0x0, 4 * ulen + 4);
        u_austrcpy(_text, _ubidi_text);
 
        int32_t len = strlen(_text);
diff --git a/src/utils_i18n_uversion.c b/src/utils_i18n_uversion.c
new file mode 100644 (file)
index 0000000..39263c8
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016 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/umachine.h>
+#include <unicode/uvernum.h>
+
+#include <utils_i18n_uversion.h>
+#include <utils_i18n_private.h>
+
+int i18n_uversion_get_version(i18n_uversion_info version_array)
+{
+       retv_if(version_array == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+       u_getVersion(version_array);
+
+       return I18N_ERROR_NONE;
+}
+
+int i18n_uversion_from_string(const char *version_string, i18n_uversion_info version_array)
+{
+       retv_if(version_string == NULL || version_array == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+       u_versionFromString(version_array, version_string);
+
+       return I18N_ERROR_NONE;
+}
+
+int i18n_uversion_from_ustring(const i18n_uchar *version_string, i18n_uversion_info version_array)
+{
+       retv_if(version_string == NULL || version_array == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+       u_versionFromUString(version_array, version_string);
+
+       return I18N_ERROR_NONE;
+}
+
+int i18n_uversion_to_string(const i18n_uversion_info version_array, char *version_string)
+{
+       retv_if(version_string == NULL || version_array == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+       u_versionToString(version_array, version_string);
+
+       return I18N_ERROR_NONE;
+}