[Base-utils][Parse Position] Complete module added 87/70787/18 accepted/tizen/common/20160628.141804 accepted/tizen/ivi/20160629.021224 accepted/tizen/mobile/20160629.021235 accepted/tizen/tv/20160629.021141 accepted/tizen/wearable/20160629.021217 submit/tizen/20160628.104345
authorRafał Szczekutek <r.szczekutek@samsung.com>
Mon, 27 Jun 2016 14:03:34 +0000 (16:03 +0200)
committerRafał Szczekutek <r.szczekutek@samsung.com>
Mon, 27 Jun 2016 14:03:34 +0000 (16:03 +0200)
implementation + documentation

Change-Id: I6f237cb0989f1f0c374a4774c156c67f17b0f7ac
Signed-off-by: Beata Stefaniuk <b.stefaniuk@samsung.com>
src/CMakeLists.txt
src/include/mobile/utils_i18n.h
src/include/mobile/utils_i18n_parse_position.h [new file with mode: 0644]
src/include/mobile/utils_i18n_types.h
src/include/wearable/utils_i18n.h
src/include/wearable/utils_i18n_field_position.h
src/include/wearable/utils_i18n_parse_position.h [new file with mode: 0644]
src/include/wearable/utils_i18n_types.h
src/utils_i18n_parse_position.cpp [new file with mode: 0644]

index 8a2df2e..2359c04 100755 (executable)
@@ -40,6 +40,7 @@ SET(BASEUTILS_SRCS
     utils_i18n_format.cpp
     utils_i18n_measure_format.cpp
     utils_i18n_field_position.cpp
+    utils_i18n_parse_position.cpp
 )
 
 ADD_LIBRARY(${target_name} SHARED ${BASEUTILS_SRCS}
@@ -81,5 +82,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_measure.h DESTIN
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_format.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_measure_format.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_field_position.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_parse_position.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n.h DESTINATION ${INCLUDE_INSTALL_DIR}/base)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pc_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
\ No newline at end of file
index b155f4d..5d04708 100644 (file)
@@ -39,6 +39,7 @@
 #include <utils_i18n_format.h>
 #include <utils_i18n_measure_format.h>
 #include <utils_i18n_field_position.h>
+#include <utils_i18n_parse_position.h>
 
 /**
  * @file utils_i18n.h
@@ -53,7 +54,7 @@ extern "C" {
 /**
  * @ingroup CAPI_BASE_UTILS_MODULE
  * @defgroup CAPI_BASE_UTILS_I18N_MODULE i18n
- * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable, measure unit, measure, format, measure format and field position.
+ * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable, measure unit, measure, format, measure format, field position and parse position.
  *        This module provides flexible generation of number or date format patterns and helps you format and parse dates/number for any locale.
  * The i18n module provides various features based on data from ICU. The following table shows the version of ICU used in each Tizen platform.
  * <table>
@@ -157,6 +158,10 @@ extern "C" {
  *       <td>@ref CAPI_BASE_UTILS_I18N_FIELD_POSITION</td>
  *       <td>The Field Position module is used to identify fields in a formatted output.</td>
  * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION</td>
+ *       <td>The Parse Position module used by Format and its subclasses to keep track of the current position during parsing.</td>
+ * </tr>
  * </table>
  *
  * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table
@@ -2908,6 +2913,46 @@ extern "C" {
  *       <td>#i18n_field_position_set_end_index</td>
  *       <td>setEndIndex</td>
  * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_create</td>
+ *       <td>ParsePosition</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_create_with_index</td>
+ *       <td>ParsePosition</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_destroy</td>
+ *       <td>~ParsePosition</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_clone</td>
+ *       <td>clone</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_get_index</td>
+ *       <td>getIndex</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_set_index</td>
+ *       <td>setIndex</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_set_error_index</td>
+ *       <td>setErrorIndex</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_get_error_index</td>
+ *       <td>getErrorIndex</td>
+ * </tr>
  * </table>
  */
 
diff --git a/src/include/mobile/utils_i18n_parse_position.h b/src/include/mobile/utils_i18n_parse_position.h
new file mode 100644 (file)
index 0000000..9666d36
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef __UTILS_I18N_PARSE_POSITION_H__
+#define __UTILS_I18N_PARSE_POSITION_H__
+
+#include <utils_i18n_types.h>
+
+/**
+ * @file utils_i18n_parse_position.h
+ * @version 0.1
+ * @brief utils_i18n_parse_position
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup CAPI_BASE_UTILS_I18N_MODULE
+ * @defgroup CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE ParsePosition
+ * @brief Parse Position is a simple object used by the Format and its subtypes
+ *        to keep track of the current position during parsing.
+ * @section CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE_HEADER Required Header
+ *        \#include <utils_i18n.h>
+ *
+ * @section CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE_OVERVIEW Overview
+ * @details The i18n_format_parse_object() method in the Format types requires
+ * a Parse Position object as an argument.
+ * By design, as you parse through a string with different formats, you can use
+ * the same Parse Position, since the index parameter records the current position.
+ */
+
+/**
+ * @addtogroup CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a parse position object.
+ * @remarks The created object should be released by the caller with the
+ *          i18n_parse_position_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[out] parse_position  The created parse position object
+ *
+ * @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_parse_position_create(i18n_parse_position_h *parse_position);
+
+/**
+ * @brief Creates a parse position object with the given initial index.
+ * @remarks The created object should be released by the caller with the
+ *          i18n_parse_position_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[out] parse_position  The parse position object
+ * @param[in]  new_index       The new text offset
+ *
+ * @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_parse_position_create_with_index(int32_t new_index, i18n_parse_position_h *parse_position);
+
+/**
+ * @brief Destroys the parse position object.
+ * @since_tizen 3.0
+ *
+ * @param[in] parse_position  The parse position object to destroy
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_destroy(i18n_parse_position_h parse_position);
+
+/**
+ * @brief Creates a polymorphic clone of the given @a parse_position object.
+ * @remarks The @a clone object should be released by the caller with the
+ *          i18n_parse_position_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[in]  parse_position  The parse position object to be cloned
+ * @param[out] clone           The created parse position object
+ *
+ * @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_parse_position_clone(i18n_parse_position_h parse_position, i18n_parse_position_h *clone);
+
+/**
+ * @brief Retrieves the current parse position.
+ * @details On input to a parse method, this is the index of the character
+ *          at which parsing will begin; on output, it is the index of the character
+ *          following the last character parsed.
+ * @since_tizen 3.0
+ *
+ * @param[in]  parse_position  The parse position object
+ * @param[out] index           The current index
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_get_index(i18n_parse_position_h parse_position, int32_t *index);
+
+/**
+ * @brief Sets the current parse position.
+ * @since_tizen 3.0
+ *
+ * @param[in] parse_position  The parse position object
+ * @param[in] index           The new index
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_set_index(i18n_parse_position_h parse_position, int32_t index);
+
+/**
+ * @brief Sets the index at which a parse error occurred.
+ * @details Formatters should set this before returning an error code
+ *          from their parse_object() method. The default value is -1
+ *          if this is not set.
+ * @since_tizen 3.0
+ *
+ * @param[in] parse_position  The parse position object
+ * @param[in] error_index     The error index
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_set_error_index(i18n_parse_position_h parse_position, int32_t error_index);
+
+/**
+ * @brief Retrieves the index at which an error occurred, or -1 if the error index
+ *        has not been set.
+ * @since_tizen 3.0
+ *
+ * @param[in]  parse_position  The parse position object
+ * @param[out] error_index     The index at which an error occurred
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_get_error_index(i18n_parse_position_h parse_position, int32_t *error_index);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UTILS_I18N_PARSE_POSITION_H__*/
index a4e480c..bc22eac 100644 (file)
@@ -2844,7 +2844,7 @@ typedef enum {
     I18N_UMEASFMT_WIDTH_NARROW = 2,   /**< Use symbols for measure units when possible */
     I18N_UMEASFMT_WIDTH_NUMERIC = 3,  /**< Completely omit measure units when possible
                                       For example, format '5 hours, 37 minutes' as '5:37' */
-    I18N_UMEASFMT_WIDTH_COUNT = 4,    /**< Count of values in this enumeration. */
+    I18N_UMEASFMT_WIDTH_COUNT = 4,    /**< Count of values in this enumeration */
 } i18n_umeasure_format_width_e;
 
 /**
@@ -2954,7 +2954,7 @@ typedef enum {
 } i18_alpha_idx_label_type_e;
 
 /**
- * @brief Handle to the object used by the Format and its subtypes to identify fields in a formatted output
+ * @brief Handle to the object used by the Format and its subtypes to identify fields in a formatted output.
  * @since_tizen 3.0
  */
 typedef void *i18n_field_position_h;
@@ -2967,6 +2967,12 @@ typedef enum {
     I18N_FIELD_POSITION_DONT_CARE = -1,
 } i18n_field_position_dont_care_e;
 
+/**
+ * @brief Handle to the object used by the Format and its subtypes to keep track of the current position during parsing.
+ * @since_tizen 3.0
+ */
+typedef void *i18n_parse_position_h;
+
 #ifdef __cplusplus
 }
 #endif
index 1cd482b..3ba2509 100644 (file)
@@ -39,6 +39,7 @@
 #include <utils_i18n_format.h>
 #include <utils_i18n_measure_format.h>
 #include <utils_i18n_field_position.h>
+#include <utils_i18n_parse_position.h>
 
 /**
  * @file utils_i18n.h
@@ -53,7 +54,7 @@ extern "C" {
 /**
  * @ingroup CAPI_BASE_UTILS_MODULE
  * @defgroup CAPI_BASE_UTILS_I18N_MODULE i18n
- * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable, measure, format, measure format and field position.
+ * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable, measure, format, measure format, field position and parse position.
  *        This module provides flexible generation of number or date format patterns and helps you format and parse dates/number for any locale.
  * The i18n module provides various features based on data from ICU. The following table shows the version of ICU used in each Tizen platform.
  * <table>
@@ -157,6 +158,10 @@ extern "C" {
  *       <td>@ref CAPI_BASE_UTILS_I18N_FIELD_POSITION</td>
  *       <td>The Field Position module is used to identify fields in a formatted output.</td>
  * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION</td>
+ *       <td>The Parse Position module used by Format and its subclasses to keep track of the current position during parsing.</td>
+ * </tr>
  * </table>
  *
  * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table
@@ -2908,6 +2913,46 @@ extern "C" {
  *       <td>#i18n_field_position_set_end_index</td>
  *       <td>setEndIndex</td>
  * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_create</td>
+ *       <td>ParsePosition</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_create_with_index</td>
+ *       <td>ParsePosition</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_destroy</td>
+ *       <td>~ParsePosition</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_clone</td>
+ *       <td>clone</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_get_index</td>
+ *       <td>getIndex</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_set_index</td>
+ *       <td>setIndex</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_set_error_index</td>
+ *       <td>setErrorIndex</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE</td>
+ *       <td>#i18n_parse_position_get_error_index</td>
+ *       <td>getErrorIndex</td>
+ * </tr>
  * </table>
  */
 
index a0564ad..a80ae77 100644 (file)
@@ -193,6 +193,10 @@ int i18n_field_position_set_begin_index(i18n_field_position_h field_position, in
  */
 int i18n_field_position_set_end_index(i18n_field_position_h field_position, int32_t end_index);
 
+/**
+ * @}
+ */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/include/wearable/utils_i18n_parse_position.h b/src/include/wearable/utils_i18n_parse_position.h
new file mode 100644 (file)
index 0000000..9666d36
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef __UTILS_I18N_PARSE_POSITION_H__
+#define __UTILS_I18N_PARSE_POSITION_H__
+
+#include <utils_i18n_types.h>
+
+/**
+ * @file utils_i18n_parse_position.h
+ * @version 0.1
+ * @brief utils_i18n_parse_position
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup CAPI_BASE_UTILS_I18N_MODULE
+ * @defgroup CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE ParsePosition
+ * @brief Parse Position is a simple object used by the Format and its subtypes
+ *        to keep track of the current position during parsing.
+ * @section CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE_HEADER Required Header
+ *        \#include <utils_i18n.h>
+ *
+ * @section CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE_OVERVIEW Overview
+ * @details The i18n_format_parse_object() method in the Format types requires
+ * a Parse Position object as an argument.
+ * By design, as you parse through a string with different formats, you can use
+ * the same Parse Position, since the index parameter records the current position.
+ */
+
+/**
+ * @addtogroup CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a parse position object.
+ * @remarks The created object should be released by the caller with the
+ *          i18n_parse_position_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[out] parse_position  The created parse position object
+ *
+ * @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_parse_position_create(i18n_parse_position_h *parse_position);
+
+/**
+ * @brief Creates a parse position object with the given initial index.
+ * @remarks The created object should be released by the caller with the
+ *          i18n_parse_position_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[out] parse_position  The parse position object
+ * @param[in]  new_index       The new text offset
+ *
+ * @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_parse_position_create_with_index(int32_t new_index, i18n_parse_position_h *parse_position);
+
+/**
+ * @brief Destroys the parse position object.
+ * @since_tizen 3.0
+ *
+ * @param[in] parse_position  The parse position object to destroy
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_destroy(i18n_parse_position_h parse_position);
+
+/**
+ * @brief Creates a polymorphic clone of the given @a parse_position object.
+ * @remarks The @a clone object should be released by the caller with the
+ *          i18n_parse_position_destroy() function.
+ * @since_tizen 3.0
+ *
+ * @param[in]  parse_position  The parse position object to be cloned
+ * @param[out] clone           The created parse position object
+ *
+ * @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_parse_position_clone(i18n_parse_position_h parse_position, i18n_parse_position_h *clone);
+
+/**
+ * @brief Retrieves the current parse position.
+ * @details On input to a parse method, this is the index of the character
+ *          at which parsing will begin; on output, it is the index of the character
+ *          following the last character parsed.
+ * @since_tizen 3.0
+ *
+ * @param[in]  parse_position  The parse position object
+ * @param[out] index           The current index
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_get_index(i18n_parse_position_h parse_position, int32_t *index);
+
+/**
+ * @brief Sets the current parse position.
+ * @since_tizen 3.0
+ *
+ * @param[in] parse_position  The parse position object
+ * @param[in] index           The new index
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_set_index(i18n_parse_position_h parse_position, int32_t index);
+
+/**
+ * @brief Sets the index at which a parse error occurred.
+ * @details Formatters should set this before returning an error code
+ *          from their parse_object() method. The default value is -1
+ *          if this is not set.
+ * @since_tizen 3.0
+ *
+ * @param[in] parse_position  The parse position object
+ * @param[in] error_index     The error index
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_set_error_index(i18n_parse_position_h parse_position, int32_t error_index);
+
+/**
+ * @brief Retrieves the index at which an error occurred, or -1 if the error index
+ *        has not been set.
+ * @since_tizen 3.0
+ *
+ * @param[in]  parse_position  The parse position object
+ * @param[out] error_index     The index at which an error occurred
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #I18N_ERROR_NONE Successful
+ * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
+ */
+int i18n_parse_position_get_error_index(i18n_parse_position_h parse_position, int32_t *error_index);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UTILS_I18N_PARSE_POSITION_H__*/
index 26efc0d..8874562 100644 (file)
@@ -2886,7 +2886,7 @@ typedef void *i18n_measure_h;
 typedef void *i18n_measure_unit_h;
 
 /**
- * @brief Callback function for the #i18n_measure_unit_get_available_types()
+ * @brief Callback function for the i18n_measure_unit_get_available_types()
  *        that returns an enumeration over all recognized types.
  * @since_tizen 3.0
  *
@@ -2967,6 +2967,12 @@ typedef enum {
     I18N_FIELD_POSITION_DONT_CARE = -1,
 } i18n_field_position_dont_care_e;
 
+/**
+ * @brief Handle to the object used by the Format and its subtypes to keep track of the current position during parsing.
+ * @since_tizen 3.0
+ */
+typedef void *i18n_parse_position_h;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/utils_i18n_parse_position.cpp b/src/utils_i18n_parse_position.cpp
new file mode 100644 (file)
index 0000000..ef49867
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include <utils_i18n_parse_position.h>
+#include <utils_i18n_private.h>
+
+#include <unicode/parsepos.h>
+
+int i18n_parse_position_create(i18n_parse_position_h *parse_position)
+{
+    retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    *parse_position = new ParsePosition();
+    retv_if(*parse_position == NULL, I18N_ERROR_OUT_OF_MEMORY);
+
+    return I18N_ERROR_NONE;
+}
+
+int i18n_parse_position_create_with_index(int32_t new_index, i18n_parse_position_h *parse_position)
+{
+    retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    *parse_position = new ParsePosition(new_index);
+    retv_if(*parse_position == NULL, I18N_ERROR_OUT_OF_MEMORY);
+
+    return I18N_ERROR_NONE;
+}
+
+int i18n_parse_position_destroy(i18n_parse_position_h parse_position)
+{
+    retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    delete((ParsePosition *) parse_position);
+
+    return I18N_ERROR_NONE;
+}
+
+int i18n_parse_position_clone(i18n_parse_position_h parse_position, i18n_parse_position_h *clone)
+{
+    retv_if(parse_position == NULL || clone == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    *clone = ((ParsePosition *) parse_position)->clone();
+    retv_if(*clone == NULL, I18N_ERROR_OUT_OF_MEMORY);
+
+    return I18N_ERROR_NONE;
+}
+
+int i18n_parse_position_get_index(i18n_parse_position_h parse_position, int32_t *index)
+{
+    retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER);
+    retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    *index = ((ParsePosition *) parse_position)->getIndex();
+
+    return I18N_ERROR_NONE;
+}
+
+int i18n_parse_position_set_index(i18n_parse_position_h parse_position, int32_t index)
+{
+    retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    ((ParsePosition *) parse_position)->setIndex(index);
+
+    return I18N_ERROR_NONE;
+}
+
+int i18n_parse_position_set_error_index(i18n_parse_position_h parse_position, int32_t error_index)
+{
+    retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    ((ParsePosition *) parse_position)->setErrorIndex(error_index);
+
+    return I18N_ERROR_NONE;
+}
+
+int i18n_parse_position_get_error_index(i18n_parse_position_h parse_position, int32_t *error_index)
+{
+    retv_if(parse_position == NULL, I18N_ERROR_INVALID_PARAMETER);
+    retv_if(error_index == NULL, I18N_ERROR_INVALID_PARAMETER);
+
+    *error_index = ((ParsePosition *) parse_position)->getErrorIndex();
+
+    return I18N_ERROR_NONE;
+}