[Base-utils][Format] Missed functions added 60/73260/5
authorRafał Szczekutek <r.szczekutek@samsung.com>
Thu, 30 Jun 2016 12:42:08 +0000 (14:42 +0200)
committerRafał Szczekutek <r.szczekutek@samsung.com>
Thu, 30 Jun 2016 12:42:08 +0000 (14:42 +0200)
Change-Id: Ied039f00917737e621c16aab221f0c9f921abb65
Signed-off-by: Beata Stefaniuk <b.stefaniuk@samsung.com>
src/include/mobile/utils_i18n_format.h
src/include/wearable/utils_i18n_format.h
src/utils_i18n_format.cpp

index 9545984792cd9d248551a12657e6f248677ebaa8..27c56663e085c9c5bc3c6f4d389f87380579aa67 100644 (file)
@@ -91,7 +91,7 @@ int i18n_format_clone(i18n_format_h format, i18n_format_h *clone);
  * @param[in] format         The format object
  * @param[in] formattable    The object to format
  * @param[in/out] append_to  An output parameter to receive the result.
- *                           Result is appended to the existing contents.
+ *                           The result is appended to the existing contents.
  *
  * @return @c 0 on success, otherwise a negative error value
  * @retval #I18N_ERROR_NONE Successful
@@ -100,6 +100,26 @@ int i18n_format_clone(i18n_format_h format, i18n_format_h *clone);
  */
 int i18n_format_format(i18n_format_h format, i18n_formattable_h formattable, char **append_to);
 
+/**
+ * @brief Formats an object to produce a string.
+ * @remarks The @a append_to parameter should be released by the caller with the
+ *          free() function.
+ * @since_tizen 3.0
+ *
+ * @param[in] 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_format_format_with_field_position(i18n_format_h 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 formattable object should be released by the caller with the
@@ -114,10 +134,29 @@ int i18n_format_format(i18n_format_h format, i18n_formattable_h formattable, cha
  * @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_format_parse_object(i18n_format_h format, const char *source, i18n_formattable_h *result);
 
+/**
+ * @brief Parses a string to produce an object.
+ * @remarks The obtained @a result formattable object should be released by the caller with the
+ *          i18n_formattable_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[in] 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 Error code. Error codes not listed below are described in the #i18n_error_code_e
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_format_parse_object_with_parse_position(i18n_format_h format, const char *source, i18n_parse_position_h parse_position, i18n_formattable_h *result);
+
 /**
  * @brief Gets the locale for the given format object.
  * @details You can choose between valid and actual locale.
index 9545984792cd9d248551a12657e6f248677ebaa8..8e291a4348d35aaea32e5f9dbf7d218c52062fcc 100644 (file)
@@ -91,7 +91,7 @@ int i18n_format_clone(i18n_format_h format, i18n_format_h *clone);
  * @param[in] format         The format object
  * @param[in] formattable    The object to format
  * @param[in/out] append_to  An output parameter to receive the result.
- *                           Result is appended to the existing contents.
+ *                           The result is appended to the existing contents.
  *
  * @return @c 0 on success, otherwise a negative error value
  * @retval #I18N_ERROR_NONE Successful
@@ -100,6 +100,26 @@ int i18n_format_clone(i18n_format_h format, i18n_format_h *clone);
  */
 int i18n_format_format(i18n_format_h format, i18n_formattable_h formattable, char **append_to);
 
+/**
+ * @brief Formats an object to produce a string.
+ * @remarks The @a append_to parameter should be released by the caller with the
+ *          free() function.
+ * @since_tizen 3.0
+ *
+ * @param[in] 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_format_format_with_field_position(i18n_format_h 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 formattable object should be released by the caller with the
@@ -114,10 +134,29 @@ int i18n_format_format(i18n_format_h format, i18n_formattable_h formattable, cha
  * @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_format_parse_object(i18n_format_h format, const char *source, i18n_formattable_h *result);
 
+/**
+ * @brief Parses a string to produce an object.
+ * @remarks The obtained @a result formattable object should be released by the caller with the
+ *          i18n_formattable_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[in] 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 Error code. Error codes not listed below are described in the #i18n_error_code_e
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_format_parse_object_with_parse_position(i18n_format_h format, char *source, i18n_parse_position_h parse_position, i18n_formattable_h *result);
+
 /**
  * @brief Gets the locale for the given format object.
  * @details You can choose between valid and actual locale.
index 327bbeb61c5102db236d351063f49b51ea05c37b..737907871078309f37e4964639144597bc537bf9 100644 (file)
@@ -64,6 +64,32 @@ int i18n_format_format(i18n_format_h format, i18n_formattable_h formattable, cha
     return _i18n_error_mapping(status);
 }
 
+int i18n_format_format_with_field_position(i18n_format_h format, i18n_formattable_h formattable, char **append_to, i18n_field_position_h field_position)
+{
+    retv_if(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 = ((Format *) 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_format_parse_object(i18n_format_h format, const char *source, i18n_formattable_h *result)
 {
     retv_if(format == NULL, I18N_ERROR_INVALID_PARAMETER);
@@ -82,6 +108,24 @@ int i18n_format_parse_object(i18n_format_h format, const char *source, i18n_form
     return _i18n_error_mapping(status);
 }
 
+int i18n_format_parse_object_with_parse_position(i18n_format_h format, const char *source, i18n_parse_position_h parse_position, i18n_formattable_h *result)
+{
+    retv_if(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);
+    UErrorCode status = U_ZERO_ERROR;
+    const UnicodeString unicode_source(source);
+
+    Formattable *f = new Formattable();
+
+    ((Format *) format)->parseObject(unicode_source, *f, *((ParsePosition *)parse_position));
+
+    *result = (i18n_formattable_h)f;
+
+    return _i18n_error_mapping(status);
+}
+
 int i18n_format_get_locale(i18n_format_h format, i18n_uloc_data_locale_type_e type,
         const char **language, const char **country)
 {