/*
*******************************************************************************
-* Copyright (C) 2007-2012, International Business Machines Corporation and
+* Copyright (C) 2007-2014, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File PLURFMT.H
-*
-* Modification History:*
-* Date Name Description
-*
********************************************************************************
*/
U_NAMESPACE_BEGIN
class Hashtable;
+class NFRule;
/**
* <p>
public:
/**
- * Creates a new <code>PluralFormat</code> for the default locale.
+ * Creates a new cardinal-number <code>PluralFormat</code> for the default locale.
* This locale will be used to get the set of plural rules and for standard
* number formatting.
* @param status output param set to success/failure code on exit, which
PluralFormat(UErrorCode& status);
/**
- * Creates a new <code>PluralFormat</code> for a given locale.
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given locale.
* @param locale the <code>PluralFormat</code> will be configured with
* rules for this locale. This locale will also be used for
* standard number formatting.
* @param status output param set to success/failure code on exit, which
* must not indicate a failure before the function call.
* @stable ICU 4.0
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample1
+ * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample
+ * <p>
*/
PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
/**
- * Creates a new <code>PluralFormat</code> for a given pattern string.
+ * Creates a new <code>PluralFormat</code> for the plural type.
+ * The standard number formatting will be done using the given locale.
+ * @param locale the default number formatting will be done using this
+ * locale.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 50
+ */
+ PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
+
+ /**
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string.
* The default locale will be used to get the set of plural rules and for
* standard number formatting.
* @param pattern the pattern for this <code>PluralFormat</code>.
PluralFormat(const UnicodeString& pattern, UErrorCode& status);
/**
- * Creates a new <code>PluralFormat</code> for a given pattern string and
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string and
* locale.
* The locale will be used to get the set of plural rules and for
* standard number formatting.
const UnicodeString& pattern,
UErrorCode& status);
+ /**
+ * Creates a new <code>PluralFormat</code> for a plural type, a
+ * pattern and a locale.
+ * @param locale the <code>PluralFormat</code> will be configured with
+ * rules for this locale. This locale will also be used for
+ * standard number formatting.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @param pattern the pattern for this <code>PluralFormat</code>.
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 50
+ */
+ PluralFormat(const Locale& locale,
+ UPluralType type,
+ const UnicodeString& pattern,
+ UErrorCode& status);
+
/**
* copy constructor.
* @stable ICU 4.0
FieldPosition& pos,
UErrorCode& status) const;
+#ifndef U_HIDE_DEPRECATED_API
/**
* Sets the locale used by this <code>PluraFormat</code> object.
* Note: Calling this method resets this <code>PluraFormat</code> object,
* i.e., a pattern that was applied previously will be removed,
* and the NumberFormat is set to the default number format for
* the locale. The resulting format behaves the same as one
- * constructed from {@link #PluralFormat(const Locale& locale, UErrorCode& status)}.
+ * constructed from {@link #PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status)}
+ * with UPLURAL_TYPE_CARDINAL.
* @param locale the <code>locale</code> to use to configure the formatter.
* @param status output param set to success/failure code on exit, which
* must not indicate a failure before the function call.
- * @stable ICU 4.0
+ * @deprecated ICU 50 This method clears the pattern and might create
+ * a different kind of PluralRules instance;
+ * use one of the constructors to create a new instance instead.
*/
void setLocale(const Locale& locale, UErrorCode& status);
+#endif /* U_HIDE_DEPRECATED_API */
/**
* Sets the number format used by this formatter. You only need to
*/
virtual Format* clone(void) const;
- /**
- * Redeclared Format method.
+ /**
+ * Formats a plural message for a number taken from a Formattable object.
*
- * @param obj The object to be formatted into a string.
+ * @param obj The object containing a number for which the
+ * plural message should be formatted.
+ * The object must be of a numeric type.
* @param appendTo output parameter to receive result.
* Result is appended to existing contents.
* @param pos On input: an alignment field, if desired.
*/
virtual UClassID getDynamicClassID() const;
-#if defined(__xlC__) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
+#if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
// Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
// prevent PluralSelectorAdapter from implementing private PluralSelector.
// xlC error message:
private:
#endif
/**
- * @internal
+ * @internal
*/
class U_I18N_API PluralSelector : public UMemory {
public:
/**
* Given a number, returns the appropriate PluralFormat keyword.
*
+ * @param context worker object for the selector.
* @param number The number to be plural-formatted.
* @param ec Error code.
* @return The selected PluralFormat keyword.
+ * @internal
*/
- virtual UnicodeString select(double number, UErrorCode& ec) const = 0;
+ virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
};
/**
virtual ~PluralSelectorAdapter();
- virtual UnicodeString select(double number, UErrorCode& /*ec*/) const;
+ virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const; /**< @internal */
void reset();
PluralSelectorAdapter pluralRulesWrapper;
PluralFormat(); // default constructor not implemented
- void init(const PluralRules* rules, UErrorCode& status);
+ void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
/**
* Copies dynamically allocated values (pointer fields).
* Others are copied using their copy constructors and assignment operators.
*/
void copyObjects(const PluralFormat& other);
+ UnicodeString& format(const Formattable& numberObject, double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const; /**< @internal */
+
/**
* Finds the PluralFormat sub-message for the given number, or the "other" sub-message.
* @param pattern A MessagePattern.
* @param partIndex the index of the first PluralFormat argument style part.
* @param selector the PluralSelector for mapping the number (minus offset) to a keyword.
+ * @param context worker object for the selector.
* @param number a number to be matched to one of the PluralFormat argument's explicit values,
* or mapped via the PluralSelector.
* @param ec ICU error code.
*/
static int32_t findSubMessage(
const MessagePattern& pattern, int32_t partIndex,
- const PluralSelector& selector, double number, UErrorCode& ec);
+ const PluralSelector& selector, void *context, double number, UErrorCode& ec); /**< @internal */
+
+ void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
+ Formattable& result, FieldPosition& pos) const;
friend class MessageFormat;
+ friend class NFRule;
};
U_NAMESPACE_END