1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/upluralrules.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,145 @@ 1.4 +/* 1.5 +***************************************************************************************** 1.6 +* Copyright (C) 2010-2013, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +***************************************************************************************** 1.9 +*/ 1.10 + 1.11 +#ifndef UPLURALRULES_H 1.12 +#define UPLURALRULES_H 1.13 + 1.14 +#include "unicode/utypes.h" 1.15 + 1.16 +#if !UCONFIG_NO_FORMATTING 1.17 + 1.18 +#include "unicode/localpointer.h" 1.19 + 1.20 +/** 1.21 + * \file 1.22 + * \brief C API: Plural rules, select plural keywords for numeric values. 1.23 + * 1.24 + * A UPluralRules object defines rules for mapping non-negative numeric 1.25 + * values onto a small set of keywords. Rules are constructed from a text 1.26 + * description, consisting of a series of keywords and conditions. 1.27 + * The uplrules_select function examines each condition in order and 1.28 + * returns the keyword for the first condition that matches the number. 1.29 + * If none match, the default rule(other) is returned. 1.30 + * 1.31 + * For more information, see the LDML spec, C.11 Language Plural Rules: 1.32 + * http://www.unicode.org/reports/tr35/#Language_Plural_Rules 1.33 + * 1.34 + * Keywords: ICU locale data has 6 predefined values - 1.35 + * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check 1.36 + * the value of keyword returned by the uplrules_select function. 1.37 + * 1.38 + * These are based on CLDR <i>Language Plural Rules</i>. For these 1.39 + * predefined rules, see the CLDR page at 1.40 + * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 1.41 + */ 1.42 + 1.43 +/** 1.44 + * Type of plurals and PluralRules. 1.45 + * @stable ICU 50 1.46 + */ 1.47 +enum UPluralType { 1.48 + /** 1.49 + * Plural rules for cardinal numbers: 1 file vs. 2 files. 1.50 + * @stable ICU 50 1.51 + */ 1.52 + UPLURAL_TYPE_CARDINAL, 1.53 + /** 1.54 + * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc. 1.55 + * @stable ICU 50 1.56 + */ 1.57 + UPLURAL_TYPE_ORDINAL, 1.58 + /** 1.59 + * Number of Plural rules types. 1.60 + * @stable ICU 50 1.61 + */ 1.62 + UPLURAL_TYPE_COUNT 1.63 +}; 1.64 +/** 1.65 + * @stable ICU 50 1.66 + */ 1.67 +typedef enum UPluralType UPluralType; 1.68 + 1.69 +/** 1.70 + * Opaque UPluralRules object for use in C programs. 1.71 + * @stable ICU 4.8 1.72 + */ 1.73 +struct UPluralRules; 1.74 +typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */ 1.75 + 1.76 +/** 1.77 + * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a 1.78 + * given locale. 1.79 + * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status). 1.80 + * @param locale The locale for which the rules are desired. 1.81 + * @param status A pointer to a UErrorCode to receive any errors. 1.82 + * @return A UPluralRules for the specified locale, or NULL if an error occurred. 1.83 + * @stable ICU 4.8 1.84 + */ 1.85 +U_STABLE UPluralRules* U_EXPORT2 1.86 +uplrules_open(const char *locale, UErrorCode *status); 1.87 + 1.88 +/** 1.89 + * Opens a new UPluralRules object using the predefined plural rules for a 1.90 + * given locale and the plural type. 1.91 + * @param locale The locale for which the rules are desired. 1.92 + * @param type The plural type (e.g., cardinal or ordinal). 1.93 + * @param status A pointer to a UErrorCode to receive any errors. 1.94 + * @return A UPluralRules for the specified locale, or NULL if an error occurred. 1.95 + * @stable ICU 50 1.96 + */ 1.97 +U_DRAFT UPluralRules* U_EXPORT2 1.98 +uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status); 1.99 + 1.100 +/** 1.101 + * Closes a UPluralRules object. Once closed it may no longer be used. 1.102 + * @param uplrules The UPluralRules object to close. 1.103 + * @stable ICU 4.8 1.104 + */ 1.105 +U_STABLE void U_EXPORT2 1.106 +uplrules_close(UPluralRules *uplrules); 1.107 + 1.108 + 1.109 +#if U_SHOW_CPLUSPLUS_API 1.110 + 1.111 +U_NAMESPACE_BEGIN 1.112 + 1.113 +/** 1.114 + * \class LocalUPluralRulesPointer 1.115 + * "Smart pointer" class, closes a UPluralRules via uplrules_close(). 1.116 + * For most methods see the LocalPointerBase base class. 1.117 + * 1.118 + * @see LocalPointerBase 1.119 + * @see LocalPointer 1.120 + * @stable ICU 4.8 1.121 + */ 1.122 +U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close); 1.123 + 1.124 +U_NAMESPACE_END 1.125 + 1.126 +#endif 1.127 + 1.128 + 1.129 +/** 1.130 + * Given a number, returns the keyword of the first rule that 1.131 + * applies to the number, according to the supplied UPluralRules object. 1.132 + * @param uplrules The UPluralRules object specifying the rules. 1.133 + * @param number The number for which the rule has to be determined. 1.134 + * @param keyword The keyword of the rule that applies to number. 1.135 + * @param capacity The capacity of keyword. 1.136 + * @param status A pointer to a UErrorCode to receive any errors. 1.137 + * @return The length of keyword. 1.138 + * @stable ICU 4.8 1.139 + */ 1.140 +U_STABLE int32_t U_EXPORT2 1.141 +uplrules_select(const UPluralRules *uplrules, 1.142 + double number, 1.143 + UChar *keyword, int32_t capacity, 1.144 + UErrorCode *status); 1.145 + 1.146 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.147 + 1.148 +#endif