michael@0: /* michael@0: ***************************************************************************************** michael@0: * Copyright (C) 2010-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ***************************************************************************************** michael@0: */ michael@0: michael@0: #ifndef UPLURALRULES_H michael@0: #define UPLURALRULES_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/localpointer.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Plural rules, select plural keywords for numeric values. michael@0: * michael@0: * A UPluralRules object defines rules for mapping non-negative numeric michael@0: * values onto a small set of keywords. Rules are constructed from a text michael@0: * description, consisting of a series of keywords and conditions. michael@0: * The uplrules_select function examines each condition in order and michael@0: * returns the keyword for the first condition that matches the number. michael@0: * If none match, the default rule(other) is returned. michael@0: * michael@0: * For more information, see the LDML spec, C.11 Language Plural Rules: michael@0: * http://www.unicode.org/reports/tr35/#Language_Plural_Rules michael@0: * michael@0: * Keywords: ICU locale data has 6 predefined values - michael@0: * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check michael@0: * the value of keyword returned by the uplrules_select function. michael@0: * michael@0: * These are based on CLDR Language Plural Rules. For these michael@0: * predefined rules, see the CLDR page at michael@0: * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html michael@0: */ michael@0: michael@0: /** michael@0: * Type of plurals and PluralRules. michael@0: * @stable ICU 50 michael@0: */ michael@0: enum UPluralType { michael@0: /** michael@0: * Plural rules for cardinal numbers: 1 file vs. 2 files. michael@0: * @stable ICU 50 michael@0: */ michael@0: UPLURAL_TYPE_CARDINAL, michael@0: /** michael@0: * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc. michael@0: * @stable ICU 50 michael@0: */ michael@0: UPLURAL_TYPE_ORDINAL, michael@0: /** michael@0: * Number of Plural rules types. michael@0: * @stable ICU 50 michael@0: */ michael@0: UPLURAL_TYPE_COUNT michael@0: }; michael@0: /** michael@0: * @stable ICU 50 michael@0: */ michael@0: typedef enum UPluralType UPluralType; michael@0: michael@0: /** michael@0: * Opaque UPluralRules object for use in C programs. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: struct UPluralRules; michael@0: typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */ michael@0: michael@0: /** michael@0: * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a michael@0: * given locale. michael@0: * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status). michael@0: * @param locale The locale for which the rules are desired. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return A UPluralRules for the specified locale, or NULL if an error occurred. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE UPluralRules* U_EXPORT2 michael@0: uplrules_open(const char *locale, UErrorCode *status); michael@0: michael@0: /** michael@0: * Opens a new UPluralRules object using the predefined plural rules for a michael@0: * given locale and the plural type. michael@0: * @param locale The locale for which the rules are desired. michael@0: * @param type The plural type (e.g., cardinal or ordinal). michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return A UPluralRules for the specified locale, or NULL if an error occurred. michael@0: * @stable ICU 50 michael@0: */ michael@0: U_DRAFT UPluralRules* U_EXPORT2 michael@0: uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status); michael@0: michael@0: /** michael@0: * Closes a UPluralRules object. Once closed it may no longer be used. michael@0: * @param uplrules The UPluralRules object to close. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uplrules_close(UPluralRules *uplrules); michael@0: michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalUPluralRulesPointer michael@0: * "Smart pointer" class, closes a UPluralRules via uplrules_close(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: michael@0: /** michael@0: * Given a number, returns the keyword of the first rule that michael@0: * applies to the number, according to the supplied UPluralRules object. michael@0: * @param uplrules The UPluralRules object specifying the rules. michael@0: * @param number The number for which the rule has to be determined. michael@0: * @param keyword The keyword of the rule that applies to number. michael@0: * @param capacity The capacity of keyword. michael@0: * @param status A pointer to a UErrorCode to receive any errors. michael@0: * @return The length of keyword. michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uplrules_select(const UPluralRules *uplrules, michael@0: double number, michael@0: UChar *keyword, int32_t capacity, michael@0: UErrorCode *status); michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif