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
40 #ifndef U_HIDE_DRAFT_API
42 * Type of plurals and PluralRules.
47 * Plural rules for cardinal numbers: 1 file vs. 2 files.
50 UPLURAL_TYPE_CARDINAL
,
52 * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
57 * Number of Plural rules types.
65 typedef enum UPluralType UPluralType
;
66 #endif /* U_HIDE_DRAFT_API */
69 * Opaque UPluralRules object for use in C programs.
73 typedef struct UPluralRules UPluralRules
; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
76 * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
78 * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).
79 * @param locale The locale for which the rules are desired.
80 * @param status A pointer to a UErrorCode to receive any errors.
81 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
84 U_STABLE UPluralRules
* U_EXPORT2
85 uplrules_open(const char *locale
, UErrorCode
*status
);
87 #ifndef U_HIDE_DRAFT_API
89 * Opens a new UPluralRules object using the predefined plural rules for a
90 * given locale and the plural type.
91 * @param locale The locale for which the rules are desired.
92 * @param type The plural type (e.g., cardinal or ordinal).
93 * @param status A pointer to a UErrorCode to receive any errors.
94 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
97 U_DRAFT UPluralRules
* U_EXPORT2
98 uplrules_openForType(const char *locale
, UPluralType type
, UErrorCode
*status
);
99 #endif /* U_HIDE_DRAFT_API */
102 * Closes a UPluralRules object. Once closed it may no longer be used.
103 * @param uplrules The UPluralRules object to close.
106 U_STABLE
void U_EXPORT2
107 uplrules_close(UPluralRules
*uplrules
);
110 #if U_SHOW_CPLUSPLUS_API
115 * \class LocalUPluralRulesPointer
116 * "Smart pointer" class, closes a UPluralRules via uplrules_close().
117 * For most methods see the LocalPointerBase base class.
119 * @see LocalPointerBase
123 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer
, UPluralRules
, uplrules_close
);
131 * Given a number, returns the keyword of the first rule that
132 * applies to the number, according to the supplied UPluralRules object.
133 * @param uplrules The UPluralRules object specifying the rules.
134 * @param number The number for which the rule has to be determined.
135 * @param keyword The keyword of the rule that applies to number.
136 * @param capacity The capacity of keyword.
137 * @param status A pointer to a UErrorCode to receive any errors.
138 * @return The length of keyword.
141 U_STABLE
int32_t U_EXPORT2
142 uplrules_select(const UPluralRules
*uplrules
,
144 UChar
*keyword
, int32_t capacity
,
147 #endif /* #if !UCONFIG_NO_FORMATTING */