ICU 60.2  60.2
Namespaces | Typedefs | Enumerations | Functions
upluralrules.h File Reference

C API: Plural rules, select plural keywords for numeric values. More...

#include "unicode/utypes.h"
#include "unicode/localpointer.h"
#include "unicode/uenum.h"
#include "unicode/unum.h"

Go to the source code of this file.

Namespaces

 icu
 File coll.h.
 

Typedefs

typedef enum UPluralType UPluralType
 
typedef struct UPluralRules UPluralRules
 C typedef for struct UPluralRules. More...
 

Enumerations

enum  UPluralType { UPLURAL_TYPE_CARDINAL, UPLURAL_TYPE_ORDINAL, UPLURAL_TYPE_COUNT }
 Type of plurals and PluralRules. More...
 

Functions

U_CAPI UPluralRulesuplrules_open (const char *locale, UErrorCode *status)
 Opens a new UPluralRules object using the predefined cardinal-number plural rules for a given locale. More...
 
U_CAPI UPluralRulesuplrules_openForType (const char *locale, UPluralType type, UErrorCode *status)
 Opens a new UPluralRules object using the predefined plural rules for a given locale and the plural type. More...
 
U_CAPI void uplrules_close (UPluralRules *uplrules)
 Closes a UPluralRules object. More...
 
U_CAPI int32_t uplrules_select (const UPluralRules *uplrules, double number, UChar *keyword, int32_t capacity, UErrorCode *status)
 Given a number, returns the keyword of the first rule that applies to the number, according to the supplied UPluralRules object. More...
 
int32_t uplrules_selectWithFormat (const UPluralRules *uplrules, double number, const UNumberFormat *fmt, UChar *keyword, int32_t capacity, UErrorCode *status)
 Given a number, returns the keyword of the first rule that applies to the number, according to the UPluralRules object and given the number format specified by the UNumberFormat object. More...
 
UEnumerationuplrules_getKeywords (const UPluralRules *uplrules, UErrorCode *status)
 Creates a string enumeration of all plural rule keywords used in this UPluralRules object. More...
 

Detailed Description

C API: Plural rules, select plural keywords for numeric values.

A UPluralRules object defines rules for mapping non-negative numeric values onto a small set of keywords. Rules are constructed from a text description, consisting of a series of keywords and conditions. The uplrules_select function examines each condition in order and returns the keyword for the first condition that matches the number. If none match, the default rule(other) is returned.

For more information, see the LDML spec, C.11 Language Plural Rules: http://www.unicode.org/reports/tr35/#Language_Plural_Rules

Keywords: ICU locale data has 6 predefined values - 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check the value of keyword returned by the uplrules_select function.

These are based on CLDR Language Plural Rules. For these predefined rules, see the CLDR page at http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html

Definition in file upluralrules.h.

Typedef Documentation

typedef struct UPluralRules UPluralRules

C typedef for struct UPluralRules.

Stable:
ICU 4.8

Definition at line 79 of file upluralrules.h.

typedef enum UPluralType UPluralType
Stable:
ICU 50

Definition at line 72 of file upluralrules.h.

Enumeration Type Documentation

Type of plurals and PluralRules.

Stable:
ICU 50
Enumerator
UPLURAL_TYPE_CARDINAL 

Plural rules for cardinal numbers: 1 file vs.

2 files.

Stable:
ICU 50
UPLURAL_TYPE_ORDINAL 

Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.

Stable:
ICU 50
UPLURAL_TYPE_COUNT 

One more than the highest normal UPluralType value.

Deprecated:
ICU 58 The numeric value may change over time, see ICU ticket #12420.

Definition at line 50 of file upluralrules.h.

Function Documentation

U_CAPI void uplrules_close ( UPluralRules uplrules)

Closes a UPluralRules object.

Once closed it may no longer be used.

Parameters
uplrulesThe UPluralRules object to close.
Stable:
ICU 4.8
UEnumeration* uplrules_getKeywords ( const UPluralRules uplrules,
UErrorCode status 
)

Creates a string enumeration of all plural rule keywords used in this UPluralRules object.

The rule "other" is always present by default.

Parameters
uplrulesThe UPluralRules object specifying the rules for a given locale.
statusA pointer to a UErrorCode to receive any errors.
Returns
a string enumeration over plural rule keywords, or NULL upon error. The caller is responsible for closing the result.
Draft:
This API may be changed in the future versions and was introduced in ICU 59
U_CAPI UPluralRules* uplrules_open ( const char *  locale,
UErrorCode status 
)

Opens a new UPluralRules object using the predefined cardinal-number plural rules for a given locale.

Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).

Parameters
localeThe locale for which the rules are desired.
statusA pointer to a UErrorCode to receive any errors.
Returns
A UPluralRules for the specified locale, or NULL if an error occurred.
Stable:
ICU 4.8
U_CAPI UPluralRules* uplrules_openForType ( const char *  locale,
UPluralType  type,
UErrorCode status 
)

Opens a new UPluralRules object using the predefined plural rules for a given locale and the plural type.

Parameters
localeThe locale for which the rules are desired.
typeThe plural type (e.g., cardinal or ordinal).
statusA pointer to a UErrorCode to receive any errors.
Returns
A UPluralRules for the specified locale, or NULL if an error occurred.
Stable:
ICU 50
U_CAPI int32_t uplrules_select ( const UPluralRules uplrules,
double  number,
UChar keyword,
int32_t  capacity,
UErrorCode status 
)

Given a number, returns the keyword of the first rule that applies to the number, according to the supplied UPluralRules object.

Parameters
uplrulesThe UPluralRules object specifying the rules.
numberThe number for which the rule has to be determined.
keywordThe keyword of the rule that applies to number.
capacityThe capacity of keyword.
statusA pointer to a UErrorCode to receive any errors.
Returns
The length of keyword.
Stable:
ICU 4.8
int32_t uplrules_selectWithFormat ( const UPluralRules uplrules,
double  number,
const UNumberFormat fmt,
UChar keyword,
int32_t  capacity,
UErrorCode status 
)

Given a number, returns the keyword of the first rule that applies to the number, according to the UPluralRules object and given the number format specified by the UNumberFormat object.

Note: This internal preview interface may be removed in the future if an architecturally cleaner solution reaches stable status.

Parameters
uplrulesThe UPluralRules object specifying the rules.
numberThe number for which the rule has to be determined.
fmtThe UNumberFormat specifying how the number will be formatted (this can affect the plural form, e.g. "1 dollar" vs "1.0 dollars"). If this is NULL, the function behaves like uplrules_select.
keywordThe keyword of the rule that applies to number.
capacityThe capacity of the keyword buffer.
statusA pointer to a UErrorCode to receive any errors.
Returns
The length of keyword.
Internal:
Do not use. This API is for internal use only. ICU 59 technology preview, may be removed in the future