X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/51004dcb01e06fef634b61be77ed73dd61cb6db9..38fbf2fd31f5cd99b500914d6037b1d06b608645:/icuSources/i18n/unicode/plurfmt.h?ds=sidebyside diff --git a/icuSources/i18n/unicode/plurfmt.h b/icuSources/i18n/unicode/plurfmt.h index 0e45b0bf..25251b75 100644 --- a/icuSources/i18n/unicode/plurfmt.h +++ b/icuSources/i18n/unicode/plurfmt.h @@ -1,15 +1,13 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* -* Copyright (C) 2007-2013, 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 -* ******************************************************************************** */ @@ -29,9 +27,11 @@ #include "unicode/numfmt.h" #include "unicode/plurrule.h" +#if U_SHOW_CPLUSPLUS_API U_NAMESPACE_BEGIN class Hashtable; +class NFRule; /** *

@@ -189,10 +189,14 @@ public: * @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 + *

+ *

Sample code

+ * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample1 + * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample + *

*/ PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status); -#ifndef U_HIDE_DRAFT_API /** * Creates a new PluralFormat for the plural type. * The standard number formatting will be done using the given locale. @@ -201,10 +205,9 @@ public: * @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. - * @draft ICU 50 + * @stable ICU 50 */ PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status); -#endif /* U_HIDE_DRAFT_API */ /** * Creates a new cardinal-number PluralFormat for a given pattern string. @@ -268,7 +271,6 @@ public: const UnicodeString& pattern, UErrorCode& status); -#ifndef U_HIDE_DRAFT_API /** * Creates a new PluralFormat for a plural type, a * pattern and a locale. @@ -280,13 +282,12 @@ public: * 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. - * @draft ICU 50 + * @stable ICU 50 */ PluralFormat(const Locale& locale, UPluralType type, const UnicodeString& pattern, UErrorCode& status); -#endif /* U_HIDE_DRAFT_API */ /** * copy constructor. @@ -450,10 +451,12 @@ public: */ 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. @@ -528,7 +531,7 @@ public: private: #endif /** - * @internal + * @internal */ class U_I18N_API PluralSelector : public UMemory { public: @@ -536,11 +539,13 @@ private: /** * 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; }; /** @@ -553,7 +558,7 @@ private: virtual ~PluralSelectorAdapter(); - virtual UnicodeString select(double number, UErrorCode& /*ec*/) const; + virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const; /**< @internal */ void reset(); @@ -578,11 +583,17 @@ private: */ 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. @@ -590,12 +601,17 @@ private: */ 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 +#endif // U_SHOW_CPLUSPLUS_API #endif /* #if !UCONFIG_NO_FORMATTING */