From: Rafał Szczekutek Date: Mon, 27 Jun 2016 13:34:43 +0000 (+0200) Subject: [Base-utils][MeasureFormat] Module implementation added X-Git-Tag: submit/tizen/20160628.104345~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b721b6f242fc1cb236a6b8d6952a291fb5cb20a;p=platform%2Fcore%2Fapi%2Fbase-utils.git [Base-utils][MeasureFormat] Module implementation added Change-Id: I22ce2a25d529abad5a25c67b9941490cfd4592cc Signed-off-by: Beata Stefaniuk --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4eb6081..d0da72a 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,7 @@ SET(BASEUTILS_SRCS utils_i18n_measure_unit.cpp utils_i18n_measure.cpp utils_i18n_format.cpp + utils_i18n_measure_format.cpp ) ADD_LIBRARY(${target_name} SHARED ${BASEUTILS_SRCS} @@ -77,5 +78,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_formattable.h DE INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_measure_unit.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_measure.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_format.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_measure_format.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) \ No newline at end of file diff --git a/src/include/mobile/utils_i18n.h b/src/include/mobile/utils_i18n.h index 962ffe1..d822a18 100644 --- a/src/include/mobile/utils_i18n.h +++ b/src/include/mobile/utils_i18n.h @@ -37,6 +37,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -51,7 +52,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, alpha_idx, formattable, measure unit, measure and format. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable, measure unit, measure, format and measure format. * 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. * @@ -147,6 +148,10 @@ extern "C" { * * * + * + * + * + * *
@ref CAPI_BASE_UTILS_I18N_FORMAT_MODULEThe Format module represents the basic format object.
@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULEThe Measure Format module represents a formatter for measure objects.
* * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -2823,6 +2828,31 @@ extern "C" { * #i18n_format_get_locale * getLocale * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create + * MeasureFormat + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_destroy + * ~MeasureFormat + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_clone + * clone + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create_currency_format_from_locale + * createCurrencyFormat + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create_currency_format + * createCurrencyFormat + * * */ diff --git a/src/include/mobile/utils_i18n_measure_format.h b/src/include/mobile/utils_i18n_measure_format.h new file mode 100644 index 0000000..4771a87 --- /dev/null +++ b/src/include/mobile/utils_i18n_measure_format.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015 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_MEASURE_FORMAT_H__ +#define __UTILS_I18N_MEASURE_FORMAT_H__ + +#include + +/** + * @file utils_i18n_measure_format.h + * @version 0.1 + * @brief utils_i18n_measure_format + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE MeasureFormat + * @brief The MeasureFormat is a formatter for Measure objects. + * @section CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE_HEADER Required Header + *» \#include + * + * @section CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE_OVERVIEW Overview + * @details + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * @{ + */ + +/** + * @brief Creates the measure format object using given locale. + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * @param[in] width The format width + * @param[out] measure_format The created measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create(const char *language, const char *country, + i18n_umeasure_format_width_e width, i18n_measure_format_h *measure_format); + +/** + * @brief Destroys the measure format object + * @since_tizen 3.0 + * + * @param[in] measure_format The measure format object to destroy + * + * @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_measure_format_destroy(i18n_measure_format_h measure_format); + +/** + * @brief Creates a polymorphic clone of the given @a measure_format object. + * @remarks The @a clone object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure_format The measure format object to be cloned + * @param[out] clone The created measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_clone(i18n_measure_format_h measure_format, i18n_format_h *clone); + +/** + * @brief Gets a formatter for currency amount objects in the given locale. + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * @param[out] measure_format The measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create_currency_format_from_locale(const char *language, const char *country, i18n_measure_format_h *measure_format); + +/** + * @brief Gets a formatter for currency amount objects in the default locale. + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[out] measure_format The measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create_currency_format(i18n_measure_format_h *measure_format); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_MEASURE_FORMAT_H__*/ diff --git a/src/include/mobile/utils_i18n_types.h b/src/include/mobile/utils_i18n_types.h index 45784f9..9f8943d 100644 --- a/src/include/mobile/utils_i18n_types.h +++ b/src/include/mobile/utils_i18n_types.h @@ -2839,10 +2839,10 @@ typedef void *i18n_measure_format_h; * @since_tizen 3.0 */ typedef enum { - I18N_UMEASFMT_WIDTH_WIDE = 0, /**< Spell out measure units. */ - I18N_UMEASFMT_WIDTH_SHORT = 1, /**< Abbreviate measure units. */ - I18N_UMEASFMT_WIDTH_NARROW = 2, /**< Use symbols for measure units when possible. */ - I18N_UMEASFMT_WIDTH_NUMERIC = 3, /**< Completely omit measure units when possible. + I18N_UMEASFMT_WIDTH_WIDE = 0, /**< Spell out measure units */ + I18N_UMEASFMT_WIDTH_SHORT = 1, /**< Abbreviate measure units */ + I18N_UMEASFMT_WIDTH_NARROW = 2, /**< Use symbols for measure units when possible */ + I18N_UMEASFMT_WIDTH_NUMERIC = 3, /**< Completely omit measure units when possible For example, format '5 hours, 37 minutes' as '5:37' */ I18N_UMEASFMT_WIDTH_COUNT = 4, /**< Count of values in this enumeration. */ } i18n_umeasure_format_width_e; diff --git a/src/include/wearable/utils_i18n.h b/src/include/wearable/utils_i18n.h index e91a135..f0dda02 100644 --- a/src/include/wearable/utils_i18n.h +++ b/src/include/wearable/utils_i18n.h @@ -37,6 +37,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -51,7 +52,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, alpha_idx, formattable, measure and format. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable, measure, format and measure format. * 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. * @@ -147,6 +148,10 @@ extern "C" { * * * + * + * + * + * *
@ref CAPI_BASE_UTILS_I18N_FORMAT_MODULEThe Format module represents the basic format object.
@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULEThe Measure Format module represents a formatter for measure objects.
* * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -2823,6 +2828,31 @@ extern "C" { * #i18n_format_get_locale * getLocale * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create + * MeasureFormat + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_destroy + * ~MeasureFormat + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_clone + * clone + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create_currency_format_from_locale + * createCurrencyFormat + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create_currency_format + * createCurrencyFormat + * * */ diff --git a/src/include/wearable/utils_i18n_measure_format.h b/src/include/wearable/utils_i18n_measure_format.h new file mode 100644 index 0000000..4771a87 --- /dev/null +++ b/src/include/wearable/utils_i18n_measure_format.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015 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_MEASURE_FORMAT_H__ +#define __UTILS_I18N_MEASURE_FORMAT_H__ + +#include + +/** + * @file utils_i18n_measure_format.h + * @version 0.1 + * @brief utils_i18n_measure_format + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE MeasureFormat + * @brief The MeasureFormat is a formatter for Measure objects. + * @section CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE_HEADER Required Header + *» \#include + * + * @section CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE_OVERVIEW Overview + * @details + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * @{ + */ + +/** + * @brief Creates the measure format object using given locale. + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * @param[in] width The format width + * @param[out] measure_format The created measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create(const char *language, const char *country, + i18n_umeasure_format_width_e width, i18n_measure_format_h *measure_format); + +/** + * @brief Destroys the measure format object + * @since_tizen 3.0 + * + * @param[in] measure_format The measure format object to destroy + * + * @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_measure_format_destroy(i18n_measure_format_h measure_format); + +/** + * @brief Creates a polymorphic clone of the given @a measure_format object. + * @remarks The @a clone object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure_format The measure format object to be cloned + * @param[out] clone The created measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_clone(i18n_measure_format_h measure_format, i18n_format_h *clone); + +/** + * @brief Gets a formatter for currency amount objects in the given locale. + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * @param[out] measure_format The measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create_currency_format_from_locale(const char *language, const char *country, i18n_measure_format_h *measure_format); + +/** + * @brief Gets a formatter for currency amount objects in the default locale. + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * @since_tizen 3.0 + * + * @param[out] measure_format The measure format 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_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create_currency_format(i18n_measure_format_h *measure_format); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_MEASURE_FORMAT_H__*/ diff --git a/src/include/wearable/utils_i18n_types.h b/src/include/wearable/utils_i18n_types.h index 5cf1aa1..26ec56d 100644 --- a/src/include/wearable/utils_i18n_types.h +++ b/src/include/wearable/utils_i18n_types.h @@ -2839,12 +2839,12 @@ typedef void *i18n_measure_format_h; * @since_tizen 3.0 */ typedef enum { - I18N_UMEASFMT_WIDTH_WIDE = 0, /**< Spell out measure units. */ - I18N_UMEASFMT_WIDTH_SHORT = 1, /**< Abbreviate measure units. */ - I18N_UMEASFMT_WIDTH_NARROW = 2, /**< Use symbols for measure units when possible. */ - I18N_UMEASFMT_WIDTH_NUMERIC = 3, /**< Completely omit measure units when possible. + I18N_UMEASFMT_WIDTH_WIDE = 0, /**< Spell out measure units */ + I18N_UMEASFMT_WIDTH_SHORT = 1, /**< Abbreviate measure units */ + I18N_UMEASFMT_WIDTH_NARROW = 2, /**< Use symbols for measure units when possible */ + I18N_UMEASFMT_WIDTH_NUMERIC = 3, /**< Completely omit measure units when possible For example, format '5 hours, 37 minutes' as '5:37' */ - I18N_UMEASFMT_WIDTH_COUNT = 4, /**< Count of values in this enumeration. */ + I18N_UMEASFMT_WIDTH_COUNT = 4, /**< Count of values in this enumeration */ } i18n_umeasure_format_width_e; /** diff --git a/src/utils_i18n_measure_format.cpp b/src/utils_i18n_measure_format.cpp new file mode 100644 index 0000000..5adb81a --- /dev/null +++ b/src/utils_i18n_measure_format.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015 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 + +int i18n_measure_format_create(i18n_measure_format_h *measure_format, const char *language, const char *country, i18n_umeasure_format_width_e width) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + UErrorCode status = U_ZERO_ERROR; + Locale locale(language, country, 0, 0); + UMeasureFormatWidth icu_width = (UMeasureFormatWidth) width; + + *measure_format = new MeasureFormat(locale, icu_width, status); + retv_if(*measure_format == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +} + +int i18n_measure_format_destroy(i18n_measure_format_h measure_format) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + + delete((MeasureFormat *) measure_format); + + return I18N_ERROR_NONE; +} + +int i18n_measure_format_clone(i18n_measure_format_h measure_format, i18n_format_h *clone) +{ + retv_if(measure_format == NULL || clone == NULL, I18N_ERROR_INVALID_PARAMETER); + + *clone = ((MeasureFormat *) measure_format)->clone(); + retv_if(*clone == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return I18N_ERROR_NONE; +} + +int i18n_measure_format_create_currency_format_from_locale(i18n_measure_format_h *measure_format, const char *language, const char *country) +{ + retv_if(measure_format == NULL || language == NULL || country == NULL, I18N_ERROR_INVALID_PARAMETER); + UErrorCode status = U_ZERO_ERROR; + Locale locale(language, country, 0, 0); + + *measure_format = MeasureFormat::createCurrencyFormat(locale, status); + retv_if(*measure_format == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +} + +int i18n_measure_format_create_currency_format(i18n_measure_format_h *measure_format) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + UErrorCode status = U_ZERO_ERROR; + + *measure_format = MeasureFormat::createCurrencyFormat(status); + retv_if(*measure_format == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +}