int i18n_measure_unit_get_subtype(i18n_measure_unit_h measure_unit, char **subtype);
/**
- * @brief Gets all of the available units.
- * @details If there are too many units to fit into @a dest_capacity the returned error code
- * is #I18N_ERROR_BUFFER_OVERFLOW.
+ * @brief Gets the available units.
+ * @details The function creates the array with the results.
+ * If there are more units available than the given @a max_count
+ * then the returned array is truncated to the first @a max_count units
+ * and the returned error code is #I18N_ERROR_BUFFER_OVERFLOW.
+ *
* @since_tizen 3.0
* @remarks The obtained array of measure unit objects should be released by the caller
* with the #i18n_measure_unit_array_destroy() function.
*
- * @param[in] dest_capacity The capacity of the given @a dest_array
- * @param[out] dest_array The destination buffer
- * @param[out] available The number of available units
+ * @param[in] max_count The maximal number of units that will be obtained
+ * @param[out] out_array The output array
+ * @param[out] available The actual number of available units
*
* @return @c 0 on success, otherwise a negative error value
* @retval #I18N_ERROR_NONE Successful
* @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
* @retval #I18N_ERROR_BUFFER_OVERFLOW Buffer overflow
*/
-int i18n_measure_unit_get_available(int32_t dest_capacity, i18n_measure_unit_h **dest_array, int32_t *available);
+int i18n_measure_unit_get_available(int32_t max_count, i18n_measure_unit_h **out_array, int32_t *available);
/**
- * @brief Gets all of the available units for a specific type.
- * @details If there are too many units to fit into dest_capacity then the error code
- * is set to #I18N_ERROR_BUFFER_OVERFLOW.
+ * @brief Gets the available units for a specific type.
+ * @details The function creates the array with the results.
+ * If there are more units available than the given @a max_count
+ * then the returned array is truncated to the first @a max_count units
+ * and the returned error code is #I18N_ERROR_BUFFER_OVERFLOW.
+ *
* @since_tizen 3.0
* @remarks The obtained array of measure unit objects should be released by the caller
* with the #i18n_measure_unit_array_destroy() function.
*
- * @param[in] dest_capacity The capacity of the given @a dest_array
- * @param[in] type The type of the obtained units
- * @param[out] dest_array The destination buffer
- * @param[out] available The number of available units
+ * @param[in] max_count The maximal number of units that will be obtained
+ * @param[in] type The type of the obtained units
+ * @param[out] out_array The output array
+ * @param[out] available The actual number of available units
*
* @return @c 0 on success, otherwise a negative error value
* @retval #I18N_ERROR_NONE Successful
* @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
* @retval #I18N_ERROR_BUFFER_OVERFLOW Buffer overflow
*/
-int i18n_measure_unit_get_available_with_type(int32_t dest_capacity, const char *type, i18n_measure_unit_h **dest_array, int32_t *available);
+int i18n_measure_unit_get_available_with_type(int32_t max_count, const char *type,
+ i18n_measure_unit_h **out_array, int32_t *available);
/**
* @brief Invokes the given callback function for every available measure unit type.
* @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
* @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
*/
-int i18n_measure_unit_get_subtype(i18n_measure_unit_h measure_unit, char **subtype);
+int i18n_measure_unit_get_subtype(i18n_measur_unit_h measure_unit, char **subtype);
/**
- * @brief Gets all of the available units.
- * @details If there are too many units to fit into @a dest_capacity the returned error code
- * is #I18N_ERROR_BUFFER_OVERFLOW.
+ * @brief Gets the available units.
+ * @details The function creates the array with the results.
+ * If there are more units available than the given @a max_count
+ * then the returned list is truncated to the first @a max_count units
+ * and the returned error code is #I18N_ERROR_BUFFER_OVERFLOW.
+ *
* @since_tizen 2.3.2
* @remarks The obtained array of measure unit objects should be released by the caller
* with the #i18n_measure_unit_array_destroy() function.
*
- * @param[in] dest_capacity The capacity of the given @a dest_array
- * @param[out] dest_array The destination buffer
- * @param[out] available The number of available units
+ * @param[in] max_count The maximal number of units that will be obtained
+ * @param[out] out_array The output array
+ * @param[out] available The actual number of available units
*
* @return @c 0 on success, otherwise a negative error value
* @retval #I18N_ERROR_NONE Successful
* @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
* @retval #I18N_ERROR_BUFFER_OVERFLOW Buffer overflow
*/
-int i18n_measure_unit_get_available(int32_t dest_capacity, i18n_measure_unit_h **dest_array, int32_t *available);
+int i18n_measure_unit_get_available(int32_t max_count, i18n_measure_unit_h **out_array, int32_t *available);
/**
- * @brief Gets all of the available units for a specific type.
- * @details If there are too many units to fit into dest_capacity then the error code
- * is set to #I18N_ERROR_BUFFER_OVERFLOW.
+ * @brief Gets the available units for a specific type.
+ * @details The function creates the array with the results.
+ * If there are more units available than the given @a max_count
+ * then the returned list is truncated to the first @a max_count units
+ * and the returned error code is #I18N_ERROR_BUFFER_OVERFLOW.
+ *
* @since_tizen 2.3.2
* @remarks The obtained array of measure unit objects should be released by the caller
* with the #i18n_measure_unit_array_destroy() function.
*
- * @param[in] dest_capacity The capacity of the given @a dest_array
- * @param[in] type The type of the obtained units
- * @param[out] dest_array The destination buffer
- * @param[out] available The number of available units
+ * @param[in] max_count The maximal number of units that will be obtained
+ * @param[in] type The type of the obtained units
+ * @param[out] out_array The output array
+ * @param[out] available The actual number of available units
*
* @return @c 0 on success, otherwise a negative error value
* @retval #I18N_ERROR_NONE Successful
* @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory
* @retval #I18N_ERROR_BUFFER_OVERFLOW Buffer overflow
*/
-int i18n_measure_unit_get_available_with_type(int32_t dest_capacity, const char *type, i18n_measure_unit_h **dest_array, int32_t *available);
+int i18n_measure_unit_get_available_with_type(int32_t max_count, const char *type,
+ i18n_measure_unit_h **out_array, int32_t *available);
/**
* @brief Invokes the given callback function for every available measure unit type.
return I18N_ERROR_NONE;
}
-int i18n_measure_unit_get_available(int32_t dest_capacity, i18n_measure_unit_h **dest_array, int32_t *available)
+int i18n_measure_unit_get_available(int32_t max_count, i18n_measure_unit_h **out_array, int32_t *available)
{
retv_if(available == NULL, I18N_ERROR_INVALID_PARAMETER);
- retv_if(dest_array == NULL, I18N_ERROR_INVALID_PARAMETER);
- retv_if(dest_capacity < 0, I18N_ERROR_INVALID_PARAMETER);
+ retv_if(out_array == NULL, I18N_ERROR_INVALID_PARAMETER);
+ retv_if(max_count < 0, I18N_ERROR_INVALID_PARAMETER);
- MeasureUnit *mu_array = new MeasureUnit[dest_capacity];
UErrorCode status = U_ZERO_ERROR;
- *available = MeasureUnit::getAvailable(mu_array, dest_capacity, status);
+ // Get the number of available units.
+ *available = MeasureUnit::getAvailable(NULL, 0, status);
+ retv_if(*available < 0, _i18n_error_mapping(status));
- *dest_array = new i18n_measure_unit_h[dest_capacity];
- for (int i = 0; i < dest_capacity; ++i) {
- (*dest_array)[i] = (const i18n_measure_unit_h) mu_array[i].clone();
+ // Get the available units.
+ MeasureUnit *mu_array = new MeasureUnit[*available];
+ status = U_ZERO_ERROR;
+
+ MeasureUnit::getAvailable(mu_array, *available, status);
+
+ // If the maximal count given by the user is lower then the available
+ // number of units, return only the first max_count units.
+ // Otherwise return all of the available units.
+ int32_t count = max_count < *available ? max_count : *available;
+
+ *out_array = new i18n_measure_unit_h[count];
+ for (int i = 0; i < count; ++i) {
+ (*out_array)[i] = (i18n_measure_unit_h) mu_array[i].clone();
}
delete[] mu_array;
- return _i18n_error_mapping(status);
+ return max_count < *available ? I18N_ERROR_BUFFER_OVERFLOW : _i18n_error_mapping(status);
}
-int i18n_measure_unit_get_available_with_type(int32_t dest_capacity, const char *type, i18n_measure_unit_h **dest_array, int32_t *available)
+int i18n_measure_unit_get_available_with_type(int32_t max_count, const char *type,
+ i18n_measure_unit_h **out_array, int32_t *available)
{
retv_if(available == NULL, I18N_ERROR_INVALID_PARAMETER);
retv_if(type == NULL, I18N_ERROR_INVALID_PARAMETER);
- retv_if(dest_array == NULL, I18N_ERROR_INVALID_PARAMETER);
- retv_if(dest_capacity < 0, I18N_ERROR_INVALID_PARAMETER);
+ retv_if(out_array == NULL, I18N_ERROR_INVALID_PARAMETER);
+ retv_if(max_count < 0, I18N_ERROR_INVALID_PARAMETER);
- MeasureUnit *mu_array = new MeasureUnit[dest_capacity];
UErrorCode status = U_ZERO_ERROR;
- *available = MeasureUnit::getAvailable(type, mu_array, dest_capacity, status);
+ // Get the number of available units for the given type.
+ *available = MeasureUnit::getAvailable(type, NULL, 0, status);
+ retv_if(*available < 0, _i18n_error_mapping(status));
- *dest_array = new i18n_measure_unit_h[dest_capacity];
- for (int i = 0; i < dest_capacity; ++i) {
- (*dest_array)[i] = (i18n_measure_unit_h) mu_array[i].clone();
+ // Get the available units for the given type.
+ MeasureUnit *mu_array = new MeasureUnit[*available];
+ status = U_ZERO_ERROR;
+
+ MeasureUnit::getAvailable(type, mu_array, *available, status);
+
+ // If the maximal count given by the user is lower then the available
+ // number of units, return only the first max_count units.
+ // Otherwise return all of the available units for the given type.
+ int32_t count = max_count < *available ? max_count : *available;
+
+ *out_array = new i18n_measure_unit_h[count];
+ for (int i = 0; i < count; ++i) {
+ (*out_array)[i] = (i18n_measure_unit_h) mu_array[i].clone();
}
delete[] mu_array;
- return _i18n_error_mapping(status);
+ return max_count < *available ? I18N_ERROR_BUFFER_OVERFLOW : _i18n_error_mapping(status);
}
int i18n_measure_unit_foreach_available_type(i18n_measure_unit_types_cb cb, void *user_data)