From: Lukasz Pik Date: Tue, 19 Dec 2017 11:28:45 +0000 (+0100) Subject: [Base-utils][MeasureFormat][ACR-1138] Added missing function X-Git-Tag: submit/tizen/20180118.063705~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=89ec2f6d97a50fd7fff822f11cf9ac98afb3b75b;p=platform%2Fcore%2Fapi%2Fbase-utils.git [Base-utils][MeasureFormat][ACR-1138] Added missing function Change-Id: I7aa1c8e5c3b289de33beecc5ecf354ae48c3d284 Signed-off-by: Lukasz Pik --- diff --git a/src/include/utils_i18n.h b/src/include/utils_i18n.h index 3c2976b..1d824cf 100644 --- a/src/include/utils_i18n.h +++ b/src/include/utils_i18n.h @@ -3356,6 +3356,11 @@ extern "C" { * formatMeasurePerUnit * * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_get_unit_display_name + * getUnitDisplayName + * + * * @ref CAPI_BASE_UTILS_I18N_FIELD_POSITION_MODULE * #i18n_field_position_create * FieldPosition diff --git a/src/include/utils_i18n_measure_format.h b/src/include/utils_i18n_measure_format.h index a195e77..47d5810 100644 --- a/src/include/utils_i18n_measure_format.h +++ b/src/include/utils_i18n_measure_format.h @@ -289,6 +289,30 @@ int i18n_measure_format_format_measure_per_unit(const i18n_measure_format_h meas i18n_uchar *append_to, int32_t *output_length); +/** + * @brief Gets the display name of the #i18n_measure_unit_h corresponding to the current locale and format width. + * @since_tizen 5.0 + * + * @param[in] measure_format The measure format object + * @param[in] measure_unit The unit for which to get the display name + * @param[in] buffer_size The size of the @a buffer. + * If @a buffer_size <= 0 then the output string is not + * inserted to the @a buffer and #I18N_ERROR_BUFFER_OVERFLOW + * is returned. + * @param[out] buffer The buffer to which the formatted string will be inserted. + * Can be @c NULL if @a output_buffer_size <= 0. + * @param[out] output_length The length of the output string + * + * @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_BUFFER_OVERFLOW Buffer overflow + */ +int i18n_measure_format_get_unit_display_name(const i18n_measure_format_h measure_format, + const i18n_measure_unit_h measure_unit, + int32_t buffer_size, + i18n_uchar *buffer, + int32_t *output_length); /** * @} diff --git a/src/utils_i18n_measure_format.cpp b/src/utils_i18n_measure_format.cpp index 595d32c..9b1cec9 100644 --- a/src/utils_i18n_measure_format.cpp +++ b/src/utils_i18n_measure_format.cpp @@ -267,3 +267,33 @@ int i18n_measure_format_format_measure_per_unit(const i18n_measure_format_h meas return _i18n_error_mapping(status); } +int i18n_measure_format_get_unit_display_name(const i18n_measure_format_h measure_format, + const i18n_measure_unit_h measure_unit, + int32_t buffer_size, + i18n_uchar *buffer, + int32_t *output_length) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(measure_unit == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(output_length == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + UnicodeString result = ((MeasureFormat *)measure_format)->getUnitDisplayName(*((MeasureUnit *)measure_unit), status); + if (result == NULL) { + *output_length = 0; + return I18N_ERROR_NONE; + } + + const i18n_uchar *uchar_result = (i18n_uchar *)result.getTerminatedBuffer(); + + retv_if(uchar_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + *output_length = i18n_ustring_get_length(uchar_result); + retv_if(*output_length > buffer_size, I18N_ERROR_BUFFER_OVERFLOW); + + if (*output_length > 0) + i18n_ustring_copy_n(buffer, uchar_result, buffer_size); + + return _i18n_error_mapping(status); +} +