jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ***************************************************************************************** jpayne@69: * Copyright (C) 2010-2013, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ***************************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef UPLURALRULES_H jpayne@69: #define UPLURALRULES_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/localpointer.h" jpayne@69: #include "unicode/uenum.h" jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: #include "unicode/unum.h" jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: // Forward-declaration jpayne@69: struct UFormattedNumber; jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Plural rules, select plural keywords for numeric values. jpayne@69: * jpayne@69: * A UPluralRules object defines rules for mapping non-negative numeric jpayne@69: * values onto a small set of keywords. Rules are constructed from a text jpayne@69: * description, consisting of a series of keywords and conditions. jpayne@69: * The uplrules_select function examines each condition in order and jpayne@69: * returns the keyword for the first condition that matches the number. jpayne@69: * If none match, the default rule(other) is returned. jpayne@69: * jpayne@69: * For more information, see the LDML spec, C.11 Language Plural Rules: jpayne@69: * http://www.unicode.org/reports/tr35/#Language_Plural_Rules jpayne@69: * jpayne@69: * Keywords: ICU locale data has 6 predefined values - jpayne@69: * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check jpayne@69: * the value of keyword returned by the uplrules_select function. jpayne@69: * jpayne@69: * These are based on CLDR Language Plural Rules. For these jpayne@69: * predefined rules, see the CLDR page at jpayne@69: * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * Type of plurals and PluralRules. jpayne@69: * @stable ICU 50 jpayne@69: */ jpayne@69: enum UPluralType { jpayne@69: /** jpayne@69: * Plural rules for cardinal numbers: 1 file vs. 2 files. jpayne@69: * @stable ICU 50 jpayne@69: */ jpayne@69: UPLURAL_TYPE_CARDINAL, jpayne@69: /** jpayne@69: * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc. jpayne@69: * @stable ICU 50 jpayne@69: */ jpayne@69: UPLURAL_TYPE_ORDINAL, jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * One more than the highest normal UPluralType value. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UPLURAL_TYPE_COUNT jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: }; jpayne@69: /** jpayne@69: * @stable ICU 50 jpayne@69: */ jpayne@69: typedef enum UPluralType UPluralType; jpayne@69: jpayne@69: /** jpayne@69: * Opaque UPluralRules object for use in C programs. jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: struct UPluralRules; jpayne@69: typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */ jpayne@69: jpayne@69: /** jpayne@69: * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a jpayne@69: * given locale. jpayne@69: * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status). jpayne@69: * @param locale The locale for which the rules are desired. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return A UPluralRules for the specified locale, or NULL if an error occurred. jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: U_CAPI UPluralRules* U_EXPORT2 jpayne@69: uplrules_open(const char *locale, UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Opens a new UPluralRules object using the predefined plural rules for a jpayne@69: * given locale and the plural type. jpayne@69: * @param locale The locale for which the rules are desired. jpayne@69: * @param type The plural type (e.g., cardinal or ordinal). jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return A UPluralRules for the specified locale, or NULL if an error occurred. jpayne@69: * @stable ICU 50 jpayne@69: */ jpayne@69: U_CAPI UPluralRules* U_EXPORT2 jpayne@69: uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Closes a UPluralRules object. Once closed it may no longer be used. jpayne@69: * @param uplrules The UPluralRules object to close. jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: U_CAPI void U_EXPORT2 jpayne@69: uplrules_close(UPluralRules *uplrules); jpayne@69: jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \class LocalUPluralRulesPointer jpayne@69: * "Smart pointer" class, closes a UPluralRules via uplrules_close(). jpayne@69: * For most methods see the LocalPointerBase base class. jpayne@69: * jpayne@69: * @see LocalPointerBase jpayne@69: * @see LocalPointer jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close); jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Given a floating-point number, returns the keyword of the first rule that jpayne@69: * applies to the number, according to the supplied UPluralRules object. jpayne@69: * @param uplrules The UPluralRules object specifying the rules. jpayne@69: * @param number The number for which the rule has to be determined. jpayne@69: * @param keyword An output buffer to write the keyword of the rule that jpayne@69: * applies to number. jpayne@69: * @param capacity The capacity of the keyword buffer. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return The length of the keyword. jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: U_CAPI int32_t U_EXPORT2 jpayne@69: uplrules_select(const UPluralRules *uplrules, jpayne@69: double number, jpayne@69: UChar *keyword, int32_t capacity, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Given a formatted number, returns the keyword of the first rule jpayne@69: * that applies to the number, according to the supplied UPluralRules object. jpayne@69: * jpayne@69: * A UFormattedNumber allows you to specify an exponent or trailing zeros, jpayne@69: * which can affect the plural category. To get a UFormattedNumber, see jpayne@69: * {@link UNumberFormatter}. jpayne@69: * jpayne@69: * @param uplrules The UPluralRules object specifying the rules. jpayne@69: * @param number The formatted number for which the rule has to be determined. jpayne@69: * @param keyword The destination buffer for the keyword of the rule that jpayne@69: * applies to number. jpayne@69: * @param capacity The capacity of the keyword buffer. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return The length of the keyword. jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: U_CAPI int32_t U_EXPORT2 jpayne@69: uplrules_selectFormatted(const UPluralRules *uplrules, jpayne@69: const struct UFormattedNumber* number, jpayne@69: UChar *keyword, int32_t capacity, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Given a number, returns the keyword of the first rule that applies to the jpayne@69: * number, according to the UPluralRules object and given the number format jpayne@69: * specified by the UNumberFormat object. jpayne@69: * Note: This internal preview interface may be removed in the future if jpayne@69: * an architecturally cleaner solution reaches stable status. jpayne@69: * @param uplrules The UPluralRules object specifying the rules. jpayne@69: * @param number The number for which the rule has to be determined. jpayne@69: * @param fmt The UNumberFormat specifying how the number will be formatted jpayne@69: * (this can affect the plural form, e.g. "1 dollar" vs "1.0 dollars"). jpayne@69: * If this is NULL, the function behaves like uplrules_select. jpayne@69: * @param keyword An output buffer to write the keyword of the rule that jpayne@69: * applies to number. jpayne@69: * @param capacity The capacity of the keyword buffer. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return The length of keyword. jpayne@69: * @internal ICU 59 technology preview, may be removed in the future jpayne@69: */ jpayne@69: U_INTERNAL int32_t U_EXPORT2 jpayne@69: uplrules_selectWithFormat(const UPluralRules *uplrules, jpayne@69: double number, jpayne@69: const UNumberFormat *fmt, jpayne@69: UChar *keyword, int32_t capacity, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Creates a string enumeration of all plural rule keywords used in this jpayne@69: * UPluralRules object. The rule "other" is always present by default. jpayne@69: * @param uplrules The UPluralRules object specifying the rules for jpayne@69: * a given locale. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return a string enumeration over plural rule keywords, or NULL jpayne@69: * upon error. The caller is responsible for closing the result. jpayne@69: * @stable ICU 59 jpayne@69: */ jpayne@69: U_STABLE UEnumeration* U_EXPORT2 jpayne@69: uplrules_getKeywords(const UPluralRules *uplrules, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif