2 *****************************************************************************************
3 * Copyright (C) 2010-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *****************************************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_FORMATTING
15 #include "unicode/localpointer.h"
19 * \brief C API: Plural rules, select plural keywords for numeric values.
21 * A UPluralRules object defines rules for mapping non-negative numeric
22 * values onto a small set of keywords. Rules are constructed from a text
23 * description, consisting of a series of keywords and conditions.
24 * The uplrules_select function examines each condition in order and
25 * returns the keyword for the first condition that matches the number.
26 * If none match, the default rule(other) is returned.
28 * For more information, see the LDML spec, C.11 Language Plural Rules:
29 * http://www.unicode.org/reports/tr35/#Language_Plural_Rules
31 * Keywords: ICU locale data has 6 predefined values -
32 * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check
33 * the value of keyword returned by the uplrules_select function.
35 * These are based on CLDR <i>Language Plural Rules</i>. For these
36 * predefined rules, see the CLDR page at
37 * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
41 * Type of plurals and PluralRules.
46 * Plural rules for cardinal numbers: 1 file vs. 2 files.
49 UPLURAL_TYPE_CARDINAL,
51 * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
56 * Number of Plural rules types.
64 typedef enum UPluralType UPluralType;
67 * Opaque UPluralRules object for use in C programs.
71 typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
74 * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
76 * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).
77 * @param locale The locale for which the rules are desired.
78 * @param status A pointer to a UErrorCode to receive any errors.
79 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
82 U_STABLE UPluralRules* U_EXPORT2
83 uplrules_open(const char *locale, UErrorCode *status);
86 * Opens a new UPluralRules object using the predefined plural rules for a
87 * given locale and the plural type.
88 * @param locale The locale for which the rules are desired.
89 * @param type The plural type (e.g., cardinal or ordinal).
90 * @param status A pointer to a UErrorCode to receive any errors.
91 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
94 U_DRAFT UPluralRules* U_EXPORT2
95 uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status);
98 * Closes a UPluralRules object. Once closed it may no longer be used.
99 * @param uplrules The UPluralRules object to close.
102 U_STABLE void U_EXPORT2
103 uplrules_close(UPluralRules *uplrules);
106 #if U_SHOW_CPLUSPLUS_API
111 * \class LocalUPluralRulesPointer
112 * "Smart pointer" class, closes a UPluralRules via uplrules_close().
113 * For most methods see the LocalPointerBase base class.
115 * @see LocalPointerBase
119 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
127 * Given a number, returns the keyword of the first rule that
128 * applies to the number, according to the supplied UPluralRules object.
129 * @param uplrules The UPluralRules object specifying the rules.
130 * @param number The number for which the rule has to be determined.
131 * @param keyword The keyword of the rule that applies to number.
132 * @param capacity The capacity of keyword.
133 * @param status A pointer to a UErrorCode to receive any errors.
134 * @return The length of keyword.
137 U_STABLE int32_t U_EXPORT2
138 uplrules_select(const UPluralRules *uplrules,
140 UChar *keyword, int32_t capacity,
143 #endif /* #if !UCONFIG_NO_FORMATTING */