From e677218031eadd3d2909d796a2a9daa757d4c2b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Szczekutek?= Date: Mon, 27 Jun 2016 15:19:17 +0200 Subject: [PATCH] [Base-utils][Formattable] Complete module added MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit implementation + documentation Author: Rafał Szczekutek Change-Id: I88144a36d76058eb18059c7862e0dffa691b529c Signed-off-by: Beata Stefaniuk --- src/CMakeLists.txt | 4 +- src/include/mobile/utils_i18n.h | 136 +++++++- src/include/mobile/utils_i18n_formattable.h | 466 ++++++++++++++++++++++++++ src/include/wearable/utils_i18n.h | 136 +++++++- src/include/wearable/utils_i18n_formattable.h | 466 ++++++++++++++++++++++++++ src/utils_i18n_formattable.cpp | 338 +++++++++++++++++++ 6 files changed, 1543 insertions(+), 3 deletions(-) create mode 100644 src/include/mobile/utils_i18n_formattable.h create mode 100644 src/include/wearable/utils_i18n_formattable.h create mode 100644 src/utils_i18n_formattable.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a23693..cb1b4e6 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,6 +34,7 @@ SET(BASEUTILS_SRCS utils_i18n_ubrk.c utils_i18n_timezone.cpp utils_i18n_alpha_idx.cpp + utils_i18n_formattable.cpp ) ADD_LIBRARY(${target_name} SHARED ${BASEUTILS_SRCS} @@ -69,5 +70,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_uenumeration.h D INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_uset.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ubrk.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_alpha_idx.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_formattable.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) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pc_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) \ No newline at end of file diff --git a/src/include/mobile/utils_i18n.h b/src/include/mobile/utils_i18n.h index 13b23bc..26ddbec 100644 --- a/src/include/mobile/utils_i18n.h +++ b/src/include/mobile/utils_i18n.h @@ -33,6 +33,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -47,7 +48,7 @@ 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 and alpha_idx. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx and formattable. * 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. * @@ -127,6 +128,9 @@ extern "C" { * * * + * + * + * * *
@ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULEAlpha_idx supports the creation of a UI index appropriate for a given language.
@ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULEFormattable interconverts between the primitive numeric types (double, long, etc.) as well as the #i18n_udate and char string.
* @@ -1913,6 +1917,136 @@ extern "C" { * #i18n_alpha_idx_reset_record_iter * resetRecordIterator * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_default + * Formattable() + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_udate + * Formattable(UDate d, ISDATE flag) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_double + * Formattable(double d) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_long + * Formattable(int32_t l) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_int64 + * Formattable(int64_t ll) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_char_string + * Formattable(const char* strToCopy) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_formattable_array + * Formattable(const Formattable* arrayToCopy, int32_t count) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_destroy + * delete + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_clone + * Formattable::clone + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_array + * Formattable::getArray + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_date + * Formattable::getDate + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_double + * Formattable::getDouble + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_int64 + * Formattable::getInt64 + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_long + * Formattable::getLong + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_string + * Formattable::getString + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_type + * Formattable::getType + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_is_numeric + * Formattable::isNumeric + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_not_equal + * Formattable::operator!= + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_equal + * Formattable::operator== + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_element_at + * Formattable::operator[] + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_array + * Formattable::setArray + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_date + * Formattable::setDate + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_double + * Formattable::setDouble + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_int64 + * Formattable::setInt64 + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_long + * Formattable::setLong + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_string + * Formattable::setString + * * */ diff --git a/src/include/mobile/utils_i18n_formattable.h b/src/include/mobile/utils_i18n_formattable.h new file mode 100644 index 0000000..c7abfab --- /dev/null +++ b/src/include/mobile/utils_i18n_formattable.h @@ -0,0 +1,466 @@ +/* + * 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_FORMATTABLE_H_ +#define UTILS_I18N_FORMATTABLE_H_ + +#include + +/** + * @file utils_i18n_formattable.h + * @version 0.1 + * @brief utils_i18n_formattable + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE Formattable + * @brief Formattable interconverts between the primitive numeric types + * (double, long, etc.) as well as #i18n_udate and char string. + * + * @section CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE_OVERVIEW Overview + * @details Internally, an #i18n_formattable_h handle holds an object + * that is a union of primitive types. + * As such, it can only store one flavor of data at a time. + * To determine what flavor of data it contains, use the + * #i18n_formattable_get_type function. + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * @{ + */ + +/** + * @brief Creates a new default #i18n_formattable_h. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_default(i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with an #i18n_udate instance. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] date The #i18n_udate instance + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_udate(i18n_udate date, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with a double number. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] d The double number + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_double(double d, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with a long number. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] l The long number + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_long(int32_t l, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with an int64_t number. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] ll The int64_t number + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_int64(int64_t ll, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with a char string pointer. + * @details Assumes that the char string is null terminated. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] str_to_copy The char string + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_char_string(const char *str_to_copy, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with an array of + * #i18n_formattable_h handles. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] array_to_copy An array with the #i18n_formattable_h handles + * @param[in] count The number of the elements in the array + * @param[out] formattable A pointer to a handle to the newly created + * formattable object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_formattable_array(const i18n_formattable_h *array_to_copy, int32_t count, i18n_formattable_h *formattable); + +/** + * @brief Releases the given #i18n_formattable_h handle. + * + * @param[in] formattable A handle to the formattable object to be released + * + * @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_formattable_destroy(i18n_formattable_h formattable); + +/** + * @brief Clones the given formattable handle with the related object to the + * @a clone handle. + * @details Clones can be used concurrently in multiple threads. + * @remarks The cloned object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] formattable A handle to the formattable object + * @param[out] clone A pointer to a handle to the formattable object which + * will be filled with a copy of the @a formattable handle. + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_clone(i18n_formattable_h formattable, i18n_formattable_h *clone); + +/** + * @brief Gets the array value and count of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_ARRAY then the + * result is undefined. The obtained array should be released by the + * caller with the free() function. + * + * @param[in] formattable A handle to the formattable object + * @param[out] array A pointer to an array of #i18n_formattable_h handles + * @param[out] count A pointer to an int32_t variable which will be filled + * with the number of array's elements + * + * @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_formattable_get_array(i18n_formattable_h formattable, i18n_formattable_h **array, int32_t *count); + +/** + * @brief Gets the date value of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_DATE then the + * result is undefined. + * + * @param[in] formattable A handle to the formattable object + * @param[out] date A pointer to an i18n_udate object which will be filled + * with the date obtained from the given formattable object + * + * @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_formattable_get_date(i18n_formattable_h formattable, i18n_udate *date); + +/** + * @brief Gets the double value of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_DOUBLE then the + * result is undefined. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to a double variable which will be filled + * with the value obtained from the given formattable object + * + * @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_formattable_get_double(i18n_formattable_h formattable, double *value); + +/** + * @brief Gets the int64 value of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_INT64 then the + * result is undefined. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to an int64_t variable which will be filled + * with the value obtained from the given formattable object + * + * @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_formattable_get_int64(i18n_formattable_h formattable, int64_t *value); + +/** + * @brief Gets the long value of the given formattable object. + * @details If the magnitude is too large to fit in a long, then the maximum or + * minimum long value, as appropriate, is set to @value variable and + * the #I18N_ERROR_INVALID_FORMAT error code is returned by the + * function. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to a int32_t variable which will be filled + * with the value obtained from the given formattable object + * + * @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_formattable_get_long(i18n_formattable_h formattable, int32_t *value); + +/** + * @brief Gets the string value of the given formattable object. + * @remarks If the type is not a string, the function returns the + * #I18N_ERROR_INVALID_FORMAT error code and the value is set to @c + * NULL. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to a char string variable which will be + * filled with the value obtained from the given formattable object + * + * @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_INVALID_FORMAT The given formattable type is not a string + * @retval #I18N_ERROR_UNKNOWN Unknown error + */ +int i18n_formattable_get_string(i18n_formattable_h formattable, char **value); + +/** + * @brief Gets the data type of the given formattable object. + * + * @param[in] formattable A handle to the formattable object + * @param[out] type A pointer to an #i18n_formattable_type_e variable which + * will be filled with the type obtained from the given formattable + * object + * + * @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_formattable_get_type(i18n_formattable_h formattable, i18n_formattable_type_e *type); + +/** + * @brief Sets the variable pointed by the @a is_numeric pointer to @c true if + * the data type of the given formattable object is #I18N_FORMATTABLE_K_DOUBLE, + * #I18N_FORMATTABLE_K_LONG or #I18N_FORMATTABLE_K_INT64. + * + * @param[in] formattable A handle to the formattable object + * @param[out] is_numeric A pointer to a boolean variable which will be filled by + * the function + * + * @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_formattable_is_numeric(i18n_formattable_h formattable, bool *is_numeric); + +/** + * @brief Sets the variable pointed by the @a not_equal pointer to @c true if + * the given @a formattable object is not equal to the given @a other + * formattable object. + * + * @param[in] formattable A handle to the formattable object + * @param[in] other A handle to the other formattable object + * @param[out] not_equal A pointer to a boolean variable which will be filled by + * the function + * + * @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_formattable_not_equal(i18n_formattable_h formattable, i18n_formattable_h other, bool *not_equal); + +/** + * @brief Sets the variable pointed by the @a equal pointer to @c true if the + * given @a formattable object is equal to the given @a other + * formattable object. + * + * @param[in] formattable A handle to the formattable object + * @param[in] other A handle to the other formattable object + * @param[out] equal A pointer to a boolean variable which will be filled by + * the function + * + * @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_formattable_equal(i18n_formattable_h formattable, i18n_formattable_h other, bool *equal); + +/** + * @brief Sets the object pointed by the @a element pointer to the element at + * the @a index position in the array stored by the given formattable + * object (if its type is #I18N_FORMATTABLE_K_ARRAY). + * @remarks If this object is not of type #I18N_FORMATTABLE_K_ARRAY then the + * result is undefined. + * + * The obtained formattable element should not be released by the caller + * as it belongs to the given formattable object of type #I18N_FORMATTABLE_K_ARRAY. + * + * @param[in] formattable A handle to the formattable object + * @param[in] index A number representing the position in the array from + * which the element should be obtained + * @param[out] element A pointer to a handle to the formattable object which + * will be filled by the function + * + * @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_INDEX_OUTOFBOUNDS Index value out of range + * @retval #I18N_ERROR_INVALID_FORMAT The given formattable type is not an array + */ +int i18n_formattable_element_at(i18n_formattable_h formattable, int32_t index, i18n_formattable_h *element); + +/** + * @brief Sets the array value and count of the given formattable object and + * changes the type to #I18N_FORMATTABLE_K_ARRAY. + * + * @param[in] formattable A handle to the formattable object + * @param[in] array An array of handles to the formattable objects + * @param[in] count The number of array elements to be copied + * + * @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_formattable_set_array(i18n_formattable_h formattable, const i18n_formattable_h *array, int32_t count); + +/** + * @brief Sets the date value of the given formattable object and changes the + * type to the #I18N_FORMATTABLE_K_DATE. + * + * @param[in] formattable A handle to the formattable object + * @param[in] d The new i18n_udate value to be set + * + * @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_formattable_set_date(i18n_formattable_h formattable, i18n_udate d); + +/** + * @brief Sets the double value of the given formattable object and changes + * the type to the #I18N_FORMATTABLE_K_DOUBLE. + * + * @param[in] formattable A handle to the formattable object + * @param[in] d The new double value to be set + * + * @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_formattable_set_double(i18n_formattable_h formattable, double d); + +/** + * @brief Sets the int64 value of the given formattable object and changes the + * type to the #I18N_FORMATTABLE_K_INT64. + * + * @param[in] formattable A handle to the formattable object + * @param[in] ll The new int64_t value to be set + * + * @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_formattable_set_int64(i18n_formattable_h formattable, int64_t ll); + +/** + * @brief Sets the long value of the given formattable object and changes the + * type to the #I18N_FORMATTABLE_K_LONG. + * + * @param[in] formattable A handle to the formattable object + * @param[in] l The new int32_t value to be set + * + * @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_formattable_set_long(i18n_formattable_h formattable, int32_t l); + +/** + * @brief Sets the string value of the given formattable object and changes + * the type to the #I18N_FORMATTABLE_K_STRING. + * + * @param[in] formattable A handle to the formattable object + * @param[in] string_to_copy The new string value to be set + * + * @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_formattable_set_string(i18n_formattable_h formattable, const char *string_to_copy); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* UTILS_I18N_FORMATTABLE_H_ */ diff --git a/src/include/wearable/utils_i18n.h b/src/include/wearable/utils_i18n.h index 13b23bc..26ddbec 100644 --- a/src/include/wearable/utils_i18n.h +++ b/src/include/wearable/utils_i18n.h @@ -33,6 +33,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -47,7 +48,7 @@ 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 and alpha_idx. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx and formattable. * 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. * @@ -127,6 +128,9 @@ extern "C" { * * * + * + * + * * *
@ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULEAlpha_idx supports the creation of a UI index appropriate for a given language.
@ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULEFormattable interconverts between the primitive numeric types (double, long, etc.) as well as the #i18n_udate and char string.
* @@ -1913,6 +1917,136 @@ extern "C" { * #i18n_alpha_idx_reset_record_iter * resetRecordIterator * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_default + * Formattable() + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_udate + * Formattable(UDate d, ISDATE flag) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_double + * Formattable(double d) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_long + * Formattable(int32_t l) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_int64 + * Formattable(int64_t ll) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_char_string + * Formattable(const char* strToCopy) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_create_with_formattable_array + * Formattable(const Formattable* arrayToCopy, int32_t count) + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_destroy + * delete + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_clone + * Formattable::clone + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_array + * Formattable::getArray + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_date + * Formattable::getDate + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_double + * Formattable::getDouble + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_int64 + * Formattable::getInt64 + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_long + * Formattable::getLong + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_string + * Formattable::getString + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_get_type + * Formattable::getType + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_is_numeric + * Formattable::isNumeric + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_not_equal + * Formattable::operator!= + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_equal + * Formattable::operator== + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_element_at + * Formattable::operator[] + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_array + * Formattable::setArray + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_date + * Formattable::setDate + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_double + * Formattable::setDouble + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_int64 + * Formattable::setInt64 + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_long + * Formattable::setLong + * + * + * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * #i18n_formattable_set_string + * Formattable::setString + * * */ diff --git a/src/include/wearable/utils_i18n_formattable.h b/src/include/wearable/utils_i18n_formattable.h new file mode 100644 index 0000000..c7abfab --- /dev/null +++ b/src/include/wearable/utils_i18n_formattable.h @@ -0,0 +1,466 @@ +/* + * 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_FORMATTABLE_H_ +#define UTILS_I18N_FORMATTABLE_H_ + +#include + +/** + * @file utils_i18n_formattable.h + * @version 0.1 + * @brief utils_i18n_formattable + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE Formattable + * @brief Formattable interconverts between the primitive numeric types + * (double, long, etc.) as well as #i18n_udate and char string. + * + * @section CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE_OVERVIEW Overview + * @details Internally, an #i18n_formattable_h handle holds an object + * that is a union of primitive types. + * As such, it can only store one flavor of data at a time. + * To determine what flavor of data it contains, use the + * #i18n_formattable_get_type function. + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE + * @{ + */ + +/** + * @brief Creates a new default #i18n_formattable_h. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_default(i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with an #i18n_udate instance. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] date The #i18n_udate instance + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_udate(i18n_udate date, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with a double number. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] d The double number + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_double(double d, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with a long number. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] l The long number + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_long(int32_t l, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with an int64_t number. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] ll The int64_t number + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_int64(int64_t ll, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with a char string pointer. + * @details Assumes that the char string is null terminated. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] str_to_copy The char string + * @param[out] formattable A pointer to a handle to the newly created formattable + * object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_char_string(const char *str_to_copy, i18n_formattable_h *formattable); + +/** + * @brief Creates a new #i18n_formattable_h handle with an array of + * #i18n_formattable_h handles. + * @remarks The created object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] array_to_copy An array with the #i18n_formattable_h handles + * @param[in] count The number of the elements in the array + * @param[out] formattable A pointer to a handle to the newly created + * formattable object + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_create_with_formattable_array(const i18n_formattable_h *array_to_copy, int32_t count, i18n_formattable_h *formattable); + +/** + * @brief Releases the given #i18n_formattable_h handle. + * + * @param[in] formattable A handle to the formattable object to be released + * + * @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_formattable_destroy(i18n_formattable_h formattable); + +/** + * @brief Clones the given formattable handle with the related object to the + * @a clone handle. + * @details Clones can be used concurrently in multiple threads. + * @remarks The cloned object should be released by the caller with the + * #i18n_formattable_destroy() function. + * + * @param[in] formattable A handle to the formattable object + * @param[out] clone A pointer to a handle to the formattable object which + * will be filled with a copy of the @a formattable handle. + * + * @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_UNKNOWN Unknown error + */ +int i18n_formattable_clone(i18n_formattable_h formattable, i18n_formattable_h *clone); + +/** + * @brief Gets the array value and count of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_ARRAY then the + * result is undefined. The obtained array should be released by the + * caller with the free() function. + * + * @param[in] formattable A handle to the formattable object + * @param[out] array A pointer to an array of #i18n_formattable_h handles + * @param[out] count A pointer to an int32_t variable which will be filled + * with the number of array's elements + * + * @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_formattable_get_array(i18n_formattable_h formattable, i18n_formattable_h **array, int32_t *count); + +/** + * @brief Gets the date value of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_DATE then the + * result is undefined. + * + * @param[in] formattable A handle to the formattable object + * @param[out] date A pointer to an i18n_udate object which will be filled + * with the date obtained from the given formattable object + * + * @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_formattable_get_date(i18n_formattable_h formattable, i18n_udate *date); + +/** + * @brief Gets the double value of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_DOUBLE then the + * result is undefined. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to a double variable which will be filled + * with the value obtained from the given formattable object + * + * @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_formattable_get_double(i18n_formattable_h formattable, double *value); + +/** + * @brief Gets the int64 value of the given formattable object. + * @remarks If this object is not of type #I18N_FORMATTABLE_K_INT64 then the + * result is undefined. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to an int64_t variable which will be filled + * with the value obtained from the given formattable object + * + * @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_formattable_get_int64(i18n_formattable_h formattable, int64_t *value); + +/** + * @brief Gets the long value of the given formattable object. + * @details If the magnitude is too large to fit in a long, then the maximum or + * minimum long value, as appropriate, is set to @value variable and + * the #I18N_ERROR_INVALID_FORMAT error code is returned by the + * function. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to a int32_t variable which will be filled + * with the value obtained from the given formattable object + * + * @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_formattable_get_long(i18n_formattable_h formattable, int32_t *value); + +/** + * @brief Gets the string value of the given formattable object. + * @remarks If the type is not a string, the function returns the + * #I18N_ERROR_INVALID_FORMAT error code and the value is set to @c + * NULL. + * + * @param[in] formattable A handle to the formattable object + * @param[out] value A pointer to a char string variable which will be + * filled with the value obtained from the given formattable object + * + * @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_INVALID_FORMAT The given formattable type is not a string + * @retval #I18N_ERROR_UNKNOWN Unknown error + */ +int i18n_formattable_get_string(i18n_formattable_h formattable, char **value); + +/** + * @brief Gets the data type of the given formattable object. + * + * @param[in] formattable A handle to the formattable object + * @param[out] type A pointer to an #i18n_formattable_type_e variable which + * will be filled with the type obtained from the given formattable + * object + * + * @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_formattable_get_type(i18n_formattable_h formattable, i18n_formattable_type_e *type); + +/** + * @brief Sets the variable pointed by the @a is_numeric pointer to @c true if + * the data type of the given formattable object is #I18N_FORMATTABLE_K_DOUBLE, + * #I18N_FORMATTABLE_K_LONG or #I18N_FORMATTABLE_K_INT64. + * + * @param[in] formattable A handle to the formattable object + * @param[out] is_numeric A pointer to a boolean variable which will be filled by + * the function + * + * @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_formattable_is_numeric(i18n_formattable_h formattable, bool *is_numeric); + +/** + * @brief Sets the variable pointed by the @a not_equal pointer to @c true if + * the given @a formattable object is not equal to the given @a other + * formattable object. + * + * @param[in] formattable A handle to the formattable object + * @param[in] other A handle to the other formattable object + * @param[out] not_equal A pointer to a boolean variable which will be filled by + * the function + * + * @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_formattable_not_equal(i18n_formattable_h formattable, i18n_formattable_h other, bool *not_equal); + +/** + * @brief Sets the variable pointed by the @a equal pointer to @c true if the + * given @a formattable object is equal to the given @a other + * formattable object. + * + * @param[in] formattable A handle to the formattable object + * @param[in] other A handle to the other formattable object + * @param[out] equal A pointer to a boolean variable which will be filled by + * the function + * + * @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_formattable_equal(i18n_formattable_h formattable, i18n_formattable_h other, bool *equal); + +/** + * @brief Sets the object pointed by the @a element pointer to the element at + * the @a index position in the array stored by the given formattable + * object (if its type is #I18N_FORMATTABLE_K_ARRAY). + * @remarks If this object is not of type #I18N_FORMATTABLE_K_ARRAY then the + * result is undefined. + * + * The obtained formattable element should not be released by the caller + * as it belongs to the given formattable object of type #I18N_FORMATTABLE_K_ARRAY. + * + * @param[in] formattable A handle to the formattable object + * @param[in] index A number representing the position in the array from + * which the element should be obtained + * @param[out] element A pointer to a handle to the formattable object which + * will be filled by the function + * + * @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_INDEX_OUTOFBOUNDS Index value out of range + * @retval #I18N_ERROR_INVALID_FORMAT The given formattable type is not an array + */ +int i18n_formattable_element_at(i18n_formattable_h formattable, int32_t index, i18n_formattable_h *element); + +/** + * @brief Sets the array value and count of the given formattable object and + * changes the type to #I18N_FORMATTABLE_K_ARRAY. + * + * @param[in] formattable A handle to the formattable object + * @param[in] array An array of handles to the formattable objects + * @param[in] count The number of array elements to be copied + * + * @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_formattable_set_array(i18n_formattable_h formattable, const i18n_formattable_h *array, int32_t count); + +/** + * @brief Sets the date value of the given formattable object and changes the + * type to the #I18N_FORMATTABLE_K_DATE. + * + * @param[in] formattable A handle to the formattable object + * @param[in] d The new i18n_udate value to be set + * + * @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_formattable_set_date(i18n_formattable_h formattable, i18n_udate d); + +/** + * @brief Sets the double value of the given formattable object and changes + * the type to the #I18N_FORMATTABLE_K_DOUBLE. + * + * @param[in] formattable A handle to the formattable object + * @param[in] d The new double value to be set + * + * @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_formattable_set_double(i18n_formattable_h formattable, double d); + +/** + * @brief Sets the int64 value of the given formattable object and changes the + * type to the #I18N_FORMATTABLE_K_INT64. + * + * @param[in] formattable A handle to the formattable object + * @param[in] ll The new int64_t value to be set + * + * @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_formattable_set_int64(i18n_formattable_h formattable, int64_t ll); + +/** + * @brief Sets the long value of the given formattable object and changes the + * type to the #I18N_FORMATTABLE_K_LONG. + * + * @param[in] formattable A handle to the formattable object + * @param[in] l The new int32_t value to be set + * + * @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_formattable_set_long(i18n_formattable_h formattable, int32_t l); + +/** + * @brief Sets the string value of the given formattable object and changes + * the type to the #I18N_FORMATTABLE_K_STRING. + * + * @param[in] formattable A handle to the formattable object + * @param[in] string_to_copy The new string value to be set + * + * @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_formattable_set_string(i18n_formattable_h formattable, const char *string_to_copy); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* UTILS_I18N_FORMATTABLE_H_ */ diff --git a/src/utils_i18n_formattable.cpp b/src/utils_i18n_formattable.cpp new file mode 100644 index 0000000..90ae8a6 --- /dev/null +++ b/src/utils_i18n_formattable.cpp @@ -0,0 +1,338 @@ +/* + * 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_formattable_create_default(i18n_formattable_h *formattable) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + *formattable = new Formattable(); + retv_if(*formattable == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_create_with_udate(i18n_udate date, i18n_formattable_h *formattable) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + *formattable = new Formattable(date, Formattable::kIsDate); + retv_if(*formattable == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_create_with_double(double d, i18n_formattable_h *formattable) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + *formattable = new Formattable(d); + retv_if(*formattable == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_create_with_long(int32_t l, i18n_formattable_h *formattable) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + *formattable = new Formattable(l); + retv_if(*formattable == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_create_with_int64(int64_t ll, i18n_formattable_h *formattable) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + *formattable = new Formattable(ll); + retv_if(*formattable == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_create_with_char_string(const char *str_to_copy, i18n_formattable_h *formattable) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + *formattable = new Formattable(str_to_copy); + retv_if(*formattable == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_create_with_formattable_array(const i18n_formattable_h *array_to_copy, int32_t count, i18n_formattable_h *formattable) +{ + retv_if(array_to_copy == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(count < 0, I18N_ERROR_INVALID_PARAMETER); + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + Formattable *f_array = new Formattable[count]; + + for (int i = 0; i < count; i++) { + retv_if(array_to_copy[i] == NULL, I18N_ERROR_INVALID_PARAMETER); + f_array[i] = *((Formattable *)array_to_copy[i]); + } + + *formattable = new Formattable(f_array, count); + + delete[] f_array; + + retv_if(*formattable == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_destroy(i18n_formattable_h formattable) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + delete ((Formattable *)formattable); + + formattable = NULL; + + return I18N_ERROR_NONE; +} + +int i18n_formattable_clone(i18n_formattable_h formattable, i18n_formattable_h *clone) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(clone == NULL, I18N_ERROR_INVALID_PARAMETER); + + *clone = ((Formattable *) formattable)->clone(); + retv_if(*clone == NULL, I18N_ERROR_UNKNOWN); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_get_array(i18n_formattable_h formattable, i18n_formattable_h **array, int32_t *count) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(array == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(count == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + const Formattable *f_array = ((Formattable *) formattable)->getArray(*count, status); + + *array = (i18n_formattable_h *)malloc(*count * sizeof(i18n_formattable_h)); + + for (int i = 0; i < *count; i++) { + (*array)[i] = (const i18n_formattable_h) &f_array[i]; + } + + return _i18n_error_mapping(status); +} + +int i18n_formattable_get_date(i18n_formattable_h formattable, i18n_udate *date) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(date == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + *date = (i18n_udate) ((Formattable *) formattable)->getDate(status); + + return _i18n_error_mapping(status); +} + +int i18n_formattable_get_double(i18n_formattable_h formattable, double *value) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(value == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + *value = ((Formattable *) formattable)->getDouble(status); + + return _i18n_error_mapping(status); +} + +int i18n_formattable_get_int64(i18n_formattable_h formattable, int64_t *value) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(value == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + *value = ((Formattable *) formattable)->getInt64(status); + + return _i18n_error_mapping(status); +} + +int i18n_formattable_get_long(i18n_formattable_h formattable, int32_t *value) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(value == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + *value = ((Formattable *) formattable)->getLong(status); + + return _i18n_error_mapping(status); +} + +int i18n_formattable_get_string(i18n_formattable_h formattable, char **value) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(value == NULL, I18N_ERROR_INVALID_PARAMETER); + + *value = NULL; + + UnicodeString result; + UErrorCode status = U_ZERO_ERROR; + ((Formattable *) formattable)->getString(result, status); + + const UChar *uchar_result = result.getTerminatedBuffer(); + retv_if(uchar_result == NULL, I18N_ERROR_INVALID_FORMAT); + + int32_t ulen = u_strlen(uchar_result); + retv_if(ulen <= 0, I18N_ERROR_UNKNOWN); + + *value = (char *) malloc(ulen + 1); + retv_if(*value == NULL, I18N_ERROR_UNKNOWN); + + u_austrcpy(*value, uchar_result); + + return _i18n_error_mapping(status); +} + +int i18n_formattable_get_type(i18n_formattable_h formattable, i18n_formattable_type_e *type) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(type == NULL, I18N_ERROR_INVALID_PARAMETER); + + *type = (i18n_formattable_type_e) ((Formattable *) formattable)->getType(); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_is_numeric(i18n_formattable_h formattable, bool *is_numeric) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(is_numeric == NULL, I18N_ERROR_INVALID_PARAMETER); + + *is_numeric = (bool) ((Formattable *) formattable)->isNumeric(); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_not_equal(i18n_formattable_h formattable, i18n_formattable_h other, bool *not_equal) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(other == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(not_equal == NULL, I18N_ERROR_INVALID_PARAMETER); + + *not_equal = (bool) (((Formattable *) formattable) != ((Formattable *) other)); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_equal(i18n_formattable_h formattable, i18n_formattable_h other, bool *equal) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(other == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(equal == NULL, I18N_ERROR_INVALID_PARAMETER); + + *equal = (bool) (((Formattable *) formattable) == ((Formattable *) other)); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_element_at(i18n_formattable_h formattable, int32_t index, i18n_formattable_h *element) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(index < 0, I18N_ERROR_INDEX_OUTOFBOUNDS); + retv_if(element == NULL, I18N_ERROR_INVALID_PARAMETER); + + int32_t count; + UErrorCode status = U_ZERO_ERROR; + ((Formattable *) formattable)->getArray(count, status); + + retv_if(status == U_INVALID_FORMAT_ERROR, I18N_ERROR_INVALID_FORMAT); + retv_if(index >= count, I18N_ERROR_INDEX_OUTOFBOUNDS); + + *element = (i18n_formattable_h) &((Formattable *) formattable)[index]; + + return _i18n_error_mapping(status); +} + +int i18n_formattable_set_array(i18n_formattable_h formattable, const i18n_formattable_h *array, int32_t count) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(array == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(count < 0, I18N_ERROR_INVALID_PARAMETER); + + Formattable *f_array = new Formattable[count]; + + for (int i = 0; i < count; i++) { + retv_if(array[i] == NULL, I18N_ERROR_INVALID_PARAMETER); + f_array[i] = *((Formattable *)array[i]); + } + + ((Formattable *) formattable)->setArray(f_array, count); + + delete[] f_array; + + return I18N_ERROR_NONE; +} + +int i18n_formattable_set_date(i18n_formattable_h formattable, i18n_udate d) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + ((Formattable *) formattable)->setDate(d); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_set_double(i18n_formattable_h formattable, double d) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + ((Formattable *) formattable)->setDouble(d); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_set_int64(i18n_formattable_h formattable, int64_t ll) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + ((Formattable *) formattable)->setInt64(ll); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_set_long(i18n_formattable_h formattable, int32_t l) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + ((Formattable *) formattable)->setLong(l); + + return I18N_ERROR_NONE; +} + +int i18n_formattable_set_string(i18n_formattable_h formattable, const char *string_to_copy) +{ + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString stringToCopy(string_to_copy); + ((Formattable *) formattable)->setString(stringToCopy); + + return I18N_ERROR_NONE; +} -- 2.7.4