From f64ee55bc80702d19e132dafd026cc11c414d9e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Szczekutek?= Date: Thu, 30 Jun 2016 13:35:28 +0200 Subject: [PATCH] [Base-utils][MeasureFormat] Missed functions added Change-Id: Idf590c5d73849266ea4afbabcdfa82e19d08c279 Signed-off-by: Beata Stefaniuk --- src/include/mobile/utils_i18n.h | 10 +++++ src/include/mobile/utils_i18n_measure_format.h | 47 +++++++++++++++++++++++ src/include/wearable/utils_i18n.h | 10 +++++ src/include/wearable/utils_i18n_measure_format.h | 47 +++++++++++++++++++++++ src/utils_i18n_measure_format.cpp | 48 ++++++++++++++++++++++++ 5 files changed, 162 insertions(+) diff --git a/src/include/mobile/utils_i18n.h b/src/include/mobile/utils_i18n.h index 5d04708..335d79d 100644 --- a/src/include/mobile/utils_i18n.h +++ b/src/include/mobile/utils_i18n.h @@ -2855,6 +2855,16 @@ extern "C" { * * * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_format + * format + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_parse_object + * parseObject + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE * #i18n_measure_format_create_currency_format_from_locale * createCurrencyFormat * diff --git a/src/include/mobile/utils_i18n_measure_format.h b/src/include/mobile/utils_i18n_measure_format.h index 4771a87..75d4a64 100644 --- a/src/include/mobile/utils_i18n_measure_format.h +++ b/src/include/mobile/utils_i18n_measure_format.h @@ -93,6 +93,53 @@ int i18n_measure_format_destroy(i18n_measure_format_h measure_format); int i18n_measure_format_clone(i18n_measure_format_h measure_format, i18n_format_h *clone); /** + * @brief Formats an object to produce a string. + * @remarks The obtained @a append_to string is actually a concatenation of the given input string and + * the result of the function (appended to the string). Actually, the @a append_to + * buffer is being reallocated inside the function which means that the buffer is not + * at the same place in memory as it was on the input. Please note that the @a append_to + * buffer should be released by the caller with the free() function. + * @since_tizen 3.0 + * + * @param[in] measure_format The format object + * @param[in] formattable The object to format + * @param[in/out] append_to Output parameter to receive the result. + * The result is appended to the existing contents. + * @param[in/out] field_position On input: an alignment field, if desired. + * On output: the offsets of the alignment field. + * + * @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_format(i18n_measure_format_h measure_format, i18n_formattable_h formattable, + char **append_to, i18n_field_position_h field_position); + +/** + * @brief Parses a string to produce an object. + * @remarks The obtained @a result object should be released by the caller + * with the i18n_formattable_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure_format The format object + * @param[in] source The string to be parsed into an object + * @param[in/out] parse_position The position to start parsing at. Upon return + * this parameter is set to the position after the + * last character successfully parsed. If the + * source is not parsed successfully, this parameter + * will remain unchanged. + * @param[out] result The formattable object to be set to the parse result. + * If parse fails, return contents are undefined. + * + * @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_parse_object(i18n_measure_format_h measure_format, const char *source, i18n_parse_position_h parse_position, i18n_formattable_h *result); + +/** * @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. diff --git a/src/include/wearable/utils_i18n.h b/src/include/wearable/utils_i18n.h index 3ba2509..39f12d6 100644 --- a/src/include/wearable/utils_i18n.h +++ b/src/include/wearable/utils_i18n.h @@ -2855,6 +2855,16 @@ extern "C" { * * * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_format + * format + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_parse_object + * parseObject + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE * #i18n_measure_format_create_currency_format_from_locale * createCurrencyFormat * diff --git a/src/include/wearable/utils_i18n_measure_format.h b/src/include/wearable/utils_i18n_measure_format.h index 4771a87..75d4a64 100644 --- a/src/include/wearable/utils_i18n_measure_format.h +++ b/src/include/wearable/utils_i18n_measure_format.h @@ -93,6 +93,53 @@ int i18n_measure_format_destroy(i18n_measure_format_h measure_format); int i18n_measure_format_clone(i18n_measure_format_h measure_format, i18n_format_h *clone); /** + * @brief Formats an object to produce a string. + * @remarks The obtained @a append_to string is actually a concatenation of the given input string and + * the result of the function (appended to the string). Actually, the @a append_to + * buffer is being reallocated inside the function which means that the buffer is not + * at the same place in memory as it was on the input. Please note that the @a append_to + * buffer should be released by the caller with the free() function. + * @since_tizen 3.0 + * + * @param[in] measure_format The format object + * @param[in] formattable The object to format + * @param[in/out] append_to Output parameter to receive the result. + * The result is appended to the existing contents. + * @param[in/out] field_position On input: an alignment field, if desired. + * On output: the offsets of the alignment field. + * + * @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_format(i18n_measure_format_h measure_format, i18n_formattable_h formattable, + char **append_to, i18n_field_position_h field_position); + +/** + * @brief Parses a string to produce an object. + * @remarks The obtained @a result object should be released by the caller + * with the i18n_formattable_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure_format The format object + * @param[in] source The string to be parsed into an object + * @param[in/out] parse_position The position to start parsing at. Upon return + * this parameter is set to the position after the + * last character successfully parsed. If the + * source is not parsed successfully, this parameter + * will remain unchanged. + * @param[out] result The formattable object to be set to the parse result. + * If parse fails, return contents are undefined. + * + * @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_parse_object(i18n_measure_format_h measure_format, const char *source, i18n_parse_position_h parse_position, i18n_formattable_h *result); + +/** * @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. diff --git a/src/utils_i18n_measure_format.cpp b/src/utils_i18n_measure_format.cpp index bfd7fa6..64ff51b 100644 --- a/src/utils_i18n_measure_format.cpp +++ b/src/utils_i18n_measure_format.cpp @@ -17,7 +17,9 @@ #include #include +#include #include +#include int i18n_measure_format_create(const char *language, const char *country, i18n_umeasure_format_width_e width, i18n_measure_format_h *measure_format) { @@ -51,6 +53,52 @@ int i18n_measure_format_clone(i18n_measure_format_h measure_format, i18n_format_ return I18N_ERROR_NONE; } +int i18n_measure_format_format(i18n_measure_format_h measure_format, i18n_formattable_h formattable, char **append_to, i18n_field_position_h field_position) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(append_to == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(field_position == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + UnicodeString unicode_append_to(*append_to); + + UnicodeString result = ((MeasureFormat *) measure_format)->format(*((Formattable *) formattable), unicode_append_to, *((FieldPosition *) field_position), status); + const UChar *uchar_result = result.getTerminatedBuffer(); + + retv_if(uchar_result == NULL, I18N_ERROR_INVALID_PARAMETER); + int32_t ulen = u_strlen(uchar_result); + + retv_if(ulen <= 0, I18N_ERROR_INVALID_PARAMETER); + *append_to = (char *) malloc(ulen + 1); + + retv_if(*append_to == NULL, I18N_ERROR_OUT_OF_MEMORY); + + u_austrcpy(*append_to, uchar_result); + + return _i18n_error_mapping(status); +} + +int i18n_measure_format_parse_object(i18n_measure_format_h measure_format, const char *source, i18n_parse_position_h parse_position, i18n_formattable_h *result) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(source == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(result == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString unicode_source(source); + + Formattable *f = new Formattable(); + + ((MeasureFormat *) measure_format)->parseObject(unicode_source, *f, *((ParsePosition *) parse_position)); + + *result = (i18n_formattable_h) f; + retv_if(*result == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return I18N_ERROR_NONE; +} + int i18n_measure_format_create_currency_format_from_locale(const char *language, const char *country, i18n_measure_format_h *measure_format) { retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); -- 2.7.4