Home | History | Annotate | Download | only in unicode
      1 /*
      2 *****************************************************************************************
      3 * Copyright (C) 2010-2011, International Business Machines
      4 * Corporation and others. All Rights Reserved.
      5 *****************************************************************************************
      6 */
      7 
      8 #ifndef UPLURALRULES_H
      9 #define UPLURALRULES_H
     10 
     11 #include "unicode/utypes.h"
     12 
     13 #if !UCONFIG_NO_FORMATTING
     14 
     15 #include "unicode/localpointer.h"
     16 
     17 /**
     18  * A UPluralRules object defines rules for mapping non-negative numeric
     19  * values onto a small set of keywords. Rules are constructed from a text
     20  * description, consisting of a series of keywords and conditions.
     21  * The uplrules_select function examines each condition in order and
     22  * returns the keyword for the first condition that matches the number.
     23  * If none match, the default rule(other) is returned.
     24  *
     25  * For more information, see the LDML spec, C.11 Language Plural Rules:
     26  * http://www.unicode.org/reports/tr35/#Language_Plural_Rules
     27  *
     28  * Keywords: ICU locale data has 6 predefined values -
     29  * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check
     30  * the value of keyword returned by the uplrules_select function.
     31  *
     32  * These are based on CLDR <i>Language Plural Rules</i>. For these
     33  * predefined rules, see the CLDR page at
     34  * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
     35  */
     36 
     37 /**
     38  * Opaque UPluralRules object for use in C programs.
     39  * @draft ICU 4.8
     40  */
     41 struct UPluralRules;
     42 typedef struct UPluralRules UPluralRules;  /**< C typedef for struct UPluralRules. @draft ICU 4.8 */
     43 
     44 /**
     45  * Open a new UPluralRules object using the predefined plural rules for a
     46  * given locale.
     47  * @param locale The locale for which the rules are desired.
     48  * @param status A pointer to a UErrorCode to receive any errors.
     49  * @return A UPluralRules for the specified locale, or 0 if an error occurred.
     50  * @draft ICU 4.8
     51  */
     52 U_DRAFT UPluralRules* U_EXPORT2
     53 uplrules_open(const char *locale,
     54              UErrorCode *status);
     55 
     56 /**
     57  * Close a UPluralRules object. Once closed it may no longer be used.
     58  * @param uplrules The UPluralRules object to close.
     59  * @draft ICU 4.8
     60  */
     61 U_DRAFT void U_EXPORT2
     62 uplrules_close(UPluralRules *uplrules);
     63 
     64 
     65 #if U_SHOW_CPLUSPLUS_API
     66 
     67 U_NAMESPACE_BEGIN
     68 
     69 /**
     70  * \class LocalUPluralRulesPointer
     71  * "Smart pointer" class, closes a UPluralRules via uplrules_close().
     72  * For most methods see the LocalPointerBase base class.
     73  *
     74  * @see LocalPointerBase
     75  * @see LocalPointer
     76  * @draft ICU 4.8
     77  */
     78 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
     79 
     80 U_NAMESPACE_END
     81 
     82 #endif
     83 
     84 
     85 /**
     86  * Given a number, returns the keyword of the first rule that
     87  * applies to the number, according to the supplied UPluralRules object.
     88  * @param uplrules The UPluralRules object specifying the rules.
     89  * @param number The number for which the rule has to be determined.
     90  * @param keyword The keyword of the rule that applies to number.
     91  * @param capacity The capacity of keyword.
     92  * @param status A pointer to a UErrorCode to receive any errors.
     93  * @return The length of keyword.
     94  * @draft ICU 4.8
     95  */
     96 U_DRAFT int32_t U_EXPORT2
     97 uplrules_select(const UPluralRules *uplrules,
     98                double number,
     99                UChar *keyword, int32_t capacity,
    100                UErrorCode *status);
    101 
    102 #endif /* #if !UCONFIG_NO_FORMATTING */
    103 
    104 #endif
    105