intl/icu/source/i18n/unicode/upluralrules.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 *****************************************************************************************
michael@0 3 * Copyright (C) 2010-2013, International Business Machines
michael@0 4 * Corporation and others. All Rights Reserved.
michael@0 5 *****************************************************************************************
michael@0 6 */
michael@0 7
michael@0 8 #ifndef UPLURALRULES_H
michael@0 9 #define UPLURALRULES_H
michael@0 10
michael@0 11 #include "unicode/utypes.h"
michael@0 12
michael@0 13 #if !UCONFIG_NO_FORMATTING
michael@0 14
michael@0 15 #include "unicode/localpointer.h"
michael@0 16
michael@0 17 /**
michael@0 18 * \file
michael@0 19 * \brief C API: Plural rules, select plural keywords for numeric values.
michael@0 20 *
michael@0 21 * A UPluralRules object defines rules for mapping non-negative numeric
michael@0 22 * values onto a small set of keywords. Rules are constructed from a text
michael@0 23 * description, consisting of a series of keywords and conditions.
michael@0 24 * The uplrules_select function examines each condition in order and
michael@0 25 * returns the keyword for the first condition that matches the number.
michael@0 26 * If none match, the default rule(other) is returned.
michael@0 27 *
michael@0 28 * For more information, see the LDML spec, C.11 Language Plural Rules:
michael@0 29 * http://www.unicode.org/reports/tr35/#Language_Plural_Rules
michael@0 30 *
michael@0 31 * Keywords: ICU locale data has 6 predefined values -
michael@0 32 * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check
michael@0 33 * the value of keyword returned by the uplrules_select function.
michael@0 34 *
michael@0 35 * These are based on CLDR <i>Language Plural Rules</i>. For these
michael@0 36 * predefined rules, see the CLDR page at
michael@0 37 * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
michael@0 38 */
michael@0 39
michael@0 40 /**
michael@0 41 * Type of plurals and PluralRules.
michael@0 42 * @stable ICU 50
michael@0 43 */
michael@0 44 enum UPluralType {
michael@0 45 /**
michael@0 46 * Plural rules for cardinal numbers: 1 file vs. 2 files.
michael@0 47 * @stable ICU 50
michael@0 48 */
michael@0 49 UPLURAL_TYPE_CARDINAL,
michael@0 50 /**
michael@0 51 * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
michael@0 52 * @stable ICU 50
michael@0 53 */
michael@0 54 UPLURAL_TYPE_ORDINAL,
michael@0 55 /**
michael@0 56 * Number of Plural rules types.
michael@0 57 * @stable ICU 50
michael@0 58 */
michael@0 59 UPLURAL_TYPE_COUNT
michael@0 60 };
michael@0 61 /**
michael@0 62 * @stable ICU 50
michael@0 63 */
michael@0 64 typedef enum UPluralType UPluralType;
michael@0 65
michael@0 66 /**
michael@0 67 * Opaque UPluralRules object for use in C programs.
michael@0 68 * @stable ICU 4.8
michael@0 69 */
michael@0 70 struct UPluralRules;
michael@0 71 typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
michael@0 72
michael@0 73 /**
michael@0 74 * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
michael@0 75 * given locale.
michael@0 76 * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).
michael@0 77 * @param locale The locale for which the rules are desired.
michael@0 78 * @param status A pointer to a UErrorCode to receive any errors.
michael@0 79 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
michael@0 80 * @stable ICU 4.8
michael@0 81 */
michael@0 82 U_STABLE UPluralRules* U_EXPORT2
michael@0 83 uplrules_open(const char *locale, UErrorCode *status);
michael@0 84
michael@0 85 /**
michael@0 86 * Opens a new UPluralRules object using the predefined plural rules for a
michael@0 87 * given locale and the plural type.
michael@0 88 * @param locale The locale for which the rules are desired.
michael@0 89 * @param type The plural type (e.g., cardinal or ordinal).
michael@0 90 * @param status A pointer to a UErrorCode to receive any errors.
michael@0 91 * @return A UPluralRules for the specified locale, or NULL if an error occurred.
michael@0 92 * @stable ICU 50
michael@0 93 */
michael@0 94 U_DRAFT UPluralRules* U_EXPORT2
michael@0 95 uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status);
michael@0 96
michael@0 97 /**
michael@0 98 * Closes a UPluralRules object. Once closed it may no longer be used.
michael@0 99 * @param uplrules The UPluralRules object to close.
michael@0 100 * @stable ICU 4.8
michael@0 101 */
michael@0 102 U_STABLE void U_EXPORT2
michael@0 103 uplrules_close(UPluralRules *uplrules);
michael@0 104
michael@0 105
michael@0 106 #if U_SHOW_CPLUSPLUS_API
michael@0 107
michael@0 108 U_NAMESPACE_BEGIN
michael@0 109
michael@0 110 /**
michael@0 111 * \class LocalUPluralRulesPointer
michael@0 112 * "Smart pointer" class, closes a UPluralRules via uplrules_close().
michael@0 113 * For most methods see the LocalPointerBase base class.
michael@0 114 *
michael@0 115 * @see LocalPointerBase
michael@0 116 * @see LocalPointer
michael@0 117 * @stable ICU 4.8
michael@0 118 */
michael@0 119 U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
michael@0 120
michael@0 121 U_NAMESPACE_END
michael@0 122
michael@0 123 #endif
michael@0 124
michael@0 125
michael@0 126 /**
michael@0 127 * Given a number, returns the keyword of the first rule that
michael@0 128 * applies to the number, according to the supplied UPluralRules object.
michael@0 129 * @param uplrules The UPluralRules object specifying the rules.
michael@0 130 * @param number The number for which the rule has to be determined.
michael@0 131 * @param keyword The keyword of the rule that applies to number.
michael@0 132 * @param capacity The capacity of keyword.
michael@0 133 * @param status A pointer to a UErrorCode to receive any errors.
michael@0 134 * @return The length of keyword.
michael@0 135 * @stable ICU 4.8
michael@0 136 */
michael@0 137 U_STABLE int32_t U_EXPORT2
michael@0 138 uplrules_select(const UPluralRules *uplrules,
michael@0 139 double number,
michael@0 140 UChar *keyword, int32_t capacity,
michael@0 141 UErrorCode *status);
michael@0 142
michael@0 143 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 144
michael@0 145 #endif

mercurial