From: RafaƂ Szczekutek Date: Mon, 27 Jun 2016 14:03:34 +0000 (+0200) Subject: [Base-utils][Parse Position] Complete module added X-Git-Tag: submit/tizen/20160628.104345^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86f8bcb7250bfa8163fc03cbd5d29f59f7fff7ce;p=platform%2Fcore%2Fapi%2Fbase-utils.git [Base-utils][Parse Position] Complete module added implementation + documentation Change-Id: I6f237cb0989f1f0c374a4774c156c67f17b0f7ac Signed-off-by: Beata Stefaniuk --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a2df2e..2359c04 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/include/mobile/utils_i18n.h b/src/include/mobile/utils_i18n.h index b155f4d..5d04708 100644 --- a/src/include/mobile/utils_i18n.h +++ b/src/include/mobile/utils_i18n.h @@ -39,6 +39,7 @@ #include #include #include +#include /** * @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. * @@ -157,6 +158,10 @@ extern "C" { * * * + * + * + * + * *
@ref CAPI_BASE_UTILS_I18N_FIELD_POSITIONThe Field Position module is used to identify fields in a formatted output.
@ref CAPI_BASE_UTILS_I18N_PARSE_POSITIONThe Parse Position module used by Format and its subclasses to keep track of the current position during parsing.
* * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -2908,6 +2913,46 @@ extern "C" { * #i18n_field_position_set_end_index * setEndIndex * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_create + * ParsePosition + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_create_with_index + * ParsePosition + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_destroy + * ~ParsePosition + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_clone + * clone + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_get_index + * getIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_set_index + * setIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_set_error_index + * setErrorIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_get_error_index + * getErrorIndex + * * */ diff --git a/src/include/mobile/utils_i18n_parse_position.h b/src/include/mobile/utils_i18n_parse_position.h new file mode 100644 index 0000000..9666d36 --- /dev/null +++ b/src/include/mobile/utils_i18n_parse_position.h @@ -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 + +/** + * @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 + * + * @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__*/ diff --git a/src/include/mobile/utils_i18n_types.h b/src/include/mobile/utils_i18n_types.h index a4e480c..bc22eac 100644 --- a/src/include/mobile/utils_i18n_types.h +++ b/src/include/mobile/utils_i18n_types.h @@ -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 diff --git a/src/include/wearable/utils_i18n.h b/src/include/wearable/utils_i18n.h index 1cd482b..3ba2509 100644 --- a/src/include/wearable/utils_i18n.h +++ b/src/include/wearable/utils_i18n.h @@ -39,6 +39,7 @@ #include #include #include +#include /** * @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. * @@ -157,6 +158,10 @@ extern "C" { * * * + * + * + * + * *
@ref CAPI_BASE_UTILS_I18N_FIELD_POSITIONThe Field Position module is used to identify fields in a formatted output.
@ref CAPI_BASE_UTILS_I18N_PARSE_POSITIONThe Parse Position module used by Format and its subclasses to keep track of the current position during parsing.
* * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -2908,6 +2913,46 @@ extern "C" { * #i18n_field_position_set_end_index * setEndIndex * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_create + * ParsePosition + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_create_with_index + * ParsePosition + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_destroy + * ~ParsePosition + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_clone + * clone + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_get_index + * getIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_set_index + * setIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_set_error_index + * setErrorIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_PARSE_POSITION_MODULE + * #i18n_parse_position_get_error_index + * getErrorIndex + * * */ diff --git a/src/include/wearable/utils_i18n_field_position.h b/src/include/wearable/utils_i18n_field_position.h index a0564ad..a80ae77 100644 --- a/src/include/wearable/utils_i18n_field_position.h +++ b/src/include/wearable/utils_i18n_field_position.h @@ -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 index 0000000..9666d36 --- /dev/null +++ b/src/include/wearable/utils_i18n_parse_position.h @@ -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 + +/** + * @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 + * + * @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__*/ diff --git a/src/include/wearable/utils_i18n_types.h b/src/include/wearable/utils_i18n_types.h index 26efc0d..8874562 100644 --- a/src/include/wearable/utils_i18n_types.h +++ b/src/include/wearable/utils_i18n_types.h @@ -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 index 0000000..ef49867 --- /dev/null +++ b/src/utils_i18n_parse_position.cpp @@ -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 +#include + +#include + +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; +}