2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __UTILS_I18N_UNUMBER_H__
18 #define __UTILS_I18N_UNUMBER_H__
20 #include <utils_i18n_types.h>
23 * @file utils_i18n_unumber.h
25 * @brief utils_i18n_unumber
29 * @ingroup CAPI_BASE_UTILS_I18N_MODULE
30 * @defgroup CAPI_BASE_UTILS_I18N_UNUMBER_MODULE Unumber
31 * @brief The Unumber module helps you format and parse numbers for any locale.
33 * @section CAPI_BASE_UTILS_I18N_UNUMBER_MODULE_HEADER Required Header
34 * \#include <utils_i18n.h>
36 * @section CAPI_BASE_UTILS_I18N_UNUMBER_MODULE_OVERVIEW Overview
37 * @details The Unumber module helps you format and parse numbers for any locale.
38 * Your code can be completely independent of the locale conventions for decimal
39 * points, thousands-separators, or even the particular decimal digits used,
40 * or whether the number format is even decimal. There are different number format
41 * styles like decimal, currency, percent and spellout.
43 * @section CAPI_BASE_UTILS_I18N_UNUMBER_MODULE_SAMPLE_CODE_1 Sample Code 1
44 * @brief Gets a currency symbol according to a given locale.
47 i18n_uchar u_buffer[64];
49 i18n_unumber_format_h num_format;
51 // creates and returns a new unumber_format
52 i18n_unumber_create(I18N_UNUMBER_CURRENCY, NULL, -1, "en_US", NULL, &num_format);
54 // gets a symbol associated with i18n_unumber_format
55 i18n_unumber_get_symbol(num_format, I18N_UNUMBER_CURRENCY_SYMBOL, u_buffer, 64, &buf_len);
57 i18n_ustring_copy_au(a_buffer, u_buffer);
58 // en_US currency symbol: $
59 dlog_print(DLOG_INFO, LOG_TAG, "en_US currency symbol: %s \n", a_buffer);
61 // destroys i18n_unumber_format
62 i18n_unumber_destroy(num_format);
67 * @addtogroup CAPI_BASE_UTILS_I18N_UNUMBER_MODULE
76 * @brief Creates and returns a new unumber_format_h for formatting and parsing numbers.
77 * @details A unumber_format_style_e may be used to format numbers by calling {@link i18n_unumber_create()}.
78 * The caller must call {@link #i18n_unumber_destroy() } when done to release resources used by this object.
79 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
80 * @remarks Must release @a num_format using i18n_unumber_destroy().
82 * @param[in] style The type of number format to create: one of
83 * #I18N_UNUMBER_DECIMAL,
84 * #I18N_UNUMBER_CURRENCY,
85 * #I18N_UNUMBER_PERCENT,
86 * #I18N_UNUMBER_SCIENTIFIC,
87 * #I18N_UNUMBER_SPELLOUT,
88 * #I18N_UNUMBER_ORDINAL,
89 * #I18N_UNUMBER_DURATION,
90 * #I18N_UNUMBER_NUMBERING_SYSTEM,
91 * #I18N_UNUMBER_PATTERN_RULEBASED,
92 * or #I18N_UNUMBER_DEFAULT \n
93 * If #I18N_UNUMBER_PATTERN_DECIMAL or #I18N_UNUMBER_PATTERN_RULEBASED is passed then the number format is created using the given pattern, which must conform
94 * to the syntax described in DecimalFormat or RuleBasedNumberFormat, respectively.
95 * @param[in] pattern A pattern specifying the format to use \n This parameter is ignored unless the style is #I18N_UNUMBER_PATTERN_DECIMAL or #I18N_UNUMBER_PATTERN_RULEBASED.
96 * @param[in] pattern_len The number of characters in the pattern, otherwise @c -1 if NULL-terminated\n
97 * This parameter is ignored unless the style is I18N_UNUMBER_PATTERN_*.
98 * @param[in] locale A locale identifier to use to determine formatting
99 * and parsing conventions, otherwise @c NULL to use the default locale.
100 * @param[in] parse_err A pointer to a #i18n_uparse_error_s structure to receive the
101 * details of any parsing errors, otherwise @c NULL if no parsing error details are desired.
102 * @param[out] num_format A pointer to a newly created #i18n_unumber_format_h, otherwise @c NULL if an error occurs.
104 * @retval #I18N_ERROR_NONE Successful
105 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
107 int i18n_unumber_create ( i18n_unumber_format_style_e style, const i18n_uchar *pattern, int32_t pattern_len, const char *locale,
108 i18n_uparse_error_s *parse_err, i18n_unumber_format_h *num_format );
111 * @brief Destroys an #i18n_unumber_format_h.
112 * @details Once destroyed, an #i18n_unumber_format may no longer be used.
113 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
115 * @param[in] fmt The formatter to destroy
117 * @retval #I18N_ERROR_NONE Successful
118 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
120 int i18n_unumber_destroy ( i18n_unumber_format_h fmt );
123 * @brief Gets a symbol associated with an #i18n_unumber_format_h.
124 * @details An #i18n_unumber_format_h uses symbols to represent the special locale-dependent characters in a number,
125 * for example the percent sign. This API is not supported for rule-based formatters.
126 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
128 * @param[in] fmt The formatter to query.
129 * @param[in] symbol The unumber_format_symbol_e constant for the symbol to get
130 * @param[out] buffer The string buffer that will receive the symbol string\n
131 * If it is @c NULL, then only the length of the symbol is returned.
132 * @param[in] size The size of the string buffer
133 * @param[out] len_symbol The length of the symbol\n
134 * The buffer is not modified if <code>length >= size</code>
136 * @retval #I18N_ERROR_NONE Successful.
137 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
139 int i18n_unumber_get_symbol ( const i18n_unumber_format_h fmt, i18n_unumber_format_symbol_e symbol, i18n_uchar *buffer, int32_t size, int32_t *len_symbol );
146 * @brief Creates a copy of an #i18n_unumber_format_h.
147 * @details This function performs a deep copy.
148 * @remarks Error codes are described in #i18n_error_code_e description.
151 * @param[in] fmt The format to copy.
152 * @param[out] fmt_clone A pointer to clone of @a fmt.
153 * @return The obtained error code.
154 * @retval #I18N_ERROR_NONE Successful.
155 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
157 int i18n_unumber_clone (const i18n_unumber_format_h fmt, i18n_unumber_format_h *fmt_clone);
160 * @brief Formats an integer using a i18n_unumber_format_h.
161 * @details The integer will be formatted according to the i18n_unumber_format_h's locale.
164 * @param[in] fmt The formatter to use.
165 * @param[in] number The number to format.
166 * @param[out] result A pointer to a buffer to receive the NULL-terminated formatted number.
167 * If the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
168 * then the error code is set to #I18N_WARNING_STRING_NOT_TERMINATED.
169 * If the formatted number doesn't fit into result then the error code is set to #I18N_ERROR_BUFFER_OVERFLOW.
170 * @param[in] result_length The maximum size of result.
171 * @param[in] pos A pointer to a i18n_ufield_position. On input, position->field is read.
172 * On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists.
173 * This parameter may be NULL, in which case no field
174 * @param[out] status A pointer to an i18n_error_code_e to receive any errors
176 * @return The total buffer size needed; if greater than result_length, the output was truncated.
178 int32_t i18n_unumber_format (const i18n_unumber_format_h fmt, int32_t number, i18n_uchar *result, int32_t result_length, i18n_ufield_position_s *pos, i18n_error_code_e *status);
181 * @brief Formats an int64 using an #i18n_unumber_format_h.
182 * @details The int64 will be formatted according to the #i18n_unumber_format_h's locale.
183 * @remarks The specific error code can be obtained using the get_last_result() method.
184 * Error codes are described in Exceptions section and #i18n_error_code_e description.
187 * @param[in] fmt The formatter to use.
188 * @param[in] number The number to format.
189 * @param[out] result A pointer to a buffer to receive the NULL-terminated formatted number.
190 * If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>)
191 * then the error code is set to #I18N_WARNING_STRING_NOT_TERMINATED.
192 * If the formatted number doesn't fit into result then the error code is set to #I18N_ERROR_BUFFER_OVERFLOW.
193 * @param[in] result_length The maximum size of @a result.
194 * @param[in,out] pos An #i18n_ufield_position_h handle. On input, position->field is read.
195 * On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists.
196 * This parameter may be NULL, in which case no field
198 * @return The total buffer size needed; if greater than @a result_length, the output was truncated.
200 * @exception #I18N_ERROR_NONE Successful
201 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
202 * @exception #I18N_WARNING_STRING_NOT_TERMINATED If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>)
203 * @exception #I18N_ERROR_BUFFER_OVERFLOW If the formatted number doesn't fit into the @a result buffer
205 int32_t i18n_unumber_format_int64 (const i18n_unumber_format_h fmt, int64_t number, i18n_uchar *result, int32_t result_length, i18n_ufield_position_h pos);
208 * @brief Formats a double using an #i18n_unumber_format_h.
209 * @details The double will be formatted according to the #i18n_unumber_format_h's locale.
210 * @remarks The specific error code can be obtained using the get_last_result() method.
211 * Error codes are described in Exceptions section and #i18n_error_code_e description.
214 * @param[in] fmt The formatter to use.
215 * @param[in] number The number to format.
216 * @param[out] result A pointer to a buffer to receive the NULL-terminated formatted number.
217 * If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>)
218 * then the error code is set to #I18N_WARNING_STRING_NOT_TERMINATED.
219 * If the formatted number doesn't fit into result then the error code is set to #I18N_ERROR_BUFFER_OVERFLOW.
220 * @param[in] result_length The maximum size of @a result.
221 * @param[in,out] pos An #i18n_ufield_position_h handle. On input, position->field is read.
222 * On output, position->beginIndex and position->endIndex indicate the beginning
223 * and ending indices of field number position->field, if such a field exists.
224 * This parameter may be NULL, in which case no field
226 * @return The total buffer size needed; if greater than @a result_length, the output was truncated.
228 * @exception #I18N_ERROR_NONE Successful
229 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
230 * @exception #I18N_WARNING_STRING_NOT_TERMINATED If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>)
231 * @exception #I18N_ERROR_BUFFER_OVERFLOW If the formatted number doesn't fit into the @a result buffer
233 int32_t i18n_unumber_format_double (const i18n_unumber_format_h fmt, double number, i18n_uchar *result, int32_t result_length, i18n_ufield_position_h pos);
236 * @brief Formats a decimal number using an #i18n_unumber_format_h.
237 * @details The number will be formatted according to the #i18n_unumber_format_h's locale. The syntax of the input number
238 * is a "numeric string" as defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal
239 * @remarks The specific error code can be obtained using the get_last_result() method.
240 * Error codes are described in Exceptions section and #i18n_error_code_e description.
243 * @param[in] fmt The formatter to use.
244 * @param[in] number The number to format.
245 * @param[in] length The length of the input @a number, or -1 if the input is NULL-terminated.
246 * @param[out] result A pointer to a buffer to receive the NULL-terminated formatted number.
247 * If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>) then
248 * the error code is set to #I18N_WARNING_STRING_NOT_TERMINATED.
249 * If the formatted number doesn't fit into result then the error code is set to
250 * #I18N_ERROR_BUFFER_OVERFLOW.
251 * @param[in] result_length The maximum size of @a result.
252 * @param[in,out] pos An #i18n_ufield_position_h handle. On input, position->field is read.
253 * On output, position->beginIndex and position->endIndex indicate the beginning and ending
254 * indices of field number position->field, if such a field exists.
255 * This parameter may be NULL, in which case it is ignored.
257 * @return The total buffer size needed; if greater than @a result_length, the output was truncated.
259 * @exception #I18N_ERROR_NONE Successful
260 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
261 * @exception #I18N_WARNING_STRING_NOT_TERMINATED If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>)
262 * @exception #I18N_ERROR_BUFFER_OVERFLOW If the formatted number doesn't fit into the @a result buffer
264 int32_t i18n_unumber_format_decimal (const i18n_unumber_format_h fmt, const char *number, int32_t length, i18n_uchar *result, int32_t result_length, i18n_ufield_position_h pos);
267 * @brief Formats a double currency amount using an #i18n_unumber_format_h.
268 * @details The double will be formatted according to the #i18n_unumber_format_h's locale.
269 * @remarks The specific error code can be obtained using the get_last_result() method.
270 * Error codes are described in Exceptions section and #i18n_error_code_e description.
273 * @param[in] fmt The formatter to use.
274 * @param[in] number The number to format.
275 * @param[in] currency The 3-letter NULL-terminated ISO 4217 currency code.
276 * @param[out] result A pointer to a buffer to receive the NULL-terminated formatted number.
277 * If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>)
278 * then the error code is set to #I18N_WARNING_STRING_NOT_TERMINATED.
279 * If the formatted number doesn't fit into result then the error code is set to
280 * #I18N_ERROR_BUFFER_OVERFLOW.
281 * @param[in] result_length The maximum size of @a result.
282 * @param[in,out] pos An #i18n_ufield_position_h handle. On input, position->field is read.
283 * On output, position->beginIndex and position->endIndex indicate the beginning and ending indices
284 * of field number position->field, if such a field exists.
285 * This parameter may be NULL, in which case it is ignored.
287 * @return The total buffer size needed; if greater than @a result_length, the output was truncated.
289 * @exception #I18N_ERROR_NONE Successful
290 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
291 * @exception #I18N_WARNING_STRING_NOT_TERMINATED If the formatted number fits into @a result but cannot be NULL-terminated (<code>length == result_length</code>)
292 * @exception #I18N_ERROR_BUFFER_OVERFLOW If the formatted number doesn't fit into the @a result buffer
294 int32_t i18n_unumber_format_double_currency (const i18n_unumber_format_h fmt, double number, i18n_uchar *currency, i18n_uchar *result, int32_t result_length, i18n_ufield_position_h pos);
297 * @brief Parses a string into an integer using an #i18n_unumber_format_h.
298 * @details The string will be parsed according to the #i18n_unumber_format_h's locale.
299 * @remarks The specific error code can be obtained using the get_last_result() method.
300 * Error codes are described in Exceptions section and #i18n_error_code_e description.
303 * @param[in] fmt The formatter to use.
304 * @param[in] text The text to parse.
305 * @param[in] text_length The length of @a text, or -1 if NULL-terminated.
306 * @param[in,out] parse_pos If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing.
307 * If not NULL, on output the offset at which parsing ended.
309 * @return The value of the parsed integer
311 * @exception #I18N_ERROR_NONE Successful
312 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
314 int32_t i18n_unumber_parse (const i18n_unumber_format_h fmt, const i18n_uchar *text, int32_t text_length, int32_t *parse_pos);
317 * @brief Parses a string into an int64 using an #i18n_unumber_format_h.
318 * @details The string will be parsed according to the #i18n_unumber_format_h's locale.
319 * @remarks The specific error code can be obtained using the get_last_result() method.
320 * Error codes are described in Exceptions section and #i18n_error_code_e description.
323 * @param[in] fmt The formatter to use.
324 * @param[in] text The text to parse.
325 * @param[in] text_length The length of @a text, or -1 if NULL-terminated.
326 * @param[in,out] parse_pos If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing.
327 * If not NULL, on output the offset at which parsing ended.
329 * @return The value of the parsed integer
331 * @exception #I18N_ERROR_NONE Successful
332 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
334 int64_t i18n_unumber_parse_int64 (const i18n_unumber_format_h fmt, const i18n_uchar *text, int32_t text_length, int32_t *parse_pos);
337 * @brief Parses a string into a double using an #i18n_unumber_format_h.
338 * @details The string will be parsed according to the #i18n_unumber_format_h's locale.
339 * @remarks The specific error code can be obtained using the get_last_result() method.
340 * Error codes are described in Exceptions section and #i18n_error_code_e description.
343 * @param[in] fmt The formatter to use.
344 * @param[in] text The text to parse.
345 * @param[out] text_length The length of @a text, or -1 if NULL-terminated.
346 * @param[in,out] parse_pos If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing.
347 * If not NULL, on output the offset at which parsing ended.
349 * @return The value of the parsed double
351 * @exception #I18N_ERROR_NONE Successful
352 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
354 double i18n_unumber_parse_double (const i18n_unumber_format_h fmt, const i18n_uchar *text, int32_t text_length, int32_t *parse_pos);
357 * @brief Parses a number from a string into an unformatted numeric string using an #i18n_unumber_format_h.
358 * @details The input string will be parsed according to the #i18n_unumber_format_h's locale.
359 * The syntax of the output is a "numeric string" as defined in the Decimal Arithmetic Specification, available at
360 * http://speleotrove.com/decimal
361 * @remarks The specific error code can be obtained using the get_last_result() method.
362 * Error codes are described in Exceptions section and #i18n_error_code_e description.
365 * @param[in] fmt The formatter to use.
366 * @param[in] text The text to parse.
367 * @param[in] text_length The length of @a text, or -1 if NULL-terminated.
368 * @param[in,out] parse_pos If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing.
369 * If not NULL, on output the offset at which parsing ended.
370 * @param[out] out_buf A (char *) buffer to receive the parsed number as a string.
371 * The output string will be NULL-terminated if there is sufficient space.
372 * @param[out] out_buf_length The size of the output buffer. May be zero, in which case the @a out_buf pointer may be NULL,
373 * and the function will return the size of the output string.
375 * @return The length of the output string, not including any terminating NULL.
377 * @exception #I18N_ERROR_NONE Successful
378 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
380 int32_t i18n_unumber_parse_decimal (const i18n_unumber_format_h fmt, const i18n_uchar *text, int32_t text_length, int32_t *parse_pos, char *out_buf, int32_t out_buf_length);
383 * @brief Parses a string into a double and a currency using an #i18n_unumber_format_h.
384 * @details The string will be parsed according to the #i18n_unumber_format_h's locale.
385 * @remarks The specific error code can be obtained using the get_last_result() method.
386 * Error codes are described in Exceptions section and #i18n_error_code_e description.
389 * @param[in] fmt The formatter to use.
390 * @param[in] text The text to parse.
391 * @param[in] text_length The length of @a text, or -1 if NULL-terminated.
392 * @param[in,out] parse_pos A pointer to an offset index into text at which to begin parsing. On output, @a parse_pos will
393 * point after the last parsed character. This parameter may be NULL, in which case parsing begins
395 * If not NULL, on output the offset at which parsing ended.
396 * @param[out] currency A pointer to the buffer to receive the parsed NULL- terminated currency.
397 * This buffer must have a capacity of at least 4 #i18n_uchar characters.
399 * @return The parsed double
401 * @exception #I18N_ERROR_NONE Successful
402 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
404 double i18n_unumber_parse_double_currency (const i18n_unumber_format_h fmt, const i18n_uchar *text, int32_t text_length, int32_t *parse_pos, i18n_uchar *currency);
407 * @brief Sets the pattern used by an #i18n_unumber_format_h.
408 * @details This can only be used on a DecimalFormat, other formats return #I18N_ERROR_NOT_SUPPORTED in the status.
409 * @remarks Error codes are described in #i18n_error_code_e description.
412 * @param[in] format The formatter to set.
413 * @param[in] localized true if the pattern is localized, false otherwise.
414 * @param[in] pattern The new pattern
415 * @param[in] pattern_length The length of @a pattern, or -1 if NULL-terminated.
416 * @param[out] parse_error A pointer to #i18n_uparse_error_s to receive information about errors occurred during parsing,
417 * or NULL if no parse error information is desired.
419 * @return The obtained error code.
420 * @retval #I18N_ERROR_NONE Successful.
421 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
423 int i18n_unumber_apply_pattern (i18n_unumber_format_h format, i18n_ubool localized, const i18n_uchar *pattern, int32_t pattern_length, i18n_uparse_error_s* parse_error);
426 * @brief Gets a locale for which decimal formatting patterns are available.
427 * @details An #i18n_unumber_format_h in a locale returned by this function will perform the correct formatting and parsing for the locale.
428 * The results of this call are not valid for rule-based number formats.
429 * @remarks The specific error code can be obtained using the get_last_result() method.
430 * Error codes are described in Exceptions section.
433 * @param[in] locale_index The index of the desired locale.
435 * @return A locale for which number formatting patterns are available, or 0 if none.
437 * @exception #I18N_ERROR_NONE Successful
439 const char *i18n_unumber_get_available (int32_t locale_index);
442 * @brief Determines how many locales have decimal formatting patterns available.
443 * @details The results of this call are not valid for rule-based number formats.
444 * This function is useful for determining the loop ending condition for calls to i18n_unumber_get_available().
445 * @remarks The specific error code can be obtained using the get_last_result() method.
446 * Error codes are described in Exceptions section.
449 * @return The number of locales for which decimal formatting patterns are available.
451 * @exception #I18N_ERROR_NONE Successful
453 int32_t i18n_unumber_count_available (void);
456 * @brief Gets a numeric attribute associated with an #i18n_unumber_format_h.
457 * @details An example of a numeric attribute is the number of integer digits a formatter will produce.
458 * @remarks The specific error code can be obtained using the get_last_result() method.
459 * Error codes are described in Exceptions section.
462 * @param[in] fmt The formatter to query.
463 * @param[in] attr The attribute to query; one of #I18N_UNUMBER_PARSE_INT_ONLY, #I18N_UNUMBER_GROUPING_USED,
464 * #I18N_UNUMBER_DECIMAL_ALWAYS_SHOWN, #I18N_UNUMBER_MAX_INTEGER_DIGITS, #I18N_UNUMBER_MIN_INTEGER_DIGITS,
465 * #I18N_UNUMBER_INTEGER_DIGITS, #I18N_UNUMBER_MAX_FRACTION_DIGITS, #I18N_UNUMBER_MIN_FRACTION_DIGITS,
466 * #I18N_UNUMBER_FRACTION_DIGITS, #I18N_UNUMBER_MULTIPLIER, #I18N_UNUMBER_GROUPING_SIZE,
467 * #I18N_UNUMBER_ROUNDING_MODE, #I18N_UNUMBER_FORMAT_WIDTH, #I18N_UNUMBER_PADDING_POSITION,
468 * #I18N_UNUMBER_SECONDARY_GROUPING_SIZE, #I18N_UNUM_SCALE.
470 * @return The value of @a attr or @c -1 if the given attribute is not supported.
472 * @exception #I18N_ERROR_NONE Successful
473 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
475 int32_t i18n_unumber_get_attribute (const i18n_unumber_format_h fmt, i18n_unumber_format_attribute_e attr);
478 * @brief Sets a numeric attribute associated with an #i18n_unumber_format_h.
479 * @details An example of a numeric attribute is the number of integer digits a formatter will produce.
480 * If the formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand
481 * the lenient-parse attribute. The #I18N_UNUMBER_ROUNDING_INCREMENT attribute is not supported.
482 * @remarks Error codes are described in #i18n_error_code_e description.
485 * @param[in] fmt The formatter to set.
486 * @param[in] attr The attribute to query; one of #I18N_UNUMBER_PARSE_INT_ONLY, #I18N_UNUMBER_GROUPING_USED,
487 * #I18N_UNUMBER_DECIMAL_ALWAYS_SHOWN, #I18N_UNUMBER_MAX_INTEGER_DIGITS, #I18N_UNUMBER_MIN_INTEGER_DIGITS,
488 * #I18N_UNUMBER_INTEGER_DIGITS, #I18N_UNUMBER_MAX_FRACTION_DIGITS, #I18N_UNUMBER_MIN_FRACTION_DIGITS,
489 * #I18N_UNUMBER_FRACTION_DIGITS, #I18N_UNUMBER_MULTIPLIER, #I18N_UNUMBER_GROUPING_SIZE,
490 * #I18N_UNUMBER_ROUNDING_MODE, #I18N_UNUMBER_FORMAT_WIDTH, #I18N_UNUMBER_PADDING_POSITION,
491 * #I18N_UNUMBER_SECONDARY_GROUPING_SIZE, #I18N_UNUMBER_SIGNIFICANT_DIGITS_USED, #I18N_UNUMBER_MIN_SIGNIFICANT_DIGITS,
492 * #I18N_UNUMBER_MAX_SIGNIFICANT_DIGITS, #I18N_UNUMBER_LENIENT_PARSE, #I18N_UNUM_SCALE,
493 * #I18N_UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS, #I18N_UNUM_PARSE_NO_EXPONENT.
494 * @param[in] new_value The new value of @a attr.
496 * @return The obtained error code.
497 * @retval #I18N_ERROR_NONE Successful.
498 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
500 int i18n_unumber_set_attribute (i18n_unumber_format_h fmt, i18n_unumber_format_attribute_e attr, int32_t new_value);
503 * @brief Gets a numeric attribute associated with an #i18n_unumber_format_h.
504 * @details An example of a numeric attribute is the number of integer digits a formatter will produce.
505 * If the formatter does not understand the attribute, -1 is returned.
506 * @remarks The specific error code can be obtained using the get_last_result() method.
507 * Error codes are described in Exceptions section.
510 * @param[in] fmt The formatter to query.
511 * @param[in] attr The attribute to query; only #I18N_UNUMBER_ROUNDING_INCREMENT is supported.
513 * @return The value of @a attr.
515 * @exception #I18N_ERROR_NONE Successful
516 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
518 double i18n_unumber_get_double_attribute (const i18n_unumber_format_h fmt, i18n_unumber_format_attribute_e attr);
521 * @brief Sets a numeric attribute associated with an #i18n_unumber_format_h.
522 * @details An example of a numeric attribute is the number of integer digits a formatter will produce.
523 * If the formatter does not understand the attribute, this call is ignored.
524 * @remarks Error codes are described in #i18n_error_code_e description.
527 * @param[in] fmt The formatter to set.
528 * @param[in] attr The attribute to query; Only #I18N_UNUMBER_ROUNDING_INCREMENT is supported.
529 * @param[in] new_value The new value of @a attr.
531 * @return The obtained error code.
532 * @retval #I18N_ERROR_NONE Successful.
533 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
535 int i18n_unumber_set_double_attribute (i18n_unumber_format_h fmt, i18n_unumber_format_attribute_e attr, double new_value);
538 * @brief Gets a text attribute associated with an #i18n_unumber_format_h.
539 * @details An example of a text attribute is the suffix for positive numbers. If the formatter does not understand the attribute,
540 * #I18N_ERROR_NOT_SUPPORTED error code is set.
541 * Rule-based formatters only understand #I18N_UNUMBER_DEFAULT_RULESET and #I18N_UNUMBER_PUBLIC_RULESETS.
542 * @remarks The specific error code can be obtained using the get_last_result() method.
543 * Error codes are described in Exceptions section and #i18n_error_code_e description.
546 * @param[in] fmt The formatter to query.
547 * @param[in] tag The attribute to query; one of #I18N_UNUMBER_POSITIVE_PREFIX, #I18N_UNUMBER_POSITIVE_SUFFIX,
548 * #I18N_UNUMBER_NEGATIVE_PREFIX, #I18N_UNUMBER_NEGATIVE_SUFFIX, #I18N_UNUMBER_PADDING_CHARACTER,
549 * #I18N_UNUMBER_CURRENCY_CODE, #I18N_UNUMBER_DEFAULT_RULESET, or #I18N_UNUMBER_PUBLIC_RULESETS.
550 * @param[out] result A pointer to a buffer to receive the attribute.
551 * @param[in] result_length The maximum size of @a result.
553 * @return The total buffer size needed; if greater than @a result_length, the output was truncated.
555 * @exception #I18N_ERROR_NONE Successful
556 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
558 int32_t i18n_unumber_get_text_attribute (const i18n_unumber_format_h fmt, i18n_unumber_format_text_attribute_e tag, i18n_uchar *result, int32_t result_length);
561 * @brief Sets a text attribute associated with an #i18n_unumber_format_h.
562 * @details An example of a text attribute is the suffix for positive numbers. Rule-based formatters only understand
563 * #I18N_UNUMBER_DEFAULT_RULESET. The #I18N_UNUMBER_PUBLIC_RULESETS tag is not supported.
564 * @remarks Error codes are described in #i18n_error_code_e description.
567 * @param[in] fmt The formatter to set.
568 * @param[in] tag The attribute to set; one of #I18N_UNUMBER_POSITIVE_PREFIX, #I18N_UNUMBER_POSITIVE_SUFFIX,
569 * #I18N_UNUMBER_NEGATIVE_PREFIX, #I18N_UNUMBER_NEGATIVE_SUFFIX, #I18N_UNUMBER_PADDING_CHARACTER,
570 * #I18N_UNUMBER_CURRENCY_CODE, #I18N_UNUMBER_DEFAULT_RULESET.
571 * @param[in] new_value The new value of @a tag.
572 * @param[in] new_value_length The length of new_value, or -1 if NULL-terminated.
574 * @return The obtained error code.
575 * @retval #I18N_ERROR_NONE Successful.
576 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
578 int i18n_unumber_set_text_attribute (const i18n_unumber_format_h fmt, i18n_unumber_format_text_attribute_e tag, const i18n_uchar *new_value, int32_t new_value_length);
581 * @brief Extracts the pattern from an #i18n_unumber_format_h.
582 * @details The pattern will follow the DecimalFormat pattern syntax.
583 * @remarks The specific error code can be obtained using the get_last_result() method.
584 * Error codes are described in Exceptions section and #i18n_error_code_e description.
587 * @param[in] fmt The formatter to query.
588 * @param[in] is_pattern_localized true if the pattern should be localized, false otherwise.
589 * This is ignored if the formatter is a rule-based formatter.
590 * @param[out] result A pointer to a buffer to receive the pattern.
591 * @param[in] result_length The maximum size of @a result.
593 * @return The total buffer size needed; if greater than @a result_length, the output was truncated.
595 * @exception #I18N_ERROR_NONE Successful
596 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
598 int32_t i18n_unumber_to_pattern (const i18n_unumber_format_h fmt, i18n_ubool is_pattern_localized, i18n_uchar *result, int32_t result_length);
601 * @brief Sets a symbol associated with an #i18n_unumber_format_h.
602 * @details An #i18n_unumber_format_h uses symbols to represent the special locale-dependent characters in a number, for example the percent sign.
603 * This API is not supported for rule-based formatters.
604 * @remarks Error codes are described in #i18n_error_code_e description.
607 * @param[in] fmt The formatter to set.
608 * @param[in] symbol The #i18n_unumber_format_symbol_e constant for the symbol to set
609 * @param[in] value The string to set the symbol to
610 * @param[in] length The length of the input string, or -1 for a zero-terminated string
612 * @return The obtained error code.
613 * @retval #I18N_ERROR_NONE Successful.
614 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
616 int i18n_unumber_set_symbol (i18n_unumber_format_h fmt, i18n_unumber_format_symbol_e symbol, const i18n_uchar *value, int32_t length);
619 * @brief Gets the locale for this number format object.
620 * @details You can choose between valid and actual locale.
621 * @remarks The specific error code can be obtained using the get_last_result() method.
622 * Error codes are described in Exceptions section and #i18n_error_code_e description.
625 * @param[in] fmt The formatter to get the locale from.
626 * @param[in] type Type of the locale we're looking for (valid or actual)
628 * @return The locale name
630 * @exception #I18N_ERROR_NONE Successful
631 * @exception #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
633 const char *i18n_unumber_get_locale_by_type (const i18n_unumber_format_h fmt, i18n_ulocale_data_locale_type_e type);
645 #endif /* __UTILS_I18N_UNUMBER_H__*/