From 0d34ee90e425210fffa07f3c1b7e85cf331ff6e4 Mon Sep 17 00:00:00 2001 From: Hyunjee Kim Date: Thu, 7 Nov 2019 16:52:35 +0900 Subject: [PATCH] [ACR-1538][Ures] Module implementation Change-Id: Ib3c1f44fca384ec845e61f0a9c0c8d837053d96f Signed-off-by: Hyunjee Kim --- src/CMakeLists.txt | 2 + src/include/utils_i18n.h | 131 ++++++++ src/include/utils_i18n_types.h | 39 +++ src/include/utils_i18n_ures.h | 528 +++++++++++++++++++++++++++++++++ src/utils_i18n_private.cpp | 2 + src/utils_i18n_ures.c | 335 +++++++++++++++++++++ 6 files changed, 1037 insertions(+) create mode 100644 src/include/utils_i18n_ures.h create mode 100644 src/utils_i18n_ures.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad7c884..fcc5520 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,7 @@ SET(BASEUTILS_SRCS utils_i18n_ucnv.c utils_i18n_ucnvsel.c utils_i18n_ucsdet.c + utils_i18n_ures.c utils_i18n_plural_rules.cpp utils_i18n_plural_format.cpp utils_i18n_immutable_idx.cpp @@ -115,5 +116,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_uidna.h DESTINAT INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ucnv.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ucnvsel.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ucsdet.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ures.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) diff --git a/src/include/utils_i18n.h b/src/include/utils_i18n.h index 538cf98..d5fe606 100644 --- a/src/include/utils_i18n.h +++ b/src/include/utils_i18n.h @@ -59,6 +59,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -111,6 +112,7 @@ extern "C" { * - Character conversion * - Converter selector * - Charset Detection + * - resource bundle * * 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. @@ -301,6 +303,10 @@ extern "C" { * @ref CAPI_BASE_UTILS_I18N_UCHARSET_DETECTION_MODULE * Detecting the charset or encoding of character data in an unknown text format * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * Resource Bundle. + * * * * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -4950,6 +4956,131 @@ extern "C" { * #i18n_ucsdet_enable_input_filter * ucsdet_enableInputFilter * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_create + * ures_open + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_create_direct + * ures_openDirect + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_create_unicode + * ures_openU + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_destroy + * ures_close + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_version + * ures_getVersion + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_locale_by_type + * ures_getLocaleByType + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_string + * ures_getString + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_UTF8_string + * ures_getUTF8String + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_binary + * ures_getBinary + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_int_vector + * ures_getIntVector + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_uint + * ures_getUInt + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_int + * ures_getInt + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_size + * ures_getSize + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_type + * ures_getType + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_key + * ures_getKey + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_reset_iterator + * ures_resetIterator + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_has_next + * ures_hasNext + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_next_resource + * ures_getNextResource + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_next_string + * ures_getNextString + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_by_index + * ures_getByIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_string_by_index + * ures_getStringByIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_UTF8_string_by_index + * ures_getUTF8StringByIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_by_key + * ures_getByKey + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_string_by_key + * ures_getStringByKey + * + * + * @ref CAPI_BASE_UTILS_I18N_URES_MODULE + * #i18n_ures_get_UTF8_string_by_key + * ures_getUTF8StringByKey + * * */ diff --git a/src/include/utils_i18n_types.h b/src/include/utils_i18n_types.h index 47aac46..f1aa8cd 100644 --- a/src/include/utils_i18n_types.h +++ b/src/include/utils_i18n_types.h @@ -33,6 +33,7 @@ */ #ifdef __cplusplus + extern "C" { #endif @@ -84,6 +85,8 @@ typedef enum { I18N_ERROR_STD3_ASCII_RULES = TIZEN_ERROR_UTILITY_ICU | 0x1E, /**< Argument does not satisfy STD3 rules. @if MOBILE (Since 2.3.1) @endif*/ I18N_ERROR_UNASSIGNED = TIZEN_ERROR_UTILITY_ICU | 0x1F, /**< Unassigned code points are found. @if MOBILE (Since 2.3.1) @endif*/ I18N_WARNING_SORT_KEY_TOO_SHORT = TIZEN_ERROR_UTILITY_ICU | 0x20, /**< Number of levels requested in getBound is higher than the number of levels in the sort key. @if MOBILE (Since 2.3.1) @endif*/ + I18N_WARNING_USING_FALLBACK = TIZEN_ERROR_UTILITY_ICU | 0x21, /**< A resource bundle lookup returned a fallback result (not an error) (Since 6.0)*/ + I18N_WARNING_USING_DEFAULT = TIZEN_ERROR_UTILITY_ICU | 0x22, /**< A resource bundle lookup returned a result from the root locale (not an error) (Since 6.0)*/ I18N_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Unknown error. @if MOBILE (Since 2.3.1) @endif*/ /** Errors connected with transliteration text from one format to another */ @@ -4819,6 +4822,42 @@ typedef void *i18n_ucharset_detector_h; */ typedef void *i18n_ucharset_match_h; +/** + * @} + */ + +/** +* @addtogroup CAPI_BASE_UTILS_I18N_URES_MODULE +* @{ +*/ + +/** + * @brief An #i18n_ures_h handle. + * @details Use i18n_ures_* functions to operate on #i18n_ures_h objects. + * @since_tizen 6.0 + */ +typedef void *i18n_ures_h; + +/** + * @brief Numeric constants for types of resource items. + * @since_tizen 6.0 + */ +typedef enum { + I18N_URES_NONE=-1, /**< Resource type constant for "no resource".*/ + I18N_URES_STRING=0, /**< Resource type constant for 16-bit Unicode strings. */ + I18N_URES_BINARY=1, /**< Resource type constant for binary data. */ + I18N_URES_TABLE=2, /**< Resource type constant for tables of key-value pairs. */ + I18N_URES_ALIAS=3, /**< Resource type constant for aliases; + internally stores a string which identifies the actual resource + storing the data (can be in a different resource bundle). + Resolved internally before delivering the actual resource through the API. */ + I18N_URES_INT=7, /**< Resource type constant for a single 28-bit integer, interpreted as + signed or unsigned by the i18n_ures_getInt() or i18n_ures_getUInt() function. */ + I18N_URES_ARRAY=8, /**< Resource type constant for arrays of resources. */ + I18N_URES_INT_VECTOR = 14, /**< Resource type constant for vectors of 32-bit integers. */ + +} i18n_ures_type_e; + /** * @} */ diff --git a/src/include/utils_i18n_ures.h b/src/include/utils_i18n_ures.h new file mode 100644 index 0000000..133fdf6 --- /dev/null +++ b/src/include/utils_i18n_ures.h @@ -0,0 +1,528 @@ +/* + * Copyright (c) 2020 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_URES_H__ +#define __UTILS_I18N_URES_H__ + +#include + +/** + * @file utils_i18n_ures.h + * @version 0.1 + * @brief utils_i18n_uclean + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_URES_MODULE Ures + * @brief Ures module provides API for Resource Bundle. + * + * @section CAPI_BASE_UTILS_I18N_URES_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_BASE_UTILS_I18N_URES_MODULE_OVERVIEW Overview + * @details C API representing a collection of resource information pertaining to a given + * locale. A resource bundle provides a way of accessing locale- specific information in + * a data file. You create a resource bundle that manages the resources for a given + * locale and then ask it for individual resources. + *

+ * Resource bundles in ICU4C are currently defined using text files which conform to the following + * BNF definition. + * More on resource bundle concepts and syntax can be found in the + * Users Guide. + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_URES_MODULE + * @{ + */ + +/** + * @brief Creates a #i18n_ures_h, from which users can extract strings by using their corresponding keys. + * @since_tizen 6.0 + * @remarks The @a ures should be released using i18n_ures_destroy(). + * @param[in] package_name The @a package_name and @a locale together point to an #i18n_ures_h. + * Typically, @a package_name will refer to a (.dat) file. + * Using a full file or directory pathname for @a package_name is deprecated. If NULL, ICU data will be used. + * @param[in] locale Specifies the locale for which we want to create the resource + * If NULL, the default locale will be used. If strlen(locale) == 0 root locale will be used. + * @param[out] ures A new #i18n_ures_h. + * @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 + * @see i18n_ures_destroy() + */ +int i18n_ures_create(const char *package_name, const char *locale, i18n_ures_h *ures); + +/** + * @brief Creates a #i18n_ures_h and does not care what kind of localeID is passed in. + * @details It simply creates a resource bundle with @a package_name. Fallback mechanism is disabled for the new resource bundle. + * If the requested bundle contains an %ALIAS directive, the results are undefined. + * @since_tizen 6.0 + * @remarks The @a ures should be released using i18n_ures_destroy(). + * @param[in] package_name The @a package_name and @a locale together point to an #i18n_ures_h. + * Typically, @a package_name will refer to a (.dat) file. + * Using a full file or directory pathname for @a package_name is deprecated. If NULL, ICU data will be used. + * @param[in] locale Specifies the locale for which we want to create the resource + * If NULL, the default locale will be used. If strlen(locale) == 0 root locale will be used. + * @param[out] ures A new #i18n_ures_h. + * @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 + * @retval #I18N_ERROR_MISSING_RESOURCE The requested resource cannot be found + * + */ +int i18n_ures_create_direct(const char *package_name, const char *locale, i18n_ures_h *ures); + +/** + * @brief Creates a #i18n_ures_h. + * @details @a package_name will be converted to char * using the default converter, then i18n_ures_create() is called. + * @since_tizen 6.0 + * @remarks The @a ures should be released using i18n_ures_destroy(). + * @param[in] package_name The @a package_name and @a locale together point to an #i18n_ures_h. + * Typically, @a package_name will refer to a (.dat) file. + * Using a full file or directory pathname for @a package_name is deprecated. If NULL, ICU data will be used. + * @param[in] locale Specifies the locale for which we want to create the resource + * If NULL, the default locale will be used. If strlen(locale) == 0 root locale will be used. + * @param[out] ures A new #i18n_ures_h. + * @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 + * @see i18n_ures_create() + * + */ +int i18n_ures_create_unicode(const i18n_uchar *package_name, const char *locale, i18n_ures_h *ures); + +/** + * @brief Destroys an #i18n_ures_h, all pointers returned from the various i18n_ures_getXXX calls on this particular resource bundle should be considered invalid henceforth. + * @since_tizen 6.0 + * @param[in] ures An #i18n_ures_h. + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @see i18n_ures_create() + * + */ +int i18n_ures_destroy(i18n_ures_h ures); + +/** + * @brief Gets the version number associated with the #i18n_ures_h as an #i18n_uversion_info array. + * @since_tizen 6.0 + * @param[in] ures The resource bundle for which the version is checked. + * @param[out] version_array A #i18n_uversion_info array that is filled with the version number as specified in the resource bundle or its parent. + * @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_ures_get_version(i18n_ures_h ures, i18n_uversion_info version_array); + +/** + * @brief Gets the name of the locale associated with @a ures. + * You can choose between requested, valid and real locale. + * @since_tizen 6.0 + * @remarks The @a locale is available until @a ures is released. + * @param[in] ures An #i18n_ures_h. + * @param[in] type You can choose between requested, valid and actual locale. + * For description see the definition of #i18n_ulocale_data_locale_type_e + * @param[out] locale A Locale name + * @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_ures_get_locale_by_type(i18n_ures_h ures, i18n_ulocale_data_locale_type_e type, const char **locale); + +/** + * @brief Gets a string from an #i18n_ures_h. + * @since_tizen 6.0 + * @remarks The @a str_result is available until @a ures is released. + * @param[in] ures An #i18n_ures_h. + * @param[out] len The length of resulting string + * @param[out] str_result The pointer to a zero-terminated #i18n_uchar array which lives in a memory mapped/DLL file. + * @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_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * @see i18n_ures_get_binary() + * @see i18n_ures_get_int_vector() + * @see i18n_ures_get_int() + * @see i18n_ures_get_uint() + * + */ +int i18n_ures_get_string(i18n_ures_h ures, int32_t *len, const i18n_uchar **str_result); + +/** + * @brief Gets a UTF-8 string from a string resource. + * @details The UTF-8 string may be returnable directly as a pointer, or it may need to be copied, + * or transformed from UTF-16 using i18n_ustring_to_UTF8() or equivalent. + * If @a force_copy==TRUE, then the string is always written to the dest buffer and dest is returned. + * If @a force_copy==FALSE, then the string is returned as a pointer if possible, without needing a dest buffer (it can be NULL). + * If the string needs to be copied or transformed, then it may be placed into dest at an arbitrary offset. + * If the string is to be written to dest, then #I18N_ERROR_BUFFER_OVERFLOW is set if appropriate, as usual. + * If the string is transformed from UTF-16, then a conversion error may occur if an unpaired surrogate is encountered. + * If the function is successful, then the output UTF-8 string is always well-formed. + * @since_tizen 6.0 + * @remarks The @a str_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[out] dest Destination buffer. Can be NULL only if capacity=*length==0. + * @param[in,out] len Input: Capacity of destination buffer. + * Output: Actual length of the UTF-8 string, not counting the terminating NUL, + * even in case of #I18N_ERROR_BUFFER_OVERFLOW. Can be NULL, meaning capacity=0 and the string length is not returned to the caller. + * @param[in] force_copy If TRUE, then the output string will always be written to dest, + * with #I18N_ERROR_BUFFER_OVERFLOW set if appropriate. + * If FALSE, then the dest buffer may or may not contain a copy of the string. dest may or may not be modified. + * If a copy needs to be written, then retval indicates overflow etc. as usual. + * @param[out] str_result The pointer to the UTF-8 string. It may be dest, or at some offset from dest (only if !force_copy), or in unrelated memory. + * Always NUL-terminated unless the string was written to dest and length==capacity. + * @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 A result would not fit in the supplied buffer + * @retval #I18N_ERROR_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * @see i18n_ures_get_string() + * @see i18n_ustring_to_UTF8() + * + */ +int i18n_ures_get_UTF8_string(i18n_ures_h ures, char *dest, int32_t *len, i18n_ubool force_copy, const char **str_result); + +/** + * @brief Gets a binary data from a binary resource. + * @since_tizen 6.0 + * @remarks The @a binary_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[out] len The length of resulting byte chunk + * @param[out] binary_result A pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file. + * @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_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * @see i18n_ures_get_string() + * @see i18n_ures_get_int_vector() + * @see i18n_ures_get_int() + * @see i18n_ures_get_uint() + * + */ +int i18n_ures_get_binary(i18n_ures_h ures, int32_t *len, const uint8_t **binary_result); + +/** + * @brief Gets a 32 bit integer array from a resource. + * @since_tizen 6.0 + * @remarks The @a int_vector_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[out] len The length of resulting byte chunk + * @param[out] int_vector_result A pointer to a chunk of integers which live in a memory mapped/DLL file. + * @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_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * @see i18n_ures_get_string() + * @see i18n_ures_get_binary() + * @see i18n_ures_get_int() + * @see i18n_ures_get_uint() + * + */ +int i18n_ures_get_int_vector(i18n_ures_h ures, int32_t *len, const int32_t **int_vector_result); + +/** + * @brief Gets an unsigned integer from a resource. This integer is originally 28 bits. + * @since_tizen 6.0 + * @param[in] ures Resource bundle. + * @param[out] uint_result An integer value. + * @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_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * @see i18n_ures_get_string() + * @see i18n_ures_get_binary() + * @see i18n_ures_get_int() + * @see i18n_ures_get_int_vector() + * + */ +int i18n_ures_get_uint(i18n_ures_h ures, uint32_t *uint_result); + +/** + * @brief Gets a signed integer from a resource. + * This integer is originally 28 bit and the sign gets propagated. + * @since_tizen 6.0 + * @param[in] ures Resource bundle. + * @param[out] int_result An integer value. + * @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_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * @see i18n_ures_get_string() + * @see i18n_ures_get_binary() + * @see i18n_ures_get_uint() + * @see i18n_ures_get_int_vector() + * + */ +int i18n_ures_get_int(i18n_ures_h ures, int32_t *int_result); + +/** + * @brief Gets the size of a resource. + * @details Size for scalar types is always 1, and for vector/table types is the number of child resources. + * @since_tizen 6.0 + * @warning Integer array is treated as a scalar type. There are no APIs to access individual members of an integer array. It is always returned as a whole. + * @param[in] ures Resource bundle. + * @param[out] size_result The number of resources in a given resource. + * @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_ures_get_size(i18n_ures_h ures, int32_t *size_result); + +/** + * @brief Gets the type of a resource. Available types are defined in enum #i18n_ures_type_e. + * @since_tizen 6.0 + * @param[in] ures Resource bundle. + * @param[out] type_result Type of the given resource. + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @see i18n_ures_type_e + * + */ +int i18n_ures_get_type(i18n_ures_h ures, i18n_ures_type_e *type_result); + +/** + * @brief Gets the key associated with a given resource. + * Not all the resources have a key - only those that are members of a table. + * @since_tizen 6.0 + * @remarks The @a key_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[out] key_result A key associated to this resource, or NULL if it doesn't have a key + * @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_ures_get_key(i18n_ures_h ures, const char **key_result); + +/** + * @brief Resets the internal context of a resource so that iteration starts from the first element. + * @since_tizen 6.0 + * @param[in] ures Resource bundle. + * @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_ures_reset_iterator(i18n_ures_h ures); + +/** + * @brief Checks whether the given resource has another element to iterate over. + * @since_tizen 6.0 + * @param[in] ures Resource bundle. + * @param[out] has_next TRUE if there are more elements, FALSE if there is no more elements + * @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_ures_has_next(i18n_ures_h ures, bool *has_next); + +/** + * @brief Gets the next resource in a given resource or NULL if there are no more resources to iterate over. Features a fill-in parameter. + * @details If @a fill_in is not NULL, it will be filled with the next resource, and a new #i18n_ures_h in @a result will not be created. + * If @a fill_in is NULL, then @a result will be set to a new #i18n_ures_h containing the next resource. + * + * If there are no more resources to iterate over, @a result will be set to NULL. + * + * This function may set @a result to a non-NULL value even if an error occurs. This function's return value should be checked. + * @since_tizen 6.0 + * @remarks If @a fill_in is NULL, the @a result should be released using i18n_ures_destroy(). + * @param[in] ures Resource bundle. + * @param[in,out] fill_in A #i18n_ures_h handle. It can be NULL. + * @param[out] result Cannot be NULL. Will be set to a new #i18n_ures_h if @a fill_in is NULL. Will be set to NULL if there are no more resources to iterate over. + * @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_ures_get_next_resource(i18n_ures_h ures, i18n_ures_h fill_in, i18n_ures_h *result); + +/** + * @brief Gets the next string in a given resource + * or NULL if there are no more resources to iterate over. + * @since_tizen 6.0 + * @remarks The @a key is available until @a ures is released. + * @remarks The @a str_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[out] len Fill in length of the string + * @param[out] key Fill in for key associated with this string. NULL if no key + * @param[out] str_result A pointer to a zero-terminated #i18n_uchar array which lives in a memory mapped/DLL file. + * @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_ures_get_next_string(i18n_ures_h ures, int32_t *len, const char **key, const i18n_uchar **str_result); + +/** + * @brief Gets the resource in a given resource at the specified index. Features a fill-in parameter. + * @details If @a fill_in is not NULL, it will be filled with output data, and @a result will not be created. @a result can be NULL in this case. + * If @a fill_in is NULL, then a new handle will be created in @a result. @a result cannot be NULL in this case. + * This function may set @a ures_result to a non-NULL value even if an error occurs. This function's return value should be checked. + * @since_tizen 6.0 + * @remarks If @a fill_in is NULL, the @a result should be released using i18n_ures_destroy(). + * @param[in] ures Resource bundle. + * @param[in] index_r An index to the wanted resource. + * @param[in,out] fill_in A #i18n_ures_h handle. It can be NULL. + * @param[out] ures_result A new #i18n_ures_h if @a fill_in is NULL. Otherwise no changes are made to this parameter. + * @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_ures_get_by_index(i18n_ures_h ures, int32_t index_r, i18n_ures_h fill_in, i18n_ures_h *ures_result); + +/** + * @brief Gets the string in a given resource at the specified index. + * @since_tizen 6.0 + * @remarks The @a str_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[in] index_s An index to the wanted string + * @param[out] len Fill in length of the string + * @param[out] str_result A pointer to a zero-terminated #i18n_uchar array which lives in a memory mapped/DLL file. + * @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_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * + * + */ +int i18n_ures_get_string_by_index(i18n_ures_h ures, int32_t index_s, int32_t *len, const i18n_uchar **str_result); + +/** + * @brief Gets a UTF-8 string from a resource at the specified index. + * @details The UTF-8 string may be returnable directly as a pointer, or it may need to be copied, + * or transformed from UTF-16 using #i18n_ustring_to_UTF8() or equivalent. + * If force_copy==TRUE, then the string is always written to the dest buffer and dest is returned. + * If force_copy==FALSE, then the string is returned as a pointer if possible, without needing a dest buffer (it can be NULL). + * If the string needs to be copied or transformed, then it may be placed into dest at an arbitrary offset. + * If the string is to be written to dest, then #I18N_ERROR_BUFFER_OVERFLOW is set if appropriate, as usual. + * If the string is transformed from UTF-16, then a conversion error may occur if an unpaired surrogate is encountered. + * If the function is successful, then the output UTF-8 string is always well-formed. + * @since_tizen 6.0 + * @remarks The @a str_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[in] index_s An index to the wanted string + * @param[out] dest Destination buffer. Can be NULL only if capacity=*length==0. + * @param[in,out] len Input: Capacity of destination buffer. + * Output: Actual length of the UTF-8 string, not counting the terminating NUL, + * even in case of #I18N_ERROR_BUFFER_OVERFLOW. Can be NULL, meaning capacity=0 and the string length is not returned to the caller. + * @param[in] force_copy If TRUE, then the output string will always be written to dest, + * with #I18N_ERROR_BUFFER_OVERFLOW set if appropriate. + * If FALSE, then the dest buffer may or may not contain a copy of the string. dest may or may not be modified. + * If a copy needs to be written, then the I18N_ERROR parameter indicates overflow etc. as usual. + * @param[out] str_result The pointer to the UTF-8 string. It may be dest, or at some offset from dest (only if !force_copy), or in unrelated memory. + * Always NUL-terminated unless the string was written to dest and length==capacity. + * @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 A result would not fit in the supplied buffer + * @retval #I18N_ERROR_RESOURCE_TYPE_MISMATCH An operation is requested over a resource that does not support it. + * @see i18n_ures_get_string_by_index() + * @see i18n_ustring_to_UTF8() + * + */ +int i18n_ures_get_UTF8_string_by_index(i18n_ures_h ures, int32_t index_s, char *dest, int32_t *len, i18n_ubool force_copy, const char **str_result); + +/** + * @brief Gets a resource in a given resource that has a given key. + * This procedure works only with table resources. Features a fill-in parameter. + * @details If @a fill_in is not NULL, it will be filled with output data, and @a result will not be created. @a result can be NULL in this case. + * If @a fill_in is NULL, then a new handle will be created in @a result. @a result cannot be NULL in this case. + * @since_tizen 6.0 + * @remarks If @a fill_in is NULL, the @a result should be released using i18n_ures_destroy(). + * @param[in] ures Resource bundle. + * @param[in] key A key associated with the wanted resource + * @param[in,out] fill_in A #i18n_ures_h handle. It can be NULL. + * @param[out] ures_result A new #i18n_ures_h if @a fill_in is NULL. Otherwise no changes are made to this parameter. + * @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_ures_get_by_key(i18n_ures_h ures, const char *key, i18n_ures_h fill_in, i18n_ures_h *ures_result); + +/** + * @brief Gets a string in a given resource that has a given key. + * This procedure works only with table resources. + * @since_tizen 6.0 + * @remarks The @a str_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[in] key A key associated with the wanted resource + * @param[out] len Fills in length of the string + * @param[out] str_result A pointer to a zero-terminated #i18n_uchar array which lives in a memory mapped/DLL file. + * @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_ures_get_string_by_key(i18n_ures_h ures, const char *key, int32_t *len, const i18n_uchar **str_result); + +/** + * @brief Gets a UTF-8 string from a resource and a key. This function works only with table resources. + * @details The UTF-8 string may be returnable directly as a pointer, or it may need to be copied, + * or transformed from UTF-16 using #i18n_ustring_to_UTF8() or equivalent. + * If force_copy==TRUE, then the string is always written to the dest buffer and dest is returned. + * If force_copy==FALSE, then the string is returned as a pointer if possible, without needing a dest buffer (it can be NULL). + * If the string needs to be copied or transformed, then it may be placed into dest at an arbitrary offset. + * If the string is to be written to dest, then #I18N_ERROR_BUFFER_OVERFLOW is set if appropriate, as usual. + * If the string is transformed from UTF-16, then a conversion error may occur if an unpaired surrogate is encountered. + * If the function is successful, then the output UTF-8 string is always well-formed. + * @since_tizen 6.0 + * @remarks The @a str_result is available until @a ures is released. + * @param[in] ures Resource bundle. + * @param[in] key A key associated with the wanted resource + * @param[out] dest Destination buffer. Can be NULL only if capacity=*length==0. + * @param[in,out] len Input: Capacity of destination buffer. + * Output: Actual length of the UTF-8 string, not counting the terminating NUL, + * even in case of #I18N_ERROR_BUFFER_OVERFLOW. Can be NULL, meaning capacity=0 and the string length is not returned to the caller. + * @param[in] force_copy If TRUE, then the output string will always be written to dest, + * with #I18N_ERROR_BUFFER_OVERFLOW set if appropriate. + * If FALSE, then the dest buffer may or may not contain a copy of the string. dest may or may not be modified. + * If a copy needs to be written, then the I18N_ERROR parameter indicates overflow etc. as usual. + * @param[out] str_result The pointer to the UTF-8 string. It may be dest, or at some offset from dest (only if !force_copy), or in unrelated memory. + * Always NUL-terminated unless the string was written to dest and length==capacity. + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @see i18n_ures_get_string_by_key() + * @see i18n_ustring_to_UTF8() + * + */ +int i18n_ures_get_UTF8_string_by_key(i18n_ures_h ures, const char *key, char *dest, int32_t *len, i18n_ubool force_copy, const char **str_result); +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_URES_H__ */ + diff --git a/src/utils_i18n_private.cpp b/src/utils_i18n_private.cpp index ad2dfde..0f7bc2d 100644 --- a/src/utils_i18n_private.cpp +++ b/src/utils_i18n_private.cpp @@ -27,6 +27,8 @@ int _i18n_error_mapping(int err) { err_map.insert(make_pair(U_STRING_NOT_TERMINATED_WARNING, I18N_WARNING_STRING_NOT_TERMINATED)); err_map.insert(make_pair(U_SORT_KEY_TOO_SHORT_WARNING, I18N_WARNING_SORT_KEY_TOO_SHORT)); err_map.insert(make_pair(U_AMBIGUOUS_ALIAS_WARNING, I18N_WARNING_AMBIGUOUS_ALIAS)); + err_map.insert(make_pair(U_USING_FALLBACK_WARNING, I18N_WARNING_USING_FALLBACK)); + err_map.insert(make_pair(U_USING_DEFAULT_WARNING, I18N_WARNING_USING_DEFAULT)); err_map.insert(make_pair(U_ZERO_ERROR, I18N_ERROR_NONE)); err_map.insert(make_pair(U_ILLEGAL_ARGUMENT_ERROR, I18N_ERROR_INVALID_PARAMETER)); err_map.insert(make_pair(U_MISSING_RESOURCE_ERROR, I18N_ERROR_MISSING_RESOURCE)); diff --git a/src/utils_i18n_ures.c b/src/utils_i18n_ures.c new file mode 100644 index 0000000..64eff0f --- /dev/null +++ b/src/utils_i18n_ures.c @@ -0,0 +1,335 @@ +/* +* Copyright (c) 2020 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_ures_create(const char *package_name, const char *locale, i18n_ures_h *ures ) +{ + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + *ures = ures_open(package_name, locale, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_create_direct(const char *package_name, const char *locale, i18n_ures_h *ures) +{ + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + *ures = ures_openDirect(package_name, locale, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_create_unicode(const i18n_uchar *package_name, const char *locale, i18n_ures_h *ures) +{ + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + *ures = ures_openU(package_name, locale, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_destroy(i18n_ures_h ures) +{ + retv_if(ures == NULL, I18N_ERROR_INVALID_PARAMETER); + + ures_close(ures); + + return I18N_ERROR_NONE; +} + +int i18n_ures_get_version(i18n_ures_h ures, i18n_uversion_info version_array) +{ + retv_if(ures == NULL, I18N_ERROR_INVALID_PARAMETER); + + ures_getVersion(ures, version_array); + + return I18N_ERROR_NONE; +} + +int i18n_ures_get_locale_by_type(i18n_ures_h ures, i18n_ulocale_data_locale_type_e type, const char **locale) +{ + retv_if(ures == NULL || (type < I18N_ULOCALE_DATA_LOCALE_TYPE_ACTUAL_LOCALE || type > I18N_ULOCALE_DATA_LOCALE_TYPE_LIMIT), I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *locale = ures_getLocaleByType(ures, type, &icu_error); + + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_string(i18n_ures_h ures, int32_t *len, const i18n_uchar **str_result) +{ + retv_if(ures == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *str_result = ures_getString(ures, len, &icu_error); + + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_UTF8_string(i18n_ures_h ures, char *dest, int32_t *len, i18n_ubool force_copy, const char **str_result) +{ + retv_if(ures == NULL || force_copy == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *str_result = ures_getUTF8String(ures, dest, len, force_copy, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_binary(i18n_ures_h ures, int32_t *len, const uint8_t **binary_result) +{ + retv_if(ures == NULL || binary_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *binary_result = ures_getBinary(ures, *len, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_int_vector(i18n_ures_h ures, int32_t *len, const int32_t **int_vector_result) +{ + retv_if(ures == NULL || int_vector_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *int_vector_result = ures_getIntVector(ures, len, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_uint(i18n_ures_h ures, uint32_t *uint_result) +{ + retv_if(ures == NULL || uint_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *uint_result = ures_getUInt(ures, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_int(i18n_ures_h ures, int32_t *int_result) +{ + retv_if(ures == NULL || int_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *int_result = ures_getInt(ures, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_size(i18n_ures_h ures, int32_t *size_result) +{ + retv_if(ures == NULL || size_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + *size_result = ures_getSize(ures); + retv_if(size_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + return I18N_ERROR_NONE; +} + +int i18n_ures_get_type(i18n_ures_h ures, i18n_ures_type_e *type_result) +{ + retv_if(ures == NULL || type_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + *type_result = ures_getType(ures); + retv_if(type_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + return I18N_ERROR_NONE; +} + +int i18n_ures_get_key(i18n_ures_h ures, const char **key_result) +{ + retv_if(ures == NULL || key_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + *key_result = ures_getKey(ures); + retv_if(key_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + return I18N_ERROR_NONE; +} + +int i18n_ures_reset_iterator(i18n_ures_h ures) +{ + retv_if(ures == NULL, I18N_ERROR_INVALID_PARAMETER); + + ures_resetIterator(ures); + + return I18N_ERROR_NONE; +} + +int i18n_ures_has_next(i18n_ures_h ures, bool *has_next) +{ + retv_if(ures == NULL || has_next == NULL, I18N_ERROR_INVALID_PARAMETER); + + *has_next = ures_hasNext(ures); + + return I18N_ERROR_NONE; +} + +int i18n_ures_get_next_resource(i18n_ures_h ures, i18n_ures_h fill_in, i18n_ures_h *result) +{ + retv_if(ures == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *result = ures_getNextResource(ures, fill_in, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_next_string(i18n_ures_h ures, int32_t *len, const char **key, const i18n_uchar **str_result) +{ + retv_if(ures == NULL || len == NULL || key == NULL || str_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *str_result = ures_getNextString(ures, len, key, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_by_index(i18n_ures_h ures, int32_t index_r, i18n_ures_h fill_in, i18n_ures_h *ures_result) +{ + retv_if(ures == NULL || ures_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *ures_result = ures_getByIndex(ures, index_r, fill_in, &icu_error); + + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_string_by_index(i18n_ures_h ures, int32_t index_s, int32_t *len, const i18n_uchar **str_result) +{ + retv_if(ures == NULL || str_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *str_result = ures_getStringByIndex(ures, index_s, len, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_UTF8_string_by_index(i18n_ures_h ures, int32_t index_s, char *dest, int32_t *len, i18n_ubool force_copy, const char **str_result) +{ + retv_if(ures == NULL || index_s < 0 || dest == NULL || str_result == NULL + || (force_copy != FALSE && force_copy != TRUE), I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *str_result = ures_getUTF8StringByIndex(ures, index_s, dest, len, force_copy, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_by_key(i18n_ures_h ures, const char *key, i18n_ures_h fill_in, i18n_ures_h *ures_result) +{ + retv_if(ures == NULL || key == NULL || ures_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *ures_result = ures_getByKey(ures, key, fill_in, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_string_by_key(i18n_ures_h ures, const char *key, int32_t *len, const i18n_uchar **str_result) +{ + retv_if(ures == NULL || key == NULL || str_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *str_result = ures_getStringByKey(ures, key, len, &icu_error); + + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} + +int i18n_ures_get_UTF8_string_by_key(i18n_ures_h ures, const char *key, char *dest, int32_t *len, i18n_ubool force_copy, const char **str_result) +{ + retv_if(ures == NULL || key == NULL || dest == NULL || + len == NULL || str_result == NULL, I18N_ERROR_INVALID_PARAMETER); + + i18n_error_code_e i18n_error; + UErrorCode icu_error = U_ZERO_ERROR; + + *str_result = ures_getUTF8StringByKey(ures, key, dest, len, force_copy, &icu_error); + ERR_MAPPING(icu_error, i18n_error); + I18N_ERR(i18n_error); + + return i18n_error; +} -- 2.34.1