* </tr>
* <tr>
* <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_format</td>
+ * <td>format</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_parse_object</td>
+ * <td>parseObject</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>
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.
* </tr>
* <tr>
* <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_format</td>
+ * <td>format</td>
+ * </tr>
+ * <tr>
+ * <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE</td>
+ * <td>#i18n_measure_format_parse_object</td>
+ * <td>parseObject</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>
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.
#include <utils_i18n_measure_format.h>
#include <utils_i18n_private.h>
+#include <malloc.h>
#include <unicode/measfmt.h>
+#include <unicode/measure.h>
int i18n_measure_format_create(const char *language, const char *country, i18n_umeasure_format_width_e width, i18n_measure_format_h *measure_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);