From 5f36f3ac713a94b58bebdc558e428cfd22808265 Mon Sep 17 00:00:00 2001 From: Tomasz Bochenski Date: Thu, 27 Oct 2016 17:08:29 +0200 Subject: [PATCH] [Base-utils][Uversion][ACR-824] Module implementation added. Change-Id: I25710b75d6145ff1874143bac52969ee42dc7d24 Signed-off-by: Tomasz Bochenski --- packaging/capi-base-utils.spec | 2 +- src/CMakeLists.txt | 2 + src/include/utils_i18n.h | 68 ++++++++++++++------- src/include/utils_i18n_types.h | 42 +++++++++++++ src/include/utils_i18n_uversion.h | 120 ++++++++++++++++++++++++++++++++++++++ src/utils_i18n_ubidi.c | 7 +-- src/utils_i18n_uversion.c | 57 ++++++++++++++++++ 7 files changed, 271 insertions(+), 27 deletions(-) create mode 100644 src/include/utils_i18n_uversion.h create mode 100644 src/utils_i18n_uversion.c diff --git a/packaging/capi-base-utils.spec b/packaging/capi-base-utils.spec index 2d501ed..cb89430 100755 --- a/packaging/capi-base-utils.spec +++ b/packaging/capi-base-utils.spec @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 48fd25d..c635129 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/include/utils_i18n.h b/src/include/utils_i18n.h index 8694d84..4767ae8 100644 --- a/src/include/utils_i18n.h +++ b/src/include/utils_i18n.h @@ -43,6 +43,7 @@ #include #include #include +#include /** * @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" { * @ref CAPI_BASE_UTILS_I18N_UBIDI_MODULE * Ubidi module provides implementation of the Unicode Bidirectional Algorithm. * + * + * @ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE + * Uversion module provides API for accessing ICU version numbers. + * * * * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -3170,6 +3176,26 @@ extern "C" { * #i18n_ubidi_write_reverse * ubidi_writeReverse * + * + * @ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE + * #i18n_uversion_get_version + * u_getVersion + * + * + * @ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE + * #i18n_uversion_from_string + * u_versionFromString + * + * + * @ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE + * #i18n_uversion_from_ustring + * u_versionFromUString + * + * + * @ref CAPI_BASE_UTILS_I18N_UVERSION_MODULE + * #i18n_uversion_to_string + * u_versionToString + * * */ diff --git a/src/include/utils_i18n_types.h b/src/include/utils_i18n_types.h index fccb2c6..0f85c3b 100644 --- a/src/include/utils_i18n_types.h +++ b/src/include/utils_i18n_types.h @@ -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 index 0000000..916ce35 --- /dev/null +++ b/src/include/utils_i18n_uversion.h @@ -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 + +/** + * @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 + * + * @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__ */ diff --git a/src/utils_i18n_ubidi.c b/src/utils_i18n_ubidi.c index 03449b7..806f0c3 100644 --- a/src/utils_i18n_ubidi.c +++ b/src/utils_i18n_ubidi.c @@ -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 index 0000000..39263c8 --- /dev/null +++ b/src/utils_i18n_uversion.c @@ -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 +#include + +#include +#include + +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; +} -- 2.7.4