[Base-utils][MeasureFormat][ACR-1138] Added missing function 17/164517/8
authorLukasz Pik <lu.pik@samsung.com>
Tue, 19 Dec 2017 11:28:45 +0000 (12:28 +0100)
committerhyunjee Kim <hj0426.kim@samsung.com>
Thu, 18 Jan 2018 02:04:46 +0000 (02:04 +0000)
Change-Id: I7aa1c8e5c3b289de33beecc5ecf354ae48c3d284
Signed-off-by: Lukasz Pik <lu.pik@samsung.com>
src/include/utils_i18n.h
src/include/utils_i18n_measure_format.h
src/utils_i18n_measure_format.cpp

index 3c2976b..1d824cf 100644 (file)
@@ -3356,6 +3356,11 @@ extern "C" {
  *       <td>formatMeasurePerUnit</td>
  * </tr>
  * <tr>
+ *      <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ *      <td>#i18n_measure_format_get_unit_display_name</td>
+ *      <td>getUnitDisplayName</td>
+ * </tr>
+ * <tr>
  *       <td>@ref CAPI_BASE_UTILS_I18N_FIELD_POSITION_MODULE</td>
  *       <td>#i18n_field_position_create</td>
  *       <td>FieldPosition</td>
index a195e77..47d5810 100644 (file)
@@ -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 <code>@a buffer_size <= 0</code> 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 <code>@a output_buffer_size <= 0</code>.
+ * @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);
 
 /**
  * @}
index 595d32c..9b1cec9 100644 (file)
@@ -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);
+}
+