jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * Copyright (C) 2007-2014, International Business Machines Corporation and jpayne@69: * others. All Rights Reserved. jpayne@69: ******************************************************************************* jpayne@69: * jpayne@69: jpayne@69: * File PLURFMT.H jpayne@69: ******************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef PLURFMT jpayne@69: #define PLURFMT jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: PluralFormat object jpayne@69: */ jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/messagepattern.h" jpayne@69: #include "unicode/numfmt.h" jpayne@69: #include "unicode/plurrule.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class Hashtable; jpayne@69: class NFRule; jpayne@69: jpayne@69: /** jpayne@69: *

jpayne@69: * PluralFormat supports the creation of internationalized jpayne@69: * messages with plural inflection. It is based on plural jpayne@69: * selection, i.e. the caller specifies messages for each jpayne@69: * plural case that can appear in the user's language and the jpayne@69: * PluralFormat selects the appropriate message based on jpayne@69: * the number. jpayne@69: *

jpayne@69: *

The Problem of Plural Forms in Internationalized Messages

jpayne@69: *

jpayne@69: * Different languages have different ways to inflect jpayne@69: * plurals. Creating internationalized messages that include plural jpayne@69: * forms is only feasible when the framework is able to handle plural jpayne@69: * forms of all languages correctly. ChoiceFormat jpayne@69: * doesn't handle this well, because it attaches a number interval to jpayne@69: * each message and selects the message whose interval contains a jpayne@69: * given number. This can only handle a finite number of jpayne@69: * intervals. But in some languages, like Polish, one plural case jpayne@69: * applies to infinitely many intervals (e.g., the plural case applies to jpayne@69: * numbers ending with 2, 3, or 4 except those ending with 12, 13, or jpayne@69: * 14). Thus ChoiceFormat is not adequate. jpayne@69: *

jpayne@69: * PluralFormat deals with this by breaking the problem jpayne@69: * into two parts: jpayne@69: *

jpayne@69: *

jpayne@69: *

Usage of PluralFormat

jpayne@69: *

Note: Typically, plural formatting is done via MessageFormat jpayne@69: * with a plural argument type, jpayne@69: * rather than using a stand-alone PluralFormat. jpayne@69: *

jpayne@69: * This discussion assumes that you use PluralFormat with jpayne@69: * a predefined set of plural rules. You can create one using one of jpayne@69: * the constructors that takes a locale object. To jpayne@69: * specify the message pattern, you can either pass it to the jpayne@69: * constructor or set it explicitly using the jpayne@69: * applyPattern() method. The format() jpayne@69: * method takes a number object and selects the message of the jpayne@69: * matching plural case. This message will be returned. jpayne@69: *

jpayne@69: *
Patterns and Their Interpretation
jpayne@69: *

jpayne@69: * The pattern text defines the message output for each plural case of the jpayne@69: * specified locale. Syntax: jpayne@69: *

jpayne@69:  * pluralStyle = [offsetValue] (selector '{' message '}')+
jpayne@69:  * offsetValue = "offset:" number
jpayne@69:  * selector = explicitValue | keyword
jpayne@69:  * explicitValue = '=' number  // adjacent, no white space in between
jpayne@69:  * keyword = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
jpayne@69:  * message: see {@link MessageFormat}
jpayne@69:  * 
jpayne@69: * Pattern_White_Space between syntax elements is ignored, except jpayne@69: * between the {curly braces} and their sub-message, jpayne@69: * and between the '=' and the number of an explicitValue. jpayne@69: * jpayne@69: *

jpayne@69: * There are 6 predefined casekeyword in CLDR/ICU - 'zero', 'one', 'two', 'few', 'many' and jpayne@69: * 'other'. You always have to define a message text for the default plural case jpayne@69: * other which is contained in every rule set. jpayne@69: * If you do not specify a message text for a particular plural case, the jpayne@69: * message text of the plural case other gets assigned to this jpayne@69: * plural case. jpayne@69: *

jpayne@69: * When formatting, the input number is first matched against the explicitValue clauses. jpayne@69: * If there is no exact-number match, then a keyword is selected by calling jpayne@69: * the PluralRules with the input number minus the offset. jpayne@69: * (The offset defaults to 0 if it is omitted from the pattern string.) jpayne@69: * If there is no clause with that keyword, then the "other" clauses is returned. jpayne@69: *

jpayne@69: * An unquoted pound sign (#) in the selected sub-message jpayne@69: * itself (i.e., outside of arguments nested in the sub-message) jpayne@69: * is replaced by the input number minus the offset. jpayne@69: * The number-minus-offset value is formatted using a jpayne@69: * NumberFormat for the PluralFormat's locale. If you jpayne@69: * need special number formatting, you have to use a MessageFormat jpayne@69: * and explicitly specify a NumberFormat argument. jpayne@69: * Note: That argument is formatting without subtracting the offset! jpayne@69: * If you need a custom format and have a non-zero offset, then you need to pass the jpayne@69: * number-minus-offset value as a separate parameter. jpayne@69: *

jpayne@69: * For a usage example, see the {@link MessageFormat} class documentation. jpayne@69: * jpayne@69: *

Defining Custom Plural Rules

jpayne@69: *

If you need to use PluralFormat with custom rules, you can jpayne@69: * create a PluralRules object and pass it to jpayne@69: * PluralFormat's constructor. If you also specify a locale in this jpayne@69: * constructor, this locale will be used to format the number in the message jpayne@69: * texts. jpayne@69: *

jpayne@69: * For more information about PluralRules, see jpayne@69: * {@link PluralRules}. jpayne@69: *

jpayne@69: * jpayne@69: * ported from Java jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: jpayne@69: class U_I18N_API PluralFormat : public Format { jpayne@69: public: jpayne@69: jpayne@69: /** jpayne@69: * Creates a new cardinal-number PluralFormat for the default locale. jpayne@69: * This locale will be used to get the set of plural rules and for standard jpayne@69: * number formatting. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new cardinal-number PluralFormat for a given locale. jpayne@69: * @param locale the PluralFormat will be configured with jpayne@69: * rules for this locale. This locale will also be used for jpayne@69: * standard number formatting. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(const Locale& locale, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new PluralFormat for a given set of rules. jpayne@69: * The standard number formatting will be done using the default locale. jpayne@69: * @param rules defines the behavior of the PluralFormat jpayne@69: * object. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(const PluralRules& rules, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new PluralFormat for a given set of rules. jpayne@69: * The standard number formatting will be done using the given locale. jpayne@69: * @param locale the default number formatting will be done using this jpayne@69: * locale. jpayne@69: * @param rules defines the behavior of the PluralFormat jpayne@69: * object. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: *

jpayne@69: *

Sample code

jpayne@69: * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample1 jpayne@69: * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample jpayne@69: *

jpayne@69: */ jpayne@69: PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new PluralFormat for the plural type. jpayne@69: * The standard number formatting will be done using the given locale. jpayne@69: * @param locale the default number formatting will be done using this jpayne@69: * locale. jpayne@69: * @param type The plural type (e.g., cardinal or ordinal). jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 50 jpayne@69: */ jpayne@69: PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new cardinal-number PluralFormat for a given pattern string. jpayne@69: * The default locale will be used to get the set of plural rules and for jpayne@69: * standard number formatting. jpayne@69: * @param pattern the pattern for this PluralFormat. jpayne@69: * errors are returned to status if the pattern is invalid. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new cardinal-number PluralFormat for a given pattern string and jpayne@69: * locale. jpayne@69: * The locale will be used to get the set of plural rules and for jpayne@69: * standard number formatting. jpayne@69: * @param locale the PluralFormat will be configured with jpayne@69: * rules for this locale. This locale will also be used for jpayne@69: * standard number formatting. jpayne@69: * @param pattern the pattern for this PluralFormat. jpayne@69: * errors are returned to status if the pattern is invalid. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new PluralFormat for a given set of rules, a jpayne@69: * pattern and a locale. jpayne@69: * @param rules defines the behavior of the PluralFormat jpayne@69: * object. jpayne@69: * @param pattern the pattern for this PluralFormat. jpayne@69: * errors are returned to status if the pattern is invalid. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(const PluralRules& rules, jpayne@69: const UnicodeString& pattern, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new PluralFormat for a given set of rules, a jpayne@69: * pattern and a locale. jpayne@69: * @param locale the PluralFormat will be configured with jpayne@69: * rules for this locale. This locale will also be used for jpayne@69: * standard number formatting. jpayne@69: * @param rules defines the behavior of the PluralFormat jpayne@69: * object. jpayne@69: * @param pattern the pattern for this PluralFormat. jpayne@69: * errors are returned to status if the pattern is invalid. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(const Locale& locale, jpayne@69: const PluralRules& rules, jpayne@69: const UnicodeString& pattern, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a new PluralFormat for a plural type, a jpayne@69: * pattern and a locale. jpayne@69: * @param locale the PluralFormat will be configured with jpayne@69: * rules for this locale. This locale will also be used for jpayne@69: * standard number formatting. jpayne@69: * @param type The plural type (e.g., cardinal or ordinal). jpayne@69: * @param pattern the pattern for this PluralFormat. jpayne@69: * errors are returned to status if the pattern is invalid. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 50 jpayne@69: */ jpayne@69: PluralFormat(const Locale& locale, jpayne@69: UPluralType type, jpayne@69: const UnicodeString& pattern, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * copy constructor. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat(const PluralFormat& other); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual ~PluralFormat(); jpayne@69: jpayne@69: /** jpayne@69: * Sets the pattern used by this plural format. jpayne@69: * The method parses the pattern and creates a map of format strings jpayne@69: * for the plural rules. jpayne@69: * Patterns and their interpretation are specified in the class description. jpayne@69: * jpayne@69: * @param pattern the pattern for this plural format jpayne@69: * errors are returned to status if the pattern is invalid. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: void applyPattern(const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: jpayne@69: using Format::format; jpayne@69: jpayne@69: /** jpayne@69: * Formats a plural message for a given number. jpayne@69: * jpayne@69: * @param number a number for which the plural message should be formatted jpayne@69: * for. If no pattern has been applied to this jpayne@69: * PluralFormat object yet, the formatted number jpayne@69: * will be returned. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @return the string containing the formatted plural message. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UnicodeString format(int32_t number, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Formats a plural message for a given number. jpayne@69: * jpayne@69: * @param number a number for which the plural message should be formatted jpayne@69: * for. If no pattern has been applied to this jpayne@69: * PluralFormat object yet, the formatted number jpayne@69: * will be returned. jpayne@69: * @param status output param set to success or failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @return the string containing the formatted plural message. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UnicodeString format(double number, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Formats a plural message for a given number. jpayne@69: * jpayne@69: * @param number a number for which the plural message should be formatted jpayne@69: * for. If no pattern has been applied to this jpayne@69: * PluralFormat object yet, the formatted number jpayne@69: * will be returned. jpayne@69: * @param appendTo output parameter to receive result. jpayne@69: * result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @return the string containing the formatted plural message. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UnicodeString& format(int32_t number, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition& pos, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Formats a plural message for a given number. jpayne@69: * jpayne@69: * @param number a number for which the plural message should be formatted jpayne@69: * for. If no pattern has been applied to this jpayne@69: * PluralFormat object yet, the formatted number jpayne@69: * will be returned. jpayne@69: * @param appendTo output parameter to receive result. jpayne@69: * result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @return the string containing the formatted plural message. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UnicodeString& format(double number, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition& pos, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Sets the locale used by this PluraFormat object. jpayne@69: * Note: Calling this method resets this PluraFormat object, jpayne@69: * i.e., a pattern that was applied previously will be removed, jpayne@69: * and the NumberFormat is set to the default number format for jpayne@69: * the locale. The resulting format behaves the same as one jpayne@69: * constructed from {@link #PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status)} jpayne@69: * with UPLURAL_TYPE_CARDINAL. jpayne@69: * @param locale the locale to use to configure the formatter. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @deprecated ICU 50 This method clears the pattern and might create jpayne@69: * a different kind of PluralRules instance; jpayne@69: * use one of the constructors to create a new instance instead. jpayne@69: */ jpayne@69: void setLocale(const Locale& locale, UErrorCode& status); jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Sets the number format used by this formatter. You only need to jpayne@69: * call this if you want a different number format than the default jpayne@69: * formatter for the locale. jpayne@69: * @param format the number format to use. jpayne@69: * @param status output param set to success/failure code on exit, which jpayne@69: * must not indicate a failure before the function call. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: void setNumberFormat(const NumberFormat* format, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator jpayne@69: * jpayne@69: * @param other the PluralFormat object to copy from. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: PluralFormat& operator=(const PluralFormat& other); jpayne@69: jpayne@69: /** jpayne@69: * Return true if another object is semantically equal to this one. jpayne@69: * jpayne@69: * @param other the PluralFormat object to be compared with. jpayne@69: * @return true if other is semantically equal to this. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual UBool operator==(const Format& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if another object is semantically unequal to this one. jpayne@69: * jpayne@69: * @param other the PluralFormat object to be compared with. jpayne@69: * @return true if other is semantically unequal to this. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual UBool operator!=(const Format& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Clones this Format object polymorphically. The caller owns the jpayne@69: * result and should delete it when done. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual PluralFormat* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Formats a plural message for a number taken from a Formattable object. jpayne@69: * jpayne@69: * @param obj The object containing a number for which the jpayne@69: * plural message should be formatted. jpayne@69: * The object must be of a numeric type. jpayne@69: * @param appendTo output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @param status output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UnicodeString& format(const Formattable& obj, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition& pos, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the pattern from applyPattern() or constructor(). jpayne@69: * jpayne@69: * @param appendTo output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @return the UnicodeString with inserted pattern. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UnicodeString& toPattern(UnicodeString& appendTo); jpayne@69: jpayne@69: /** jpayne@69: * This method is not yet supported by PluralFormat. jpayne@69: *

jpayne@69: * Before calling, set parse_pos.index to the offset you want to start jpayne@69: * parsing at in the source. After calling, parse_pos.index is the end of jpayne@69: * the text you parsed. If error occurs, index is unchanged. jpayne@69: *

jpayne@69: * When parsing, leading whitespace is discarded (with a successful parse), jpayne@69: * while trailing whitespace is left as is. jpayne@69: *

jpayne@69: * See Format::parseObject() for more. jpayne@69: * jpayne@69: * @param source The string to be parsed into an object. jpayne@69: * @param result Formattable to be set to the parse result. jpayne@69: * If parse fails, return contents are undefined. jpayne@69: * @param parse_pos The position to start parsing at. Upon return jpayne@69: * this param is set to the position after the jpayne@69: * last character successfully parsed. If the jpayne@69: * source is not parsed successfully, this param jpayne@69: * will remain unchanged. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual void parseObject(const UnicodeString& source, jpayne@69: Formattable& result, jpayne@69: ParsePosition& parse_pos) const; jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for this class. jpayne@69: * jpayne@69: * @stable ICU 4.0 jpayne@69: * jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for the actual class. jpayne@69: * jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID() const; jpayne@69: jpayne@69: private: jpayne@69: /** jpayne@69: * @internal (private) jpayne@69: */ jpayne@69: class U_I18N_API PluralSelector : public UMemory { jpayne@69: public: jpayne@69: virtual ~PluralSelector(); jpayne@69: /** jpayne@69: * Given a number, returns the appropriate PluralFormat keyword. jpayne@69: * jpayne@69: * @param context worker object for the selector. jpayne@69: * @param number The number to be plural-formatted. jpayne@69: * @param ec Error code. jpayne@69: * @return The selected PluralFormat keyword. jpayne@69: * @internal (private) jpayne@69: */ jpayne@69: virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0; jpayne@69: }; jpayne@69: jpayne@69: class U_I18N_API PluralSelectorAdapter : public PluralSelector { jpayne@69: public: jpayne@69: PluralSelectorAdapter() : pluralRules(NULL) { jpayne@69: } jpayne@69: jpayne@69: virtual ~PluralSelectorAdapter(); jpayne@69: jpayne@69: virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const; jpayne@69: jpayne@69: void reset(); jpayne@69: jpayne@69: PluralRules* pluralRules; jpayne@69: }; jpayne@69: jpayne@69: Locale locale; jpayne@69: MessagePattern msgPattern; jpayne@69: NumberFormat* numberFormat; jpayne@69: double offset; jpayne@69: PluralSelectorAdapter pluralRulesWrapper; jpayne@69: jpayne@69: PluralFormat(); // default constructor not implemented jpayne@69: void init(const PluralRules* rules, UPluralType type, UErrorCode& status); jpayne@69: /** jpayne@69: * Copies dynamically allocated values (pointer fields). jpayne@69: * Others are copied using their copy constructors and assignment operators. jpayne@69: */ jpayne@69: void copyObjects(const PluralFormat& other); jpayne@69: jpayne@69: UnicodeString& format(const Formattable& numberObject, double number, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition& pos, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Finds the PluralFormat sub-message for the given number, or the "other" sub-message. jpayne@69: * @param pattern A MessagePattern. jpayne@69: * @param partIndex the index of the first PluralFormat argument style part. jpayne@69: * @param selector the PluralSelector for mapping the number (minus offset) to a keyword. jpayne@69: * @param context worker object for the selector. jpayne@69: * @param number a number to be matched to one of the PluralFormat argument's explicit values, jpayne@69: * or mapped via the PluralSelector. jpayne@69: * @param ec ICU error code. jpayne@69: * @return the sub-message start part index. jpayne@69: */ jpayne@69: static int32_t findSubMessage( jpayne@69: const MessagePattern& pattern, int32_t partIndex, jpayne@69: const PluralSelector& selector, void *context, double number, UErrorCode& ec); /**< @internal */ jpayne@69: jpayne@69: void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner, jpayne@69: Formattable& result, FieldPosition& pos) const; jpayne@69: jpayne@69: friend class MessageFormat; jpayne@69: friend class NFRule; jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // _PLURFMT jpayne@69: //eof