Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / icu / source / i18n / unicode / upluralrules.h
1 /*
2 *****************************************************************************************
3 * Copyright (C) 2010-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *****************************************************************************************
6 */
7
8 #ifndef UPLURALRULES_H
9 #define UPLURALRULES_H
10
11 #include "unicode/utypes.h"
12
13 #if !UCONFIG_NO_FORMATTING
14
15 #include "unicode/localpointer.h"
16
17 /**
18  * \file
19  * \brief C API: Plural rules, select plural keywords for numeric values.
20  *
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.
27  *
28  * For more information, see the LDML spec, C.11 Language Plural Rules:
29  * http://www.unicode.org/reports/tr35/#Language_Plural_Rules
30  *
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.
34  *
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
38  */
39
40 /**
41  * Type of plurals and PluralRules.
42  * @stable ICU 50
43  */
44 enum UPluralType {
45     /**
46      * Plural rules for cardinal numbers: 1 file vs. 2 files.
47      * @stable ICU 50
48      */
49     UPLURAL_TYPE_CARDINAL,
50     /**
51      * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
52      * @stable ICU 50
53      */
54     UPLURAL_TYPE_ORDINAL,
55     /**
56      * Number of Plural rules types.
57      * @stable ICU 50
58      */
59     UPLURAL_TYPE_COUNT
60 };
61 /**
62  * @stable ICU 50
63  */
64 typedef enum UPluralType UPluralType;
65
66 /**
67  * Opaque UPluralRules object for use in C programs.
68  * @stable ICU 4.8
69  */
70 struct UPluralRules;
71 typedef struct UPluralRules UPluralRules;  /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
72
73 /**
74  * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
75  * given locale.
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.
80  * @stable ICU 4.8
81  */
82 U_STABLE UPluralRules* U_EXPORT2
83 uplrules_open(const char *locale, UErrorCode *status);
84
85 /**
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.
92  * @stable ICU 50
93  */
94 U_DRAFT UPluralRules* U_EXPORT2
95 uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status);
96
97 /**
98  * Closes a UPluralRules object. Once closed it may no longer be used.
99  * @param uplrules The UPluralRules object to close.
100  * @stable ICU 4.8
101  */
102 U_STABLE void U_EXPORT2
103 uplrules_close(UPluralRules *uplrules);
104
105
106 #if U_SHOW_CPLUSPLUS_API
107
108 U_NAMESPACE_BEGIN
109
110 /**
111  * \class LocalUPluralRulesPointer
112  * "Smart pointer" class, closes a UPluralRules via uplrules_close().
113  * For most methods see the LocalPointerBase base class.
114  *
115  * @see LocalPointerBase
116  * @see LocalPointer
117  * @stable ICU 4.8
118  */
119 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
120
121 U_NAMESPACE_END
122
123 #endif
124
125
126 /**
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.
135  * @stable ICU 4.8
136  */
137 U_STABLE int32_t U_EXPORT2
138 uplrules_select(const UPluralRules *uplrules,
139                double number,
140                UChar *keyword, int32_t capacity,
141                UErrorCode *status);
142
143 #endif /* #if !UCONFIG_NO_FORMATTING */
144
145 #endif