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}
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
#include <utils_i18n_measure_unit.h>
#include <utils_i18n_measure.h>
#include <utils_i18n_format.h>
+#include <utils_i18n_measure_format.h>
/**
* @file utils_i18n.h
/**
* @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.
* <table>
* <td>@ref CAPI_BASE_UTILS_I18N_FORMAT_MODULE</td>
* <td>The Format module represents the basic format object.</td>
* </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>The Measure Format module represents a formatter for measure objects.</td>
+ * </tr>
* </table>
*
* @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table
* <td>#i18n_format_get_locale</td>
* <td>getLocale</td>
* </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_create</td>
+ * <td>MeasureFormat</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_destroy</td>
+ * <td>~MeasureFormat</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_clone</td>
+ * <td>clone</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_create_currency_format_from_locale</td>
+ * <td>createCurrencyFormat</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_create_currency_format</td>
+ * <td>createCurrencyFormat</td>
+ * </tr>
* </table>
*/
--- /dev/null
+/*
+ * 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 <utils_i18n_types.h>
+
+/**
+ * @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 <utils_i18n.h>
+ *
+ * @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__*/
* @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;
#include <utils_i18n_measure_unit.h>
#include <utils_i18n_measure.h>
#include <utils_i18n_format.h>
+#include <utils_i18n_measure_format.h>
/**
* @file utils_i18n.h
/**
* @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.
* <table>
* <td>@ref CAPI_BASE_UTILS_I18N_FORMAT_MODULE</td>
* <td>The Format module represents the basic format object.</td>
* </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>The Measure Format module represents a formatter for measure objects.</td>
+ * </tr>
* </table>
*
* @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table
* <td>#i18n_format_get_locale</td>
* <td>getLocale</td>
* </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_create</td>
+ * <td>MeasureFormat</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_destroy</td>
+ * <td>~MeasureFormat</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_clone</td>
+ * <td>clone</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_create_currency_format_from_locale</td>
+ * <td>createCurrencyFormat</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_create_currency_format</td>
+ * <td>createCurrencyFormat</td>
+ * </tr>
* </table>
*/
--- /dev/null
+/*
+ * 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 <utils_i18n_types.h>
+
+/**
+ * @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 <utils_i18n.h>
+ *
+ * @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__*/
* @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;
/**
--- /dev/null
+/*
+ * 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 <utils_i18n_measure_format.h>
+#include <utils_i18n_private.h>
+
+#include <unicode/measfmt.h>
+
+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);
+}