1 // Copyright (C) 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ***************************************************************************************** 5 * Copyright (C) 2010-2013, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ***************************************************************************************** 8 */ 9 10 #ifndef UPLURALRULES_H 11 #define UPLURALRULES_H 12 13 #include "unicode/utypes.h" 14 15 #if !UCONFIG_NO_FORMATTING 16 17 #include "unicode/localpointer.h" 18 19 /** 20 * \file 21 * \brief C API: Plural rules, select plural keywords for numeric values. 22 * 23 * A UPluralRules object defines rules for mapping non-negative numeric 24 * values onto a small set of keywords. Rules are constructed from a text 25 * description, consisting of a series of keywords and conditions. 26 * The uplrules_select function examines each condition in order and 27 * returns the keyword for the first condition that matches the number. 28 * If none match, the default rule(other) is returned. 29 * 30 * For more information, see the LDML spec, C.11 Language Plural Rules: 31 * http://www.unicode.org/reports/tr35/#Language_Plural_Rules 32 * 33 * Keywords: ICU locale data has 6 predefined values - 34 * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check 35 * the value of keyword returned by the uplrules_select function. 36 * 37 * These are based on CLDR <i>Language Plural Rules</i>. For these 38 * predefined rules, see the CLDR page at 39 * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 40 */ 41 42 /** 43 * Type of plurals and PluralRules. 44 * @stable ICU 50 45 */ 46 enum UPluralType { 47 /** 48 * Plural rules for cardinal numbers: 1 file vs. 2 files. 49 * @stable ICU 50 50 */ 51 UPLURAL_TYPE_CARDINAL, 52 /** 53 * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc. 54 * @stable ICU 50 55 */ 56 UPLURAL_TYPE_ORDINAL, 57 #ifndef U_HIDE_DEPRECATED_API 58 /** 59 * One more than the highest normal UPluralType value. 60 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 61 */ 62 UPLURAL_TYPE_COUNT 63 #endif // U_HIDE_DEPRECATED_API 64 }; 65 /** 66 * @stable ICU 50 67 */ 68 typedef enum UPluralType UPluralType; 69 70 /** 71 * Opaque UPluralRules object for use in C programs. 72 * @stable ICU 4.8 73 */ 74 struct UPluralRules; 75 typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */ 76 77 /** 78 * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a 79 * given locale. 80 * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status). 81 * @param locale The locale for which the rules are desired. 82 * @param status A pointer to a UErrorCode to receive any errors. 83 * @return A UPluralRules for the specified locale, or NULL if an error occurred. 84 * @stable ICU 4.8 85 */ 86 U_STABLE UPluralRules* U_EXPORT2 87 uplrules_open(const char *locale, UErrorCode *status); 88 89 /** 90 * Opens a new UPluralRules object using the predefined plural rules for a 91 * given locale and the plural type. 92 * @param locale The locale for which the rules are desired. 93 * @param type The plural type (e.g., cardinal or ordinal). 94 * @param status A pointer to a UErrorCode to receive any errors. 95 * @return A UPluralRules for the specified locale, or NULL if an error occurred. 96 * @stable ICU 50 97 */ 98 U_DRAFT UPluralRules* U_EXPORT2 99 uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status); 100 101 /** 102 * Closes a UPluralRules object. Once closed it may no longer be used. 103 * @param uplrules The UPluralRules object to close. 104 * @stable ICU 4.8 105 */ 106 U_STABLE void U_EXPORT2 107 uplrules_close(UPluralRules *uplrules); 108 109 110 #if U_SHOW_CPLUSPLUS_API 111 112 U_NAMESPACE_BEGIN 113 114 /** 115 * \class LocalUPluralRulesPointer 116 * "Smart pointer" class, closes a UPluralRules via uplrules_close(). 117 * For most methods see the LocalPointerBase base class. 118 * 119 * @see LocalPointerBase 120 * @see LocalPointer 121 * @stable ICU 4.8 122 */ 123 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close); 124 125 U_NAMESPACE_END 126 127 #endif 128 129 130 /** 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. 139 * @stable ICU 4.8 140 */ 141 U_STABLE int32_t U_EXPORT2 142 uplrules_select(const UPluralRules *uplrules, 143 double number, 144 UChar *keyword, int32_t capacity, 145 UErrorCode *status); 146 147 #endif /* #if !UCONFIG_NO_FORMATTING */ 148 149 #endif 150