From: Rafał Szczekutek Date: Fri, 24 Jun 2016 16:40:04 +0000 (+0200) Subject: [Base-utils][AlphabeticIndex] Complete module added X-Git-Tag: submit/tizen/20160627.042525^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F01%2F74801%2F12;p=platform%2Fcore%2Fapi%2Fbase-utils.git [Base-utils][AlphabeticIndex] Complete module added Change-Id: Ib0612ff3ff85f38100b1a4d06d45eda394a6eed2 Signed-off-by: Rafał Szczekutek Signed-off-by: Jakub Siewierski --- diff --git a/packaging/capi-base-utils.spec b/packaging/capi-base-utils.spec index 7887d68..0ac8647 100755 --- a/packaging/capi-base-utils.spec +++ b/packaging/capi-base-utils.spec @@ -1,6 +1,6 @@ Name: capi-base-utils Summary: Base Utils -Version: 1.2.3 +Version: 1.2.4 Release: 1 Group: Base License: Apache-2.0 and ICU diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b858ab8..0a23693 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,7 @@ SET(BASEUTILS_SRCS utils_i18n_uset.c utils_i18n_ubrk.c utils_i18n_timezone.cpp + utils_i18n_alpha_idx.cpp ) ADD_LIBRARY(${target_name} SHARED ${BASEUTILS_SRCS} @@ -67,5 +68,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_timezone.h DESTI INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_uenumeration.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_uset.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ubrk.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_alpha_idx.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/mobile/utils_i18n.h b/src/include/mobile/utils_i18n.h index 3bdb929..13b23bc 100644 --- a/src/include/mobile/utils_i18n.h +++ b/src/include/mobile/utils_i18n.h @@ -32,6 +32,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -46,7 +47,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 and unumber. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber and alpha_idx. * 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. * @@ -123,6 +124,10 @@ extern "C" { * * * + * + * + * + * *
@ref CAPI_BASE_UTILS_I18N_UNUMBER_MODULEUnumber helps you format and parse numbers for any locale.
@ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULEAlpha_idx supports the creation of a UI index appropriate for a given language.
* * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -1778,6 +1783,136 @@ extern "C" { * #i18n_ustring_from_UTF32_with_sub * u_strFromUTF32WithSub * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_create + * AlphabeticIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_destroy + * ~AlphabeticIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_add_labels + * addLabels + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_add_record + * addRecord + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_next_bucket + * nextBucket + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_next_record + * nextRecord + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_record_count + * getBucketRecordCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_label + * getBucketLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_record_data + * getRecordData + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_inflow_label + * getInflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_inflow_label + * setInflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_overflow_label + * getOverflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_overflow_label + * setOverflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_underflow_label + * getUnderflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_underflow_label + * setUnderflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_max_label_count + * getMaxLabelCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_max_label_count + * setMaxLabelCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_clear_records + * clearRecords + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_count + * getBucketCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_record_count + * getRecordCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_index + * getBucketIndex(const UnicodeString &itemName, UErrorCode &status) + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_current_bucket_index + * getBucketIndex() + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_label_type + * getBucketLabelType + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_record_name + * getRecordName + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_reset_bucket_iter + * resetBucketIterator + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_reset_record_iter + * resetRecordIterator + * * */ diff --git a/src/include/mobile/utils_i18n_alpha_idx.h b/src/include/mobile/utils_i18n_alpha_idx.h new file mode 100644 index 0000000..5131a37 --- /dev/null +++ b/src/include/mobile/utils_i18n_alpha_idx.h @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2016 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_ALPHA_IDX_H__ +#define __UTILS_I18N_ALPHA_IDX_H__ + +#include + +/** + * @file utils_i18n_alpha_idx.h + * @version 0.1 + * @brief utils_i18n_alpha_idx + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE AlphabeticIndex + * @brief AlphabeticIndex supports the creation of a UI index appropriate for a given language. + * @section CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE_OVERVIEW Overview + * @details The module can generate a list of labels for use as a UI "index", + * that is, a list of clickable characters (or character sequences) + * that allow the user to see a segment (bucket) of a larger "target" list. + * That is, each label corresponds to a bucket in the target list, where + * everything in the bucket is greater than or equal to the character + * (according to the locale's collation). Strings can be added to the index; + * they will be in sorted order in the right bucket. + * The module also supports having buckets for strings before the first (underflow), + * after the last (overflow), and between scripts (inflow). For example, + * if the index is constructed with labels for Russian and English, + * Greek characters would fall into an inflow bucket between the other two scripts. + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * @{ + */ + +/** + * @brief Creates an alphabetic index object for the specified locale. + * @remarks The created object should be released by the caller with the + * #i18n_alpha_idx_destroy() function. + * + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * @param[out] index The created alphabetic index 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_alpha_idx_create(const char *language, const char *country, + i18_alpha_idx_h *index); + +/** + * @brief Destroys the alphabetic index object. + * + * @param[in] index The alphabetic index to be destroyed + * + * @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_alpha_idx_destroy(i18_alpha_idx_h index); + +/** + * @brief Adds the index characters from a specified locale to the index. + * + * @param[in] index Label will be added to this alphabetic index + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * + * @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_alpha_idx_add_labels(i18_alpha_idx_h index, const char *language, + const char *country); + +/** + * @brief Adds the record to the alphabetic index. + * + * @param[in] index Record will be added to this alphabetic index + * @param[in] name The display name for the record + * @param[in] data An optional pointer to user data associated with this item + * + * @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_alpha_idx_add_record(i18_alpha_idx_h index, const char *name, + const void *data); + +/** + * @brief Sets the next bucket as current bucket in the index. + * + * @param[in] index The alphabetic index, which contains buckets + * @param[out] success A flag set to @c true if the iteration succeeded, + * or @c false at the end of iteration. + * + * @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_alpha_idx_get_next_bucket(i18_alpha_idx_h index, bool *success); + +/** + * @brief Sets the next record as current record in current bucket of the index. + * @details When i18n_alpha_idx_next_bucket() is called, record iteration is reset + * to just before the first record in the new bucket. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] success A flag set to @c true if the iteration succeeded, + * or @c false at the end of iteration. + * + * @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_alpha_idx_get_next_record(i18_alpha_idx_h index, bool *success); + +/** + * @brief Gets the number of records in the current bucket. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] records_count Number of records in the current bucket + * + * @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_alpha_idx_get_bucket_record_count(i18_alpha_idx_h index, int32_t *records_count); + +/** + * @brief Gets the name of the label of the current bucket in alphabetic index. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets + * @param[out] label The name of the label of the current bucket + * + * @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_alpha_idx_get_bucket_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Gets the data pointer of the current record in current bucket in alphabetic index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] data The data pointer of the current record + * + * @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_INDEX_OUTOFBOUNDS Trying to access the index that is out of bounds + */ +int i18n_alpha_idx_get_record_data(i18_alpha_idx_h index, const void **data); + +/** + * @brief Gets the default label used for abbreviated buckets between other index characters. + * @details For example, consider the labels when Latin and Greek are used: X Y Z ... Α Β + * Γ. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] label The default label used for abbreviated bucket between other index characters + * + * @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_alpha_idx_get_inflow_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Sets the default label used for abbreviated buckets between other index characters. + * @details An inflow label will be automatically inserted if two otherwise-adjacent label characters + * are from different scripts, e.g. Latin and Cyrillic, and a third script, + * e.g. Greek, sorts between the two. The default inflow character is an ellipsis (...) + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] label The default label used for abbreviated bucket between other index characters + * + * @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_alpha_idx_set_inflow_label(i18_alpha_idx_h index, const char *label); + +/** + * @brief Gets the special label used for items that sort after the last normal label, + * and that would not otherwise have an appropriate label. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] label The special label used for items that sort after the last normal label + * + * @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_alpha_idx_get_overflow_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Sets the special label used for items that sort after the last normal label, + * and that would not otherwise have an appropriate label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] label The special label used for items that sort after the last normal label + * + * @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_alpha_idx_set_overflow_label(i18_alpha_idx_h index, const char *label); + +/** + * @brief Gets the special label used for items that sort before the first normal label, + * and that would not otherwise have an appropriate label. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] label The special label used for items that sort before the first normal label + * + * @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_alpha_idx_get_underflow_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Sets the special label used for items that sort before the first normal label, + * and that would not otherwise have an appropriate label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] label The special label used for items that sort before the first normal label + * + * @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_alpha_idx_set_underflow_label(i18_alpha_idx_h index, const char *label); + +/** + * @brief Gets the limit on the number of labels permitted in the index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] max_label_count The maximum number of labels + * + * @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_alpha_idx_get_max_label_count(i18_alpha_idx_h index, int32_t *max_label_count); + +/** + * @brief Gets the limit on the number of labels permitted in the index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] max_label_count The maximum number of labels + * + * @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_alpha_idx_set_max_label_count(i18_alpha_idx_h index, int32_t max_label_count); + +/** + * @brief Remove all records from the index. + * @details The set of Buckets, which define the headings under which records are classified, + * is not altered. + * + * @param[in] index The alphabetic index, which contains buckets with records + * + * @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_alpha_idx_clear_records(i18_alpha_idx_h index); + +/** + * @brief Gets the number of labels in this index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] bucket_count The number of labels in this index, including any under, + * over or inflow labels + * + * @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_alpha_idx_get_bucket_count(i18_alpha_idx_h index, int32_t *bucket_count); + +/** + * @brief Gets the total number of records in this index, that is, the number of + * pairs added. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] record_count The number of records in this index, that is, + * the total number of (name, data) items added with + * i18n_alpha_idx_add_record() + * + * @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_alpha_idx_get_record_count(i18_alpha_idx_h index, int32_t *record_count); + +/** + * @brief Given the name of a record, returns the zero-based index of the bucket + * in which the item should appear. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] item_name The name whose bucket position in the index is to be determined + * @param[out] bucket_index The bucket number for this 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_alpha_idx_get_bucket_index(i18_alpha_idx_h index, const char *item_name, int32_t *bucket_index); + +/** + * @brief Gets the zero based index of the current bucket of this index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] bucket_index The number of current bucket + * + * @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_alpha_idx_get_current_bucket_index(i18_alpha_idx_h index, int32_t *bucket_index); + +/** + * @brief Gets the type of the label for the current bucket. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] type The alphabetic index label type + * + * @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_alpha_idx_get_bucket_label_type(i18_alpha_idx_h index, + i18_alpha_idx_label_type_e *type); + +/** + * @brief Gets the name of the current record. + * @details Returns NULL if the Record iteration position is before first or after the last. + * @remarks The obtained @a record_name should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] record_name The name of the current index item + * + * @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_INDEX_OUTOFBOUNDS Trying to access the index that is out of bounds + */ +int i18n_alpha_idx_get_record_name(i18_alpha_idx_h index, char **record_name); + +/** + * @brief Resets the bucket iteration for this index. + * @details The next call to i18n_alpha_idx_next_bucket() will restart the iteration at the first label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * + * @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_alpha_idx_reset_bucket_iter(i18_alpha_idx_h index); + +/** + * @brief Resets the record iteration for this index. + * @details The next call to i18n_alpha_idx_next_record() will restart the iteration at the first label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * + * @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_alpha_idx_reset_record_iter(i18_alpha_idx_h index); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_ALPHA_IDX_H__ */ diff --git a/src/include/mobile/utils_i18n_types.h b/src/include/mobile/utils_i18n_types.h index 009d970..45784f9 100644 --- a/src/include/mobile/utils_i18n_types.h +++ b/src/include/mobile/utils_i18n_types.h @@ -2908,6 +2908,51 @@ typedef enum { I18N_ULOC_REQUESTED_LOCALE = 2, /**< This is the requested locale (deprecated) */ } i18n_uloc_data_locale_type_e; +/* + * @brief The Alphabetic index handle. + * @since_tizen 3.0 + */ +typedef void *i18_alpha_idx_h; + +/** + * @brief Enumeration for alphabetic index label types. + * @since_tizen 3.0 + * + * @see i18n_alpha_idx_get_bucket_label_type() + */ +typedef enum { + /** + * Normal Label, typically the starting letter of the names in the bucket with this label. + */ + I18_ALPHA_IDX_NORMAL, + + /** + * Underflow Label. + * + * The bucket with this label contains names in scripts that sort before any + * of the bucket labels in this index. + */ + I18_ALPHA_IDX_UNDERFLOW, + + /** + * Inflow Label. + * + * The bucket with this label contains names in scripts that sort between + * two of the bucket labels in this index. Inflow labels are created when + * an index contains normal labels for multiple scripts, and skips other + * scripts that sort between some of the included scripts. + */ + I18_ALPHA_IDX_INFLOW, + + /** + * Overflow Label. + * + * The bucket with this label contains names in scripts that sort after + * all of the bucket labels in this index. + */ + I18_ALPHA_IDX_OVERFLOW, +} i18_alpha_idx_label_type_e; + #ifdef __cplusplus } #endif diff --git a/src/include/wearable/utils_i18n.h b/src/include/wearable/utils_i18n.h index 3bdb929..13b23bc 100644 --- a/src/include/wearable/utils_i18n.h +++ b/src/include/wearable/utils_i18n.h @@ -32,6 +32,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -46,7 +47,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 and unumber. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber and alpha_idx. * 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. * @@ -123,6 +124,10 @@ extern "C" { * * * + * + * + * + * *
@ref CAPI_BASE_UTILS_I18N_UNUMBER_MODULEUnumber helps you format and parse numbers for any locale.
@ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULEAlpha_idx supports the creation of a UI index appropriate for a given language.
* * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -1778,6 +1783,136 @@ extern "C" { * #i18n_ustring_from_UTF32_with_sub * u_strFromUTF32WithSub * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_create + * AlphabeticIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_destroy + * ~AlphabeticIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_add_labels + * addLabels + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_add_record + * addRecord + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_next_bucket + * nextBucket + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_next_record + * nextRecord + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_record_count + * getBucketRecordCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_label + * getBucketLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_record_data + * getRecordData + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_inflow_label + * getInflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_inflow_label + * setInflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_overflow_label + * getOverflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_overflow_label + * setOverflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_underflow_label + * getUnderflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_underflow_label + * setUnderflowLabel + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_max_label_count + * getMaxLabelCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_set_max_label_count + * setMaxLabelCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_clear_records + * clearRecords + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_count + * getBucketCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_record_count + * getRecordCount + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_index + * getBucketIndex(const UnicodeString &itemName, UErrorCode &status) + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_current_bucket_index + * getBucketIndex() + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_bucket_label_type + * getBucketLabelType + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_get_record_name + * getRecordName + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_reset_bucket_iter + * resetBucketIterator + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_reset_record_iter + * resetRecordIterator + * * */ diff --git a/src/include/wearable/utils_i18n_alpha_idx.h b/src/include/wearable/utils_i18n_alpha_idx.h new file mode 100644 index 0000000..5131a37 --- /dev/null +++ b/src/include/wearable/utils_i18n_alpha_idx.h @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2016 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_ALPHA_IDX_H__ +#define __UTILS_I18N_ALPHA_IDX_H__ + +#include + +/** + * @file utils_i18n_alpha_idx.h + * @version 0.1 + * @brief utils_i18n_alpha_idx + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE AlphabeticIndex + * @brief AlphabeticIndex supports the creation of a UI index appropriate for a given language. + * @section CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE_OVERVIEW Overview + * @details The module can generate a list of labels for use as a UI "index", + * that is, a list of clickable characters (or character sequences) + * that allow the user to see a segment (bucket) of a larger "target" list. + * That is, each label corresponds to a bucket in the target list, where + * everything in the bucket is greater than or equal to the character + * (according to the locale's collation). Strings can be added to the index; + * they will be in sorted order in the right bucket. + * The module also supports having buckets for strings before the first (underflow), + * after the last (overflow), and between scripts (inflow). For example, + * if the index is constructed with labels for Russian and English, + * Greek characters would fall into an inflow bucket between the other two scripts. + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * @{ + */ + +/** + * @brief Creates an alphabetic index object for the specified locale. + * @remarks The created object should be released by the caller with the + * #i18n_alpha_idx_destroy() function. + * + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * @param[out] index The created alphabetic index 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_alpha_idx_create(const char *language, const char *country, + i18_alpha_idx_h *index); + +/** + * @brief Destroys the alphabetic index object. + * + * @param[in] index The alphabetic index to be destroyed + * + * @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_alpha_idx_destroy(i18_alpha_idx_h index); + +/** + * @brief Adds the index characters from a specified locale to the index. + * + * @param[in] index Label will be added to this alphabetic index + * @param[in] language The language of the locale + * @param[in] country The country of the locale + * + * @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_alpha_idx_add_labels(i18_alpha_idx_h index, const char *language, + const char *country); + +/** + * @brief Adds the record to the alphabetic index. + * + * @param[in] index Record will be added to this alphabetic index + * @param[in] name The display name for the record + * @param[in] data An optional pointer to user data associated with this item + * + * @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_alpha_idx_add_record(i18_alpha_idx_h index, const char *name, + const void *data); + +/** + * @brief Sets the next bucket as current bucket in the index. + * + * @param[in] index The alphabetic index, which contains buckets + * @param[out] success A flag set to @c true if the iteration succeeded, + * or @c false at the end of iteration. + * + * @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_alpha_idx_get_next_bucket(i18_alpha_idx_h index, bool *success); + +/** + * @brief Sets the next record as current record in current bucket of the index. + * @details When i18n_alpha_idx_next_bucket() is called, record iteration is reset + * to just before the first record in the new bucket. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] success A flag set to @c true if the iteration succeeded, + * or @c false at the end of iteration. + * + * @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_alpha_idx_get_next_record(i18_alpha_idx_h index, bool *success); + +/** + * @brief Gets the number of records in the current bucket. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] records_count Number of records in the current bucket + * + * @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_alpha_idx_get_bucket_record_count(i18_alpha_idx_h index, int32_t *records_count); + +/** + * @brief Gets the name of the label of the current bucket in alphabetic index. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets + * @param[out] label The name of the label of the current bucket + * + * @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_alpha_idx_get_bucket_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Gets the data pointer of the current record in current bucket in alphabetic index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] data The data pointer of the current record + * + * @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_INDEX_OUTOFBOUNDS Trying to access the index that is out of bounds + */ +int i18n_alpha_idx_get_record_data(i18_alpha_idx_h index, const void **data); + +/** + * @brief Gets the default label used for abbreviated buckets between other index characters. + * @details For example, consider the labels when Latin and Greek are used: X Y Z ... Α Β + * Γ. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] label The default label used for abbreviated bucket between other index characters + * + * @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_alpha_idx_get_inflow_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Sets the default label used for abbreviated buckets between other index characters. + * @details An inflow label will be automatically inserted if two otherwise-adjacent label characters + * are from different scripts, e.g. Latin and Cyrillic, and a third script, + * e.g. Greek, sorts between the two. The default inflow character is an ellipsis (...) + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] label The default label used for abbreviated bucket between other index characters + * + * @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_alpha_idx_set_inflow_label(i18_alpha_idx_h index, const char *label); + +/** + * @brief Gets the special label used for items that sort after the last normal label, + * and that would not otherwise have an appropriate label. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] label The special label used for items that sort after the last normal label + * + * @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_alpha_idx_get_overflow_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Sets the special label used for items that sort after the last normal label, + * and that would not otherwise have an appropriate label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] label The special label used for items that sort after the last normal label + * + * @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_alpha_idx_set_overflow_label(i18_alpha_idx_h index, const char *label); + +/** + * @brief Gets the special label used for items that sort before the first normal label, + * and that would not otherwise have an appropriate label. + * @remarks The obtained @a label should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] label The special label used for items that sort before the first normal label + * + * @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_alpha_idx_get_underflow_label(i18_alpha_idx_h index, char **label); + +/** + * @brief Sets the special label used for items that sort before the first normal label, + * and that would not otherwise have an appropriate label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] label The special label used for items that sort before the first normal label + * + * @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_alpha_idx_set_underflow_label(i18_alpha_idx_h index, const char *label); + +/** + * @brief Gets the limit on the number of labels permitted in the index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] max_label_count The maximum number of labels + * + * @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_alpha_idx_get_max_label_count(i18_alpha_idx_h index, int32_t *max_label_count); + +/** + * @brief Gets the limit on the number of labels permitted in the index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] max_label_count The maximum number of labels + * + * @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_alpha_idx_set_max_label_count(i18_alpha_idx_h index, int32_t max_label_count); + +/** + * @brief Remove all records from the index. + * @details The set of Buckets, which define the headings under which records are classified, + * is not altered. + * + * @param[in] index The alphabetic index, which contains buckets with records + * + * @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_alpha_idx_clear_records(i18_alpha_idx_h index); + +/** + * @brief Gets the number of labels in this index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] bucket_count The number of labels in this index, including any under, + * over or inflow labels + * + * @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_alpha_idx_get_bucket_count(i18_alpha_idx_h index, int32_t *bucket_count); + +/** + * @brief Gets the total number of records in this index, that is, the number of + * pairs added. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] record_count The number of records in this index, that is, + * the total number of (name, data) items added with + * i18n_alpha_idx_add_record() + * + * @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_alpha_idx_get_record_count(i18_alpha_idx_h index, int32_t *record_count); + +/** + * @brief Given the name of a record, returns the zero-based index of the bucket + * in which the item should appear. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[in] item_name The name whose bucket position in the index is to be determined + * @param[out] bucket_index The bucket number for this 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_alpha_idx_get_bucket_index(i18_alpha_idx_h index, const char *item_name, int32_t *bucket_index); + +/** + * @brief Gets the zero based index of the current bucket of this index. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] bucket_index The number of current bucket + * + * @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_alpha_idx_get_current_bucket_index(i18_alpha_idx_h index, int32_t *bucket_index); + +/** + * @brief Gets the type of the label for the current bucket. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] type The alphabetic index label type + * + * @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_alpha_idx_get_bucket_label_type(i18_alpha_idx_h index, + i18_alpha_idx_label_type_e *type); + +/** + * @brief Gets the name of the current record. + * @details Returns NULL if the Record iteration position is before first or after the last. + * @remarks The obtained @a record_name should be released by the caller with the free() function. + * + * @param[in] index The alphabetic index, which contains buckets with records + * @param[out] record_name The name of the current index item + * + * @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_INDEX_OUTOFBOUNDS Trying to access the index that is out of bounds + */ +int i18n_alpha_idx_get_record_name(i18_alpha_idx_h index, char **record_name); + +/** + * @brief Resets the bucket iteration for this index. + * @details The next call to i18n_alpha_idx_next_bucket() will restart the iteration at the first label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * + * @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_alpha_idx_reset_bucket_iter(i18_alpha_idx_h index); + +/** + * @brief Resets the record iteration for this index. + * @details The next call to i18n_alpha_idx_next_record() will restart the iteration at the first label. + * + * @param[in] index The alphabetic index, which contains buckets with records + * + * @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_alpha_idx_reset_record_iter(i18_alpha_idx_h index); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_ALPHA_IDX_H__ */ diff --git a/src/include/wearable/utils_i18n_types.h b/src/include/wearable/utils_i18n_types.h index ddb8139..5cf1aa1 100644 --- a/src/include/wearable/utils_i18n_types.h +++ b/src/include/wearable/utils_i18n_types.h @@ -2908,6 +2908,51 @@ typedef enum { I18N_ULOC_REQUESTED_LOCALE = 2, /**< This is the requested locale (deprecated) */ } i18n_uloc_data_locale_type_e; +/* + * @brief The Alphabetic index handle. + * @since_tizen 3.0 + */ +typedef void *i18_alpha_idx_h; + +/** + * @brief Enumeration for alphabetic index label types. + * @since_tizen 3.0 + * + * @see i18n_alpha_idx_get_bucket_label_type() + */ +typedef enum { + /** + * Normal Label, typically the starting letter of the names in the bucket with this label. + */ + I18_ALPHA_IDX_NORMAL, + + /** + * Underflow Label. + * + * The bucket with this label contains names in scripts that sort before any + * of the bucket labels in this index. + */ + I18_ALPHA_IDX_UNDERFLOW, + + /** + * Inflow Label. + * + * The bucket with this label contains names in scripts that sort between + * two of the bucket labels in this index. Inflow labels are created when + * an index contains normal labels for multiple scripts, and skips other + * scripts that sort between some of the included scripts. + */ + I18_ALPHA_IDX_INFLOW, + + /** + * Overflow Label. + * + * The bucket with this label contains names in scripts that sort after + * all of the bucket labels in this index. + */ + I18_ALPHA_IDX_OVERFLOW, +} i18_alpha_idx_label_type_e; + #ifdef __cplusplus } #endif diff --git a/src/utils_i18n_alpha_idx.cpp b/src/utils_i18n_alpha_idx.cpp new file mode 100644 index 0000000..e0e8831 --- /dev/null +++ b/src/utils_i18n_alpha_idx.cpp @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2016 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 +#include +#include + +int i18n_alpha_idx_create(const char *language, const char *country, + i18_alpha_idx_h *index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + Locale locale(language, country, 0, 0); + UErrorCode status = U_ZERO_ERROR; + + *index = new AlphabeticIndex(locale, status); + retv_if(*index == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_destroy(i18_alpha_idx_h index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + delete ((AlphabeticIndex *) index); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_add_labels(i18_alpha_idx_h index, + const char *language, const char *country) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + Locale locale(language, country, 0, 0); + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->addLabels(locale, status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_add_record(i18_alpha_idx_h index, const char *name, + const void *data) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString _name(name); + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->addRecord(_name, data, status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_next_bucket(i18_alpha_idx_h index, bool *success) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + if(success != NULL) + *success = ((AlphabeticIndex *) index)->nextBucket(status); + else + ((AlphabeticIndex *) index)->nextBucket(status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_next_record(i18_alpha_idx_h index, bool *success) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + if(success != NULL) + *success = ((AlphabeticIndex *) index)->nextRecord(status); + else + ((AlphabeticIndex *) index)->nextRecord(status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_bucket_record_count(i18_alpha_idx_h index, + int32_t *records_count) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(records_count == NULL, I18N_ERROR_INVALID_PARAMETER); + + *records_count = ((AlphabeticIndex *) index)->getBucketRecordCount(); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_get_bucket_label(i18_alpha_idx_h index, + char **label) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(label == NULL, I18N_ERROR_INVALID_PARAMETER); + + UnicodeString _label = ((AlphabeticIndex *) index)->getBucketLabel(); + + std::string _label_string; + _label.toUTF8String(_label_string); + + *label = strdup(_label_string.c_str()); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_get_record_data(i18_alpha_idx_h index, + const void **data) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(data == NULL, I18N_ERROR_INVALID_PARAMETER); + + *data = ((AlphabeticIndex *) index)->getRecordData(); + retv_if(*data == NULL, I18N_ERROR_INDEX_OUTOFBOUNDS); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_get_inflow_label(i18_alpha_idx_h index, + char **label) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(label == NULL, I18N_ERROR_INVALID_PARAMETER); + + UnicodeString _label = ((AlphabeticIndex *) index)->getInflowLabel(); + + std::string _label_string; + _label.toUTF8String(_label_string); + + *label = strdup(_label_string.c_str()); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_set_inflow_label(i18_alpha_idx_h index, + const char *label) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(label == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString inflow_label(label); + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->setInflowLabel(inflow_label, status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_overflow_label(i18_alpha_idx_h index, + char **label) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(label == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString overflow_label = ((AlphabeticIndex *) index)->getOverflowLabel(); + + std::string _label_string; + overflow_label.toUTF8String(_label_string); + + *label = strdup(_label_string.c_str()); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_set_overflow_label(i18_alpha_idx_h index, + const char *label) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(label == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString overflow_label(label); + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->setOverflowLabel(overflow_label, status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_underflow_label(i18_alpha_idx_h index, + char **label) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(label == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString overflow_label = ((AlphabeticIndex *) index)->getOverflowLabel(); + + std::string _label_string; + overflow_label.toUTF8String(_label_string); + + *label = strdup(_label_string.c_str()); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_set_underflow_label(i18_alpha_idx_h index, + const char *label) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(label == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString underflow_label(label); + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->setOverflowLabel(underflow_label, status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_max_label_count(i18_alpha_idx_h index, + int32_t *max_label_count) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(max_label_count == NULL, I18N_ERROR_INVALID_PARAMETER); + + *max_label_count = ((AlphabeticIndex *) index)->getMaxLabelCount(); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_set_max_label_count(i18_alpha_idx_h index, + int32_t max_label_count) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->setMaxLabelCount(max_label_count, status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_clear_records(i18_alpha_idx_h index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->clearRecords(status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_bucket_count(i18_alpha_idx_h index, + int32_t *bucket_count) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(bucket_count == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + *bucket_count = ((AlphabeticIndex *) index)->getBucketCount(status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_record_count(i18_alpha_idx_h index, + int32_t *record_count) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(record_count == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + *record_count = ((AlphabeticIndex *) index)->getRecordCount(status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_bucket_index(i18_alpha_idx_h index, + const char *item_name, + int32_t *bucket_index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(item_name == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(bucket_index == NULL, I18N_ERROR_INVALID_PARAMETER); + + UnicodeString _item_name(item_name); + UErrorCode status = U_ZERO_ERROR; + + *bucket_index = ((AlphabeticIndex *) index)->getBucketIndex(_item_name, status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_get_current_bucket_index(i18_alpha_idx_h index, + int32_t *bucket_index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(bucket_index == NULL, I18N_ERROR_INVALID_PARAMETER); + + *bucket_index = ((AlphabeticIndex *) index)->getBucketIndex(); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_get_bucket_label_type(i18_alpha_idx_h index, + i18_alpha_idx_label_type_e *type) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(type == NULL, I18N_ERROR_INVALID_PARAMETER); + + *type = (i18_alpha_idx_label_type_e) ((AlphabeticIndex *) index)->getBucketLabelType(); + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_get_record_name(i18_alpha_idx_h index, + char **record_name) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(record_name == NULL, I18N_ERROR_INVALID_PARAMETER); + + const UnicodeString _record_name = ((AlphabeticIndex *) index)->getRecordName(); + + std::string _record_name_string; + _record_name.toUTF8String(_record_name_string); + + *record_name = strdup(_record_name_string.c_str()); + + if(_record_name.isEmpty()) { + return I18N_ERROR_INDEX_OUTOFBOUNDS; + } + + return I18N_ERROR_NONE; +} + +int i18n_alpha_idx_reset_bucket_iter(i18_alpha_idx_h index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->resetBucketIterator(status); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_reset_record_iter(i18_alpha_idx_h index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + ((AlphabeticIndex *) index)->resetRecordIterator(); + + return I18N_ERROR_NONE; +}