Tizen Native API
Functions
Unumber
i18n

Functions

int i18n_unumber_create (i18n_unumber_format_style_e style, const i18n_uchar *pattern, int32_t pattern_len, const char *locale, i18n_uparse_error_s *parse_err, i18n_unumber_format_h *num_format)
 Creates and returns a new unumber_format_h for formatting and parsing numbers.
int i18n_unumber_destroy (i18n_unumber_format_h fmt)
 Destroys an i18n_unumber_format_h.
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)
 Gets a symbol associated with an i18n_unumber_format_h.

The Unumber module helps you format and parse numbers for any locale.

Required Header

#include <utils_i18n.h>

Overview

The Unumber module helps you format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal. There are different number format styles like decimal, currency, percent and spellout.

Sample Code 1

Gets a currency symbol according to a given locale.

    int buf_len;
    i18n_uchar u_buffer[64];
    char a_buffer[64];
    i18n_unumber_format_h num_format;

    // creates and returns a new unumber_format
    i18n_unumber_create(I18N_UNUMBER_CURRENCY, NULL, -1, "en_US", NULL, &num_format);

    // gets a symbol associated with i18n_unumber_format
    i18n_unumber_get_symbol(num_format, I18N_UNUMBER_CURRENCY_SYMBOL, u_buffer, 64, &buf_len);
 
    i18n_ustring_copy_au(a_buffer, u_buffer);
    // en_US currency symbol: $
    dlog_print(DLOG_INFO, LOG_TAG, "en_US currency symbol: %s \n", a_buffer);

    // destroys i18n_unumber_format
    i18n_unumber_destroy(num_format);

Enumeration Type Documentation

Enumeration for the possible number format styles.

Enumerator:
I18N_UNUMBER_PATTERN_DECIMAL 

Decimal format defined by a pattern string

I18N_UNUMBER_DECIMAL 

Decimal format ("normal" style)

I18N_UNUMBER_CURRENCY 

Currency format with a currency symbol, e.g., "$1.00"

I18N_UNUMBER_PERCENT 

Percent format

I18N_UNUMBER_SCIENTIFIC 

Scientific format

I18N_UNUMBER_SPELLOUT 

Spellout rule-based format

I18N_UNUMBER_ORDINAL 

Ordinal rule-based format

I18N_UNUMBER_DURATION 

Duration rule-based format

I18N_UNUMBER_NUMBERING_SYSTEM 

Numbering system rule-based format

I18N_UNUMBER_PATTERN_RULEBASED 

Rule-based format defined by a pattern string

I18N_UNUMBER_CURRENCY_ISO 

Currency format with an ISO currency code, e.g., "USD1.00"

I18N_UNUMBER_CURRENCY_PLURAL 

Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars"

I18N_UNUMBER_FORMAT_STYLE_COUNT 

One more than the highest number format style constant

I18N_UNUMBER_DEFAULT 

Default format

I18N_UNUMBER_IGNORE 

Alias for I18N_UNUMBER_PATTERN_DECIMAL

Enumeration of constants for specifying a number format symbol.

Enumerator:
I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL 

The decimal separator

I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL 

The grouping separator

I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL 

The pattern separator

I18N_UNUMBER_PERCENT_SYMBOL 

The percent sign

I18N_UNUMBER_ZERO_DIGIT_SYMBOL 

Zero

I18N_UNUMBER_DIGIT_SYMBOL 

Character representing a digit in the pattern.

I18N_UNUMBER_MINUS_SIGN_SYMBOL 

The minus sign

I18N_UNUMBER_PLUS_SIGN_SYMBOL 

The plus sign

I18N_UNUMBER_CURRENCY_SYMBOL 

The currency symbol

I18N_UNUMBER_INTL_CURRENCY_SYMBOL 

The international currency symbol

I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL 

The monetary separator

I18N_UNUMBER_EXPONENTIAL_SYMBOL 

The exponential symbol

I18N_UNUMBER_PERMILL_SYMBOL 

Per mill symbol

I18N_UNUMBER_PAD_ESCAPE_SYMBOL 

Escape padding character

I18N_UNUMBER_INFINITY_SYMBOL 

Infinity symbol

I18N_UNUMBER_NAN_SYMBOL 

Nan symbol

I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL 

Significant digit symbol

I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL 

The monetary grouping separator

I18N_UNUMBER_ONE_DIGIT_SYMBOL 

One

I18N_UNUMBER_TWO_DIGIT_SYMBOL 

Two

I18N_UNUMBER_THREE_DIGIT_SYMBOL 

Three

I18N_UNUMBER_FOUR_DIGIT_SYMBOL 

Four

I18N_UNUMBER_FIVE_DIGIT_SYMBOL 

Five

I18N_UNUMBER_SIX_DIGIT_SYMBOL 

Six

I18N_UNUMBER_SEVEN_DIGIT_SYMBOL 

Seven

I18N_UNUMBER_EIGHT_DIGIT_SYMBOL 

Eight

I18N_UNUMBER_NINE_DIGIT_SYMBOL 

Nine

I18N_UNUMBER_FORMAT_SYMBOL_COUNT 

count symbol constants


Function Documentation

int i18n_unumber_create ( i18n_unumber_format_style_e  style,
const i18n_uchar *  pattern,
int32_t  pattern_len,
const char *  locale,
i18n_uparse_error_s *  parse_err,
i18n_unumber_format_h *  num_format 
)

Creates and returns a new unumber_format_h for formatting and parsing numbers.

A unumber_format_style_e may be used to format numbers by calling i18n_unumber_create(). The caller must call i18n_unumber_destroy() when done to release resources used by this object.

Since :
2.3
Remarks:
Must release num_format using i18n_unumber_destroy().
Parameters:
[in]styleThe type of number format to open: one of I18N_UNUMBER_DECIMAL, I18N_UNUMBER_CURRENCY, I18N_UNUMBER_PERCENT, I18N_UNUMBER_SCIENTIFIC, I18N_UNUMBER_SPELLOUT, I18N_UNUMBER_ORDINAL, I18N_UNUMBER_DURATION, I18N_UNUMBER_NUMBERING_SYSTEM, I18N_UNUMBER_PATTERN_RULEBASED, or I18N_UNUMBER_DEFAULT
If I18N_UNUMBER_PATTERN_DECIMAL or I18N_UNUMBER_PATTERN_RULEBASED is passed then the number format is opened using the given pattern, which must conform to the syntax described in DecimalFormat or RuleBasedNumberFormat, respectively.
[in]patternA pattern specifying the format to use
This parameter is ignored unless the style is I18N_UNUMBER_PATTERN_DECIMAL or I18N_UNUMBER_PATTERN_RULEBASED.
[in]pattern_lenThe number of characters in the pattern, otherwise -1 if null-terminated
This parameter is ignored unless the style is I18N_UNUMBER_PATTERN.
[in]localeA locale identifier to use to determine formatting and parsing conventions, otherwise NULL to use the default locale.
[in]parse_errA pointer to a i18n_unumber_uparse_error_h struct to receive the details of any parsing errors, otherwise NULL if no parsing error details are desired.
[out]num_formatA pointer to a newly created i18n_unumber_format_h, otherwise NULL if an error occurrs.
Return values:
I18N_ERROR_NONESuccessful
I18N_ERROR_INVALID_PARAMETERInvalid function parameter
int i18n_unumber_destroy ( i18n_unumber_format_h  fmt)

Destroys an i18n_unumber_format_h.

Once destroyed, an i18n_unumber_format may no longer be used.

Since :
2.3
Parameters:
[in]fmtThe formatter to destroy
Return values:
I18N_ERROR_NONESuccessful
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 
)

Gets a symbol associated with an i18n_unumber_format_h.

An i18n_unumber_format_h uses symbols to represent the special locale-dependent characters in a number, for example the percent sign. This API is not supported for rule-based formatters.

Since :
2.3
Parameters:
[in]fmtThe formatter to query.
[in]symbolThe unumber_format_symbol_e constant for the symbol to get
[out]bufferThe string buffer that will receive the symbol string
If it is NULL, then only the length of the symbol is returned.
[in]sizeThe size of the string buffer
[out]len_symbolThe length of the symbol
The buffer is not modified if length >= size
Return values:
I18N_ERROR_NONESuccessful.
I18N_ERROR_INVALID_PARAMETERInvalid function parameter

Except as noted, this content - excluding the Code Examples - is licensed under Creative Commons Attribution 3.0 and all of the Code Examples contained herein are licensed under BSD-3-Clause.
For details, see the Content License