annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/upluralrules.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 // © 2016 and later: Unicode, Inc. and others.
jpayne@69 2 // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69 3 /*
jpayne@69 4 *****************************************************************************************
jpayne@69 5 * Copyright (C) 2010-2013, International Business Machines
jpayne@69 6 * Corporation and others. All Rights Reserved.
jpayne@69 7 *****************************************************************************************
jpayne@69 8 */
jpayne@69 9
jpayne@69 10 #ifndef UPLURALRULES_H
jpayne@69 11 #define UPLURALRULES_H
jpayne@69 12
jpayne@69 13 #include "unicode/utypes.h"
jpayne@69 14
jpayne@69 15 #if !UCONFIG_NO_FORMATTING
jpayne@69 16
jpayne@69 17 #include "unicode/localpointer.h"
jpayne@69 18 #include "unicode/uenum.h"
jpayne@69 19 #ifndef U_HIDE_INTERNAL_API
jpayne@69 20 #include "unicode/unum.h"
jpayne@69 21 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 22
jpayne@69 23 // Forward-declaration
jpayne@69 24 struct UFormattedNumber;
jpayne@69 25
jpayne@69 26 /**
jpayne@69 27 * \file
jpayne@69 28 * \brief C API: Plural rules, select plural keywords for numeric values.
jpayne@69 29 *
jpayne@69 30 * A UPluralRules object defines rules for mapping non-negative numeric
jpayne@69 31 * values onto a small set of keywords. Rules are constructed from a text
jpayne@69 32 * description, consisting of a series of keywords and conditions.
jpayne@69 33 * The uplrules_select function examines each condition in order and
jpayne@69 34 * returns the keyword for the first condition that matches the number.
jpayne@69 35 * If none match, the default rule(other) is returned.
jpayne@69 36 *
jpayne@69 37 * For more information, see the LDML spec, C.11 Language Plural Rules:
jpayne@69 38 * http://www.unicode.org/reports/tr35/#Language_Plural_Rules
jpayne@69 39 *
jpayne@69 40 * Keywords: ICU locale data has 6 predefined values -
jpayne@69 41 * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check
jpayne@69 42 * the value of keyword returned by the uplrules_select function.
jpayne@69 43 *
jpayne@69 44 * These are based on CLDR <i>Language Plural Rules</i>. For these
jpayne@69 45 * predefined rules, see the CLDR page at
jpayne@69 46 * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
jpayne@69 47 */
jpayne@69 48
jpayne@69 49 /**
jpayne@69 50 * Type of plurals and PluralRules.
jpayne@69 51 * @stable ICU 50
jpayne@69 52 */
jpayne@69 53 enum UPluralType {
jpayne@69 54 /**
jpayne@69 55 * Plural rules for cardinal numbers: 1 file vs. 2 files.
jpayne@69 56 * @stable ICU 50
jpayne@69 57 */
jpayne@69 58 UPLURAL_TYPE_CARDINAL,
jpayne@69 59 /**
jpayne@69 60 * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
jpayne@69 61 * @stable ICU 50
jpayne@69 62 */
jpayne@69 63 UPLURAL_TYPE_ORDINAL,
jpayne@69 64 #ifndef U_HIDE_DEPRECATED_API
jpayne@69 65 /**
jpayne@69 66 * One more than the highest normal UPluralType value.
jpayne@69 67 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
jpayne@69 68 */
jpayne@69 69 UPLURAL_TYPE_COUNT
jpayne@69 70 #endif /* U_HIDE_DEPRECATED_API */
jpayne@69 71 };
jpayne@69 72 /**
jpayne@69 73 * @stable ICU 50
jpayne@69 74 */
jpayne@69 75 typedef enum UPluralType UPluralType;
jpayne@69 76
jpayne@69 77 /**
jpayne@69 78 * Opaque UPluralRules object for use in C programs.
jpayne@69 79 * @stable ICU 4.8
jpayne@69 80 */
jpayne@69 81 struct UPluralRules;
jpayne@69 82 typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
jpayne@69 83
jpayne@69 84 /**
jpayne@69 85 * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
jpayne@69 86 * given locale.
jpayne@69 87 * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).
jpayne@69 88 * @param locale The locale for which the rules are desired.
jpayne@69 89 * @param status A pointer to a UErrorCode to receive any errors.
jpayne@69 90 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
jpayne@69 91 * @stable ICU 4.8
jpayne@69 92 */
jpayne@69 93 U_CAPI UPluralRules* U_EXPORT2
jpayne@69 94 uplrules_open(const char *locale, UErrorCode *status);
jpayne@69 95
jpayne@69 96 /**
jpayne@69 97 * Opens a new UPluralRules object using the predefined plural rules for a
jpayne@69 98 * given locale and the plural type.
jpayne@69 99 * @param locale The locale for which the rules are desired.
jpayne@69 100 * @param type The plural type (e.g., cardinal or ordinal).
jpayne@69 101 * @param status A pointer to a UErrorCode to receive any errors.
jpayne@69 102 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
jpayne@69 103 * @stable ICU 50
jpayne@69 104 */
jpayne@69 105 U_CAPI UPluralRules* U_EXPORT2
jpayne@69 106 uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status);
jpayne@69 107
jpayne@69 108 /**
jpayne@69 109 * Closes a UPluralRules object. Once closed it may no longer be used.
jpayne@69 110 * @param uplrules The UPluralRules object to close.
jpayne@69 111 * @stable ICU 4.8
jpayne@69 112 */
jpayne@69 113 U_CAPI void U_EXPORT2
jpayne@69 114 uplrules_close(UPluralRules *uplrules);
jpayne@69 115
jpayne@69 116
jpayne@69 117 #if U_SHOW_CPLUSPLUS_API
jpayne@69 118
jpayne@69 119 U_NAMESPACE_BEGIN
jpayne@69 120
jpayne@69 121 /**
jpayne@69 122 * \class LocalUPluralRulesPointer
jpayne@69 123 * "Smart pointer" class, closes a UPluralRules via uplrules_close().
jpayne@69 124 * For most methods see the LocalPointerBase base class.
jpayne@69 125 *
jpayne@69 126 * @see LocalPointerBase
jpayne@69 127 * @see LocalPointer
jpayne@69 128 * @stable ICU 4.8
jpayne@69 129 */
jpayne@69 130 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
jpayne@69 131
jpayne@69 132 U_NAMESPACE_END
jpayne@69 133
jpayne@69 134 #endif
jpayne@69 135
jpayne@69 136
jpayne@69 137 /**
jpayne@69 138 * Given a floating-point number, returns the keyword of the first rule that
jpayne@69 139 * applies to the number, according to the supplied UPluralRules object.
jpayne@69 140 * @param uplrules The UPluralRules object specifying the rules.
jpayne@69 141 * @param number The number for which the rule has to be determined.
jpayne@69 142 * @param keyword An output buffer to write the keyword of the rule that
jpayne@69 143 * applies to number.
jpayne@69 144 * @param capacity The capacity of the keyword buffer.
jpayne@69 145 * @param status A pointer to a UErrorCode to receive any errors.
jpayne@69 146 * @return The length of the keyword.
jpayne@69 147 * @stable ICU 4.8
jpayne@69 148 */
jpayne@69 149 U_CAPI int32_t U_EXPORT2
jpayne@69 150 uplrules_select(const UPluralRules *uplrules,
jpayne@69 151 double number,
jpayne@69 152 UChar *keyword, int32_t capacity,
jpayne@69 153 UErrorCode *status);
jpayne@69 154
jpayne@69 155 /**
jpayne@69 156 * Given a formatted number, returns the keyword of the first rule
jpayne@69 157 * that applies to the number, according to the supplied UPluralRules object.
jpayne@69 158 *
jpayne@69 159 * A UFormattedNumber allows you to specify an exponent or trailing zeros,
jpayne@69 160 * which can affect the plural category. To get a UFormattedNumber, see
jpayne@69 161 * {@link UNumberFormatter}.
jpayne@69 162 *
jpayne@69 163 * @param uplrules The UPluralRules object specifying the rules.
jpayne@69 164 * @param number The formatted number for which the rule has to be determined.
jpayne@69 165 * @param keyword The destination buffer for the keyword of the rule that
jpayne@69 166 * applies to number.
jpayne@69 167 * @param capacity The capacity of the keyword buffer.
jpayne@69 168 * @param status A pointer to a UErrorCode to receive any errors.
jpayne@69 169 * @return The length of the keyword.
jpayne@69 170 * @stable ICU 64
jpayne@69 171 */
jpayne@69 172 U_CAPI int32_t U_EXPORT2
jpayne@69 173 uplrules_selectFormatted(const UPluralRules *uplrules,
jpayne@69 174 const struct UFormattedNumber* number,
jpayne@69 175 UChar *keyword, int32_t capacity,
jpayne@69 176 UErrorCode *status);
jpayne@69 177
jpayne@69 178 #ifndef U_HIDE_INTERNAL_API
jpayne@69 179 /**
jpayne@69 180 * Given a number, returns the keyword of the first rule that applies to the
jpayne@69 181 * number, according to the UPluralRules object and given the number format
jpayne@69 182 * specified by the UNumberFormat object.
jpayne@69 183 * Note: This internal preview interface may be removed in the future if
jpayne@69 184 * an architecturally cleaner solution reaches stable status.
jpayne@69 185 * @param uplrules The UPluralRules object specifying the rules.
jpayne@69 186 * @param number The number for which the rule has to be determined.
jpayne@69 187 * @param fmt The UNumberFormat specifying how the number will be formatted
jpayne@69 188 * (this can affect the plural form, e.g. "1 dollar" vs "1.0 dollars").
jpayne@69 189 * If this is NULL, the function behaves like uplrules_select.
jpayne@69 190 * @param keyword An output buffer to write the keyword of the rule that
jpayne@69 191 * applies to number.
jpayne@69 192 * @param capacity The capacity of the keyword buffer.
jpayne@69 193 * @param status A pointer to a UErrorCode to receive any errors.
jpayne@69 194 * @return The length of keyword.
jpayne@69 195 * @internal ICU 59 technology preview, may be removed in the future
jpayne@69 196 */
jpayne@69 197 U_INTERNAL int32_t U_EXPORT2
jpayne@69 198 uplrules_selectWithFormat(const UPluralRules *uplrules,
jpayne@69 199 double number,
jpayne@69 200 const UNumberFormat *fmt,
jpayne@69 201 UChar *keyword, int32_t capacity,
jpayne@69 202 UErrorCode *status);
jpayne@69 203
jpayne@69 204 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 205
jpayne@69 206 /**
jpayne@69 207 * Creates a string enumeration of all plural rule keywords used in this
jpayne@69 208 * UPluralRules object. The rule "other" is always present by default.
jpayne@69 209 * @param uplrules The UPluralRules object specifying the rules for
jpayne@69 210 * a given locale.
jpayne@69 211 * @param status A pointer to a UErrorCode to receive any errors.
jpayne@69 212 * @return a string enumeration over plural rule keywords, or NULL
jpayne@69 213 * upon error. The caller is responsible for closing the result.
jpayne@69 214 * @stable ICU 59
jpayne@69 215 */
jpayne@69 216 U_STABLE UEnumeration* U_EXPORT2
jpayne@69 217 uplrules_getKeywords(const UPluralRules *uplrules,
jpayne@69 218 UErrorCode *status);
jpayne@69 219
jpayne@69 220 #endif /* #if !UCONFIG_NO_FORMATTING */
jpayne@69 221
jpayne@69 222 #endif