]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/upluralrules.h
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / upluralrules.h
1 /*
2 *****************************************************************************************
3 * Copyright (C) 2010-2012, 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 * Opaque UPluralRules object for use in C programs.
42 * @stable ICU 4.8
43 */
44 struct UPluralRules;
45 typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
46
47 /**
48 * Open a new UPluralRules object using the predefined plural rules for a
49 * given locale.
50 * @param locale The locale for which the rules are desired.
51 * @param status A pointer to a UErrorCode to receive any errors.
52 * @return A UPluralRules for the specified locale, or 0 if an error occurred.
53 * @stable ICU 4.8
54 */
55 U_DRAFT UPluralRules* U_EXPORT2
56 uplrules_open(const char *locale,
57 UErrorCode *status);
58
59 /**
60 * Close a UPluralRules object. Once closed it may no longer be used.
61 * @param uplrules The UPluralRules object to close.
62 * @stable ICU 4.8
63 */
64 U_DRAFT void U_EXPORT2
65 uplrules_close(UPluralRules *uplrules);
66
67
68 #if U_SHOW_CPLUSPLUS_API
69
70 U_NAMESPACE_BEGIN
71
72 /**
73 * \class LocalUPluralRulesPointer
74 * "Smart pointer" class, closes a UPluralRules via uplrules_close().
75 * For most methods see the LocalPointerBase base class.
76 *
77 * @see LocalPointerBase
78 * @see LocalPointer
79 * @stable ICU 4.8
80 */
81 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
82
83 U_NAMESPACE_END
84
85 #endif
86
87
88 /**
89 * Given a number, returns the keyword of the first rule that
90 * applies to the number, according to the supplied UPluralRules object.
91 * @param uplrules The UPluralRules object specifying the rules.
92 * @param number The number for which the rule has to be determined.
93 * @param keyword The keyword of the rule that applies to number.
94 * @param capacity The capacity of keyword.
95 * @param status A pointer to a UErrorCode to receive any errors.
96 * @return The length of keyword.
97 * @stable ICU 4.8
98 */
99 U_DRAFT int32_t U_EXPORT2
100 uplrules_select(const UPluralRules *uplrules,
101 double number,
102 UChar *keyword, int32_t capacity,
103 UErrorCode *status);
104
105 #endif /* #if !UCONFIG_NO_FORMATTING */
106
107 #endif