// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * Copyright (C) 2008-2015, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* * * * File PLURRULE.H * * Modification History:* * Date Name Description * ******************************************************************************** */ #ifndef PLURRULE #define PLURRULE #include "unicode/utypes.h" #if U_SHOW_CPLUSPLUS_API /** * \file * \brief C++ API: PluralRules object */ #if !UCONFIG_NO_FORMATTING #include "unicode/format.h" #include "unicode/upluralrules.h" #ifndef U_HIDE_INTERNAL_API #include "unicode/numfmt.h" #endif /* U_HIDE_INTERNAL_API */ /** * Value returned by PluralRules::getUniqueKeywordValue() when there is no * unique value to return. * @stable ICU 4.8 */ #define UPLRULES_NO_UNIQUE_VALUE … U_NAMESPACE_BEGIN class Hashtable; class IFixedDecimal; class FixedDecimal; class RuleChain; class PluralRuleParser; class PluralKeywordEnumeration; class AndConstraint; class SharedPluralRules; class StandardPluralRanges; namespace number { class FormattedNumber; class FormattedNumberRange; namespace impl { class UFormattedNumberRangeData; class DecimalQuantity; class DecNum; } } #ifndef U_HIDE_INTERNAL_API DecimalQuantity; #endif /* U_HIDE_INTERNAL_API */ /** * Defines rules for mapping non-negative numeric values onto a small set of * keywords. Rules are constructed from a text description, consisting * of a series of keywords and conditions. The {@link #select} method * examines each condition in order and returns the keyword for the * first condition that matches the number. If none match, * default rule(other) is returned. * * For more information, details, and tips for writing rules, see the * LDML spec, Part 3.5 Language Plural Rules: * https://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules * * Examples:<pre> * "one: n is 1; few: n in 2..4"</pre> * This defines two rules, for 'one' and 'few'. The condition for * 'one' is "n is 1" which means that the number must be equal to * 1 for this condition to pass. The condition for 'few' is * "n in 2..4" which means that the number must be between 2 and * 4 inclusive for this condition to pass. All other numbers * are assigned the keyword "other" by the default rule. * </p><pre> * "zero: n is 0; one: n is 1; zero: n mod 100 in 1..19"</pre> * This illustrates that the same keyword can be defined multiple times. * Each rule is examined in order, and the first keyword whose condition * passes is the one returned. Also notes that a modulus is applied * to n in the last rule. Thus its condition holds for 119, 219, 319... * </p><pre> * "one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14"</pre> * This illustrates conjunction and negation. The condition for 'few' * has two parts, both of which must be met: "n mod 10 in 2..4" and * "n mod 100 not in 12..14". The first part applies a modulus to n * before the test as in the previous example. The second part applies * a different modulus and also uses negation, thus it matches all * numbers _not_ in 12, 13, 14, 112, 113, 114, 212, 213, 214... * </p> * <p> * Syntax:<pre> * \code * rules = rule (';' rule)* * rule = keyword ':' condition * keyword = <identifier> * condition = and_condition ('or' and_condition)* * and_condition = relation ('and' relation)* * relation = is_relation | in_relation | within_relation | 'n' <EOL> * is_relation = expr 'is' ('not')? value * in_relation = expr ('not')? 'in' range_list * within_relation = expr ('not')? 'within' range * expr = ('n' | 'i' | 'f' | 'v' | 'j') ('mod' value)? * range_list = (range | value) (',' range_list)* * value = digit+ ('.' digit+)? * digit = 0|1|2|3|4|5|6|7|8|9 * range = value'..'value * \endcode * </pre></p> * <p> * <p> * The i, f, and v values are defined as follows: * </p> * <ul> * <li>i to be the integer digits.</li> * <li>f to be the visible fractional digits, as an integer.</li> * <li>v to be the number of visible fraction digits.</li> * <li>j is defined to only match integers. That is j is 3 fails if v != 0 (eg for 3.1 or 3.0).</li> * </ul> * <p> * Examples are in the following table: * </p> * <table border='1' style="border-collapse:collapse"> * <tr> * <th>n</th> * <th>i</th> * <th>f</th> * <th>v</th> * </tr> * <tr> * <td>1.0</td> * <td>1</td> * <td align="right">0</td> * <td>1</td> * </tr> * <tr> * <td>1.00</td> * <td>1</td> * <td align="right">0</td> * <td>2</td> * </tr> * <tr> * <td>1.3</td> * <td>1</td> * <td align="right">3</td> * <td>1</td> * </tr> * <tr> * <td>1.03</td> * <td>1</td> * <td align="right">3</td> * <td>2</td> * </tr> * <tr> * <td>1.23</td> * <td>1</td> * <td align="right">23</td> * <td>2</td> * </tr> * </table> * <p> * The difference between 'in' and 'within' is that 'in' only includes integers in the specified range, while 'within' * includes all values. Using 'within' with a range_list consisting entirely of values is the same as using 'in' (it's * not an error). * </p> * An "identifier" is a sequence of characters that do not have the * Unicode Pattern_Syntax or Pattern_White_Space properties. * <p> * The difference between 'in' and 'within' is that 'in' only includes * integers in the specified range, while 'within' includes all values. * Using 'within' with a range_list consisting entirely of values is the * same as using 'in' (it's not an error). *</p> * <p> * Keywords * could be defined by users or from ICU locale data. There are 6 * predefined values in ICU - 'zero', 'one', 'two', 'few', 'many' and * 'other'. Callers need to check the value of keyword returned by * {@link #select} method. * </p> * * Examples:<pre> * UnicodeString keyword = pl->select(number); * if (keyword== UnicodeString("one") { * ... * } * else if ( ... ) * </pre> * <strong>Note:</strong><br> * <p> * ICU defines plural rules for many locales based on CLDR <i>Language Plural Rules</i>. * For these predefined rules, see CLDR page at * https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/language_plural_rules.html * </p> */ class U_I18N_API PluralRules : public UObject { … }; U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ #endif /* U_SHOW_CPLUSPLUS_API */ #endif // _PLURRULE //eof