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: * Copyright (C) 2007-2013, International Business Machines Corporation and jpayne@69: * others. All Rights Reserved. jpayne@69: ******************************************************************************** jpayne@69: * jpayne@69: * File MSGFMT.H jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 02/19/97 aliu Converted from java. jpayne@69: * 03/20/97 helena Finished first cut of implementation. jpayne@69: * 07/22/98 stephen Removed operator!= (defined in Format) jpayne@69: * 08/19/2002 srl Removing Javaisms jpayne@69: *******************************************************************************/ jpayne@69: jpayne@69: #ifndef MSGFMT_H jpayne@69: #define MSGFMT_H 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: Formats messages in a language-neutral way. jpayne@69: */ jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/format.h" jpayne@69: #include "unicode/locid.h" jpayne@69: #include "unicode/messagepattern.h" jpayne@69: #include "unicode/parseerr.h" jpayne@69: #include "unicode/plurfmt.h" jpayne@69: #include "unicode/plurrule.h" jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: // Forward declaration. jpayne@69: struct UHashtable; jpayne@69: typedef struct UHashtable UHashtable; /**< @internal */ jpayne@69: U_CDECL_END jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class AppendableWrapper; jpayne@69: class DateFormat; jpayne@69: class NumberFormat; jpayne@69: jpayne@69: /** jpayne@69: *

MessageFormat prepares strings for display to users, jpayne@69: * with optional arguments (variables/placeholders). jpayne@69: * The arguments can occur in any order, which is necessary for translation jpayne@69: * into languages with different grammars. jpayne@69: * jpayne@69: *

A MessageFormat is constructed from a pattern string jpayne@69: * with arguments in {curly braces} which will be replaced by formatted values. jpayne@69: * jpayne@69: *

MessageFormat differs from the other Format jpayne@69: * classes in that you create a MessageFormat object with one jpayne@69: * of its constructors (not with a createInstance style factory jpayne@69: * method). Factory methods aren't necessary because MessageFormat jpayne@69: * itself doesn't implement locale-specific behavior. Any locale-specific jpayne@69: * behavior is defined by the pattern that you provide and the jpayne@69: * subformats used for inserted arguments. jpayne@69: * jpayne@69: *

Arguments can be named (using identifiers) or numbered (using small ASCII-digit integers). jpayne@69: * Some of the API methods work only with argument numbers and throw an exception jpayne@69: * if the pattern has named arguments (see {@link #usesNamedArguments()}). jpayne@69: * jpayne@69: *

An argument might not specify any format type. In this case, jpayne@69: * a numeric value is formatted with a default (for the locale) NumberFormat, jpayne@69: * and a date/time value is formatted with a default (for the locale) DateFormat. jpayne@69: * jpayne@69: *

An argument might specify a "simple" type for which the specified jpayne@69: * Format object is created, cached and used. jpayne@69: * jpayne@69: *

An argument might have a "complex" type with nested MessageFormat sub-patterns. jpayne@69: * During formatting, one of these sub-messages is selected according to the argument value jpayne@69: * and recursively formatted. jpayne@69: * jpayne@69: *

After construction, a custom Format object can be set for jpayne@69: * a top-level argument, overriding the default formatting and parsing behavior jpayne@69: * for that argument. jpayne@69: * However, custom formatting can be achieved more simply by writing jpayne@69: * a typeless argument in the pattern string jpayne@69: * and supplying it with a preformatted string value. jpayne@69: * jpayne@69: *

When formatting, MessageFormat takes a collection of argument values jpayne@69: * and writes an output string. jpayne@69: * The argument values may be passed as an array jpayne@69: * (when the pattern contains only numbered arguments) jpayne@69: * or as an array of names and and an array of arguments (which works for both named jpayne@69: * and numbered arguments). jpayne@69: * jpayne@69: *

Each argument is matched with one of the input values by array index or argument name jpayne@69: * and formatted according to its pattern specification jpayne@69: * (or using a custom Format object if one was set). jpayne@69: * A numbered pattern argument is matched with an argument name that contains that number jpayne@69: * as an ASCII-decimal-digit string (without leading zero). jpayne@69: * jpayne@69: *

Patterns and Their Interpretation

jpayne@69: * jpayne@69: * MessageFormat uses patterns of the following form: jpayne@69: *
jpayne@69:  * message = messageText (argument messageText)*
jpayne@69:  * argument = noneArg | simpleArg | complexArg
jpayne@69:  * complexArg = choiceArg | pluralArg | selectArg | selectordinalArg
jpayne@69:  *
jpayne@69:  * noneArg = '{' argNameOrNumber '}'
jpayne@69:  * simpleArg = '{' argNameOrNumber ',' argType [',' argStyle] '}'
jpayne@69:  * choiceArg = '{' argNameOrNumber ',' "choice" ',' choiceStyle '}'
jpayne@69:  * pluralArg = '{' argNameOrNumber ',' "plural" ',' pluralStyle '}'
jpayne@69:  * selectArg = '{' argNameOrNumber ',' "select" ',' selectStyle '}'
jpayne@69:  * selectordinalArg = '{' argNameOrNumber ',' "selectordinal" ',' pluralStyle '}'
jpayne@69:  *
jpayne@69:  * choiceStyle: see {@link ChoiceFormat}
jpayne@69:  * pluralStyle: see {@link PluralFormat}
jpayne@69:  * selectStyle: see {@link SelectFormat}
jpayne@69:  *
jpayne@69:  * argNameOrNumber = argName | argNumber
jpayne@69:  * argName = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
jpayne@69:  * argNumber = '0' | ('1'..'9' ('0'..'9')*)
jpayne@69:  *
jpayne@69:  * argType = "number" | "date" | "time" | "spellout" | "ordinal" | "duration"
jpayne@69:  * argStyle = "short" | "medium" | "long" | "full" | "integer" | "currency" | "percent" | argStyleText | "::" argSkeletonText
jpayne@69:  * 
jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: *

Recommendation: Use the real apostrophe (single quote) character jpayne@69: * \htmlonly’\endhtmlonly (U+2019) for jpayne@69: * human-readable text, and use the ASCII apostrophe ' (U+0027) jpayne@69: * only in program syntax, like quoting in MessageFormat. jpayne@69: * See the annotations for U+0027 Apostrophe in The Unicode Standard. jpayne@69: * jpayne@69: *

The choice argument type is deprecated. jpayne@69: * Use plural arguments for proper plural selection, jpayne@69: * and select arguments for simple selection among a fixed set of choices. jpayne@69: * jpayne@69: *

The argType and argStyle values are used to create jpayne@69: * a Format instance for the format element. The following jpayne@69: * table shows how the values map to Format instances. Combinations not jpayne@69: * shown in the table are illegal. Any argStyleText must jpayne@69: * be a valid pattern string for the Format subclass used. jpayne@69: * jpayne@69: *

jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: *
argType jpayne@69: * argStyle jpayne@69: * resulting Format object jpayne@69: *
(none) jpayne@69: * null jpayne@69: *
number jpayne@69: * (none) jpayne@69: * NumberFormat.createInstance(getLocale(), status) jpayne@69: *
integer jpayne@69: * NumberFormat.createInstance(getLocale(), kNumberStyle, status) jpayne@69: *
currency jpayne@69: * NumberFormat.createCurrencyInstance(getLocale(), status) jpayne@69: *
percent jpayne@69: * NumberFormat.createPercentInstance(getLocale(), status) jpayne@69: *
argStyleText jpayne@69: * new DecimalFormat(argStyleText, new DecimalFormatSymbols(getLocale(), status), status) jpayne@69: *
argSkeletonText jpayne@69: * NumberFormatter::forSkeleton(argSkeletonText, status).locale(getLocale()).toFormat(status) jpayne@69: *
date jpayne@69: * (none) jpayne@69: * DateFormat.createDateInstance(kDefault, getLocale(), status) jpayne@69: *
short jpayne@69: * DateFormat.createDateInstance(kShort, getLocale(), status) jpayne@69: *
medium jpayne@69: * DateFormat.createDateInstance(kDefault, getLocale(), status) jpayne@69: *
long jpayne@69: * DateFormat.createDateInstance(kLong, getLocale(), status) jpayne@69: *
full jpayne@69: * DateFormat.createDateInstance(kFull, getLocale(), status) jpayne@69: *
argStyleText jpayne@69: * new SimpleDateFormat(argStyleText, getLocale(), status) jpayne@69: *
argSkeletonText jpayne@69: * DateFormat::createInstanceForSkeleton(argSkeletonText, getLocale(), status) jpayne@69: *
time jpayne@69: * (none) jpayne@69: * DateFormat.createTimeInstance(kDefault, getLocale(), status) jpayne@69: *
short jpayne@69: * DateFormat.createTimeInstance(kShort, getLocale(), status) jpayne@69: *
medium jpayne@69: * DateFormat.createTimeInstance(kDefault, getLocale(), status) jpayne@69: *
long jpayne@69: * DateFormat.createTimeInstance(kLong, getLocale(), status) jpayne@69: *
full jpayne@69: * DateFormat.createTimeInstance(kFull, getLocale(), status) jpayne@69: *
argStyleText jpayne@69: * new SimpleDateFormat(argStyleText, getLocale(), status) jpayne@69: *
spellout jpayne@69: * argStyleText (optional) jpayne@69: * new RuleBasedNumberFormat(URBNF_SPELLOUT, getLocale(), status) jpayne@69: *
    .setDefaultRuleset(argStyleText, status);
jpayne@69: *
ordinal jpayne@69: * argStyleText (optional) jpayne@69: * new RuleBasedNumberFormat(URBNF_ORDINAL, getLocale(), status) jpayne@69: *
    .setDefaultRuleset(argStyleText, status);
jpayne@69: *
duration jpayne@69: * argStyleText (optional) jpayne@69: * new RuleBasedNumberFormat(URBNF_DURATION, getLocale(), status) jpayne@69: *
    .setDefaultRuleset(argStyleText, status);
jpayne@69: *
jpayne@69: *

jpayne@69: * jpayne@69: *

Argument formatting

jpayne@69: * jpayne@69: *

Arguments are formatted according to their type, using the default jpayne@69: * ICU formatters for those types, unless otherwise specified.

jpayne@69: * jpayne@69: *

There are also several ways to control the formatting.

jpayne@69: * jpayne@69: *

We recommend you use default styles, predefined style values, skeletons, jpayne@69: * or preformatted values, but not pattern strings or custom format objects.

jpayne@69: * jpayne@69: *

For more details, see the jpayne@69: * ICU User Guide.

jpayne@69: * jpayne@69: *

Usage Information

jpayne@69: * jpayne@69: *

Here are some examples of usage: jpayne@69: * Example 1: jpayne@69: * jpayne@69: *

jpayne@69:  * \code
jpayne@69:  *     UErrorCode success = U_ZERO_ERROR;
jpayne@69:  *     GregorianCalendar cal(success);
jpayne@69:  *     Formattable arguments[] = {
jpayne@69:  *         7L,
jpayne@69:  *         Formattable( (Date) cal.getTime(success), Formattable::kIsDate),
jpayne@69:  *         "a disturbance in the Force"
jpayne@69:  *     };
jpayne@69:  *
jpayne@69:  *     UnicodeString result;
jpayne@69:  *     MessageFormat::format(
jpayne@69:  *          "At {1,time,::jmm} on {1,date,::dMMMM}, there was {2} on planet {0,number}.",
jpayne@69:  *          arguments, 3, result, success );
jpayne@69:  *
jpayne@69:  *     cout << "result: " << result << endl;
jpayne@69:  *     //: At 4:34 PM on March 23, there was a disturbance
jpayne@69:  *     //             in the Force on planet 7.
jpayne@69:  * \endcode
jpayne@69:  * 
jpayne@69: * jpayne@69: * Typically, the message format will come from resources, and the jpayne@69: * arguments will be dynamically set at runtime. jpayne@69: * jpayne@69: *

Example 2: jpayne@69: * jpayne@69: *

jpayne@69:  *  \code
jpayne@69:  *     success = U_ZERO_ERROR;
jpayne@69:  *     Formattable testArgs[] = {3L, "MyDisk"};
jpayne@69:  *
jpayne@69:  *     MessageFormat form(
jpayne@69:  *         "The disk \"{1}\" contains {0} file(s).", success );
jpayne@69:  *
jpayne@69:  *     UnicodeString string;
jpayne@69:  *     FieldPosition fpos = 0;
jpayne@69:  *     cout << "format: " << form.format(testArgs, 2, string, fpos, success ) << endl;
jpayne@69:  *
jpayne@69:  *     // output, with different testArgs:
jpayne@69:  *     // output: The disk "MyDisk" contains 0 file(s).
jpayne@69:  *     // output: The disk "MyDisk" contains 1 file(s).
jpayne@69:  *     // output: The disk "MyDisk" contains 1,273 file(s).
jpayne@69:  *  \endcode
jpayne@69:  *  
jpayne@69: * jpayne@69: * jpayne@69: *

For messages that include plural forms, you can use a plural argument: jpayne@69: *

jpayne@69:  * \code
jpayne@69:  *  success = U_ZERO_ERROR;
jpayne@69:  *  MessageFormat msgFmt(
jpayne@69:  *       "{num_files, plural, "
jpayne@69:  *       "=0{There are no files on disk \"{disk_name}\".}"
jpayne@69:  *       "=1{There is one file on disk \"{disk_name}\".}"
jpayne@69:  *       "other{There are # files on disk \"{disk_name}\".}}",
jpayne@69:  *      Locale("en"),
jpayne@69:  *      success);
jpayne@69:  *  FieldPosition fpos = 0;
jpayne@69:  *  Formattable testArgs[] = {0L, "MyDisk"};
jpayne@69:  *  UnicodeString testArgsNames[] = {"num_files", "disk_name"};
jpayne@69:  *  UnicodeString result;
jpayne@69:  *  cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);
jpayne@69:  *  testArgs[0] = 3L;
jpayne@69:  *  cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);
jpayne@69:  * \endcode
jpayne@69:  * output:
jpayne@69:  * There are no files on disk "MyDisk".
jpayne@69:  * There are 3 files on "MyDisk".
jpayne@69:  * 
jpayne@69: * See {@link PluralFormat} and {@link PluralRules} for details. jpayne@69: * jpayne@69: *

Synchronization

jpayne@69: * jpayne@69: *

MessageFormats are not synchronized. jpayne@69: * It is recommended to create separate format instances for each thread. jpayne@69: * If multiple threads access a format concurrently, it must be synchronized jpayne@69: * externally. jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: class U_I18N_API MessageFormat : public Format { jpayne@69: public: jpayne@69: #ifndef U_HIDE_OBSOLETE_API jpayne@69: /** jpayne@69: * Enum type for kMaxFormat. jpayne@69: * @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6, jpayne@69: * rendering this enum type obsolete. jpayne@69: */ jpayne@69: enum EFormatNumber { jpayne@69: /** jpayne@69: * The maximum number of arguments. jpayne@69: * @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6, jpayne@69: * rendering this constant obsolete. jpayne@69: */ jpayne@69: kMaxFormat = 10 jpayne@69: }; jpayne@69: #endif /* U_HIDE_OBSOLETE_API */ jpayne@69: jpayne@69: /** jpayne@69: * Constructs a new MessageFormat using the given pattern and the jpayne@69: * default locale. jpayne@69: * jpayne@69: * @param pattern Pattern used to construct object. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: MessageFormat(const UnicodeString& pattern, jpayne@69: UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Constructs a new MessageFormat using the given pattern and locale. jpayne@69: * @param pattern Pattern used to construct object. jpayne@69: * @param newLocale The locale to use for formatting dates and numbers. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: MessageFormat(const UnicodeString& pattern, jpayne@69: const Locale& newLocale, jpayne@69: UErrorCode& status); jpayne@69: /** jpayne@69: * Constructs a new MessageFormat using the given pattern and locale. jpayne@69: * @param pattern Pattern used to construct object. jpayne@69: * @param newLocale The locale to use for formatting dates and numbers. jpayne@69: * @param parseError Struct to receive information on the position jpayne@69: * of an error within the pattern. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: MessageFormat(const UnicodeString& pattern, jpayne@69: const Locale& newLocale, jpayne@69: UParseError& parseError, jpayne@69: UErrorCode& status); jpayne@69: /** jpayne@69: * Constructs a new MessageFormat from an existing one. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: MessageFormat(const MessageFormat&); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const MessageFormat& operator=(const MessageFormat&); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual ~MessageFormat(); 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 2.0 jpayne@69: */ jpayne@69: virtual MessageFormat* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Returns true if the given Format objects are semantically equal. jpayne@69: * Objects of different subclasses are considered unequal. jpayne@69: * @param other the object to be compared with. jpayne@69: * @return true if the given Format objects are semantically equal. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UBool operator==(const Format& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the locale to be used for creating argument Format objects. jpayne@69: * @param theLocale the new locale value to be set. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setLocale(const Locale& theLocale); jpayne@69: jpayne@69: /** jpayne@69: * Gets the locale used for creating argument Format objects. jpayne@69: * format information. jpayne@69: * @return the locale of the object. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual const Locale& getLocale(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Applies the given pattern string to this message format. jpayne@69: * jpayne@69: * @param pattern The pattern to be applied. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void applyPattern(const UnicodeString& pattern, jpayne@69: UErrorCode& status); jpayne@69: /** jpayne@69: * Applies the given pattern string to this message format. jpayne@69: * jpayne@69: * @param pattern The pattern to be applied. jpayne@69: * @param parseError Struct to receive information on the position jpayne@69: * of an error within the pattern. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void applyPattern(const UnicodeString& pattern, jpayne@69: UParseError& parseError, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the UMessagePatternApostropheMode and the pattern used by this message format. jpayne@69: * Parses the pattern and caches Format objects for simple argument types. jpayne@69: * Patterns and their interpretation are specified in the jpayne@69: * class description. jpayne@69: *

jpayne@69: * This method is best used only once on a given object to avoid confusion about the mode, jpayne@69: * and after constructing the object with an empty pattern string to minimize overhead. jpayne@69: * jpayne@69: * @param pattern The pattern to be applied. jpayne@69: * @param aposMode The new apostrophe mode. jpayne@69: * @param parseError Struct to receive information on the position jpayne@69: * of an error within the pattern. jpayne@69: * Can be NULL. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: virtual void applyPattern(const UnicodeString& pattern, jpayne@69: UMessagePatternApostropheMode aposMode, jpayne@69: UParseError* parseError, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * @return this instance's UMessagePatternApostropheMode. jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: UMessagePatternApostropheMode getApostropheMode() const { jpayne@69: return msgPattern.getApostropheMode(); jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * Returns a pattern that can be used to recreate this object. jpayne@69: * jpayne@69: * @param appendTo Output parameter to receive the pattern. jpayne@69: * Result is appended to existing contents. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UnicodeString& toPattern(UnicodeString& appendTo) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets subformats. jpayne@69: * See the class description about format numbering. jpayne@69: * The caller should not delete the Format objects after this call. jpayne@69: * The array formatsToAdopt is not itself adopted. Its jpayne@69: * ownership is retained by the caller. If the call fails because jpayne@69: * memory cannot be allocated, then the formats will be deleted jpayne@69: * by this method, and this object will remain unchanged. jpayne@69: * jpayne@69: *

If this format uses named arguments, the new formats are discarded jpayne@69: * and this format remains unchanged. jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: * @param formatsToAdopt the format to be adopted. jpayne@69: * @param count the size of the array. jpayne@69: */ jpayne@69: virtual void adoptFormats(Format** formatsToAdopt, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Sets subformats. jpayne@69: * See the class description about format numbering. jpayne@69: * Each item in the array is cloned into the internal array. jpayne@69: * If the call fails because memory cannot be allocated, then this jpayne@69: * object will remain unchanged. jpayne@69: * jpayne@69: *

If this format uses named arguments, the new formats are discarded jpayne@69: * and this format remains unchanged. jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: * @param newFormats the new format to be set. jpayne@69: * @param cnt the size of the array. jpayne@69: */ jpayne@69: virtual void setFormats(const Format** newFormats, int32_t cnt); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Sets one subformat. jpayne@69: * See the class description about format numbering. jpayne@69: * The caller should not delete the Format object after this call. jpayne@69: * If the number is over the number of formats already set, jpayne@69: * the item will be deleted and ignored. jpayne@69: * jpayne@69: *

If this format uses named arguments, the new format is discarded jpayne@69: * and this format remains unchanged. jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: * @param formatNumber index of the subformat. jpayne@69: * @param formatToAdopt the format to be adopted. jpayne@69: */ jpayne@69: virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt); jpayne@69: jpayne@69: /** jpayne@69: * Sets one subformat. jpayne@69: * See the class description about format numbering. jpayne@69: * If the number is over the number of formats already set, jpayne@69: * the item will be ignored. jpayne@69: * @param formatNumber index of the subformat. jpayne@69: * @param format the format to be set. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setFormat(int32_t formatNumber, const Format& format); jpayne@69: jpayne@69: /** jpayne@69: * Gets format names. This function returns formatNames in StringEnumerations jpayne@69: * which can be used with getFormat() and setFormat() to export formattable jpayne@69: * array from current MessageFormat to another. It is the caller's responsibility jpayne@69: * to delete the returned formatNames. jpayne@69: * @param status output param set to success/failure code. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual StringEnumeration* getFormatNames(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Gets subformat pointer for given format name. jpayne@69: * This function supports both named and numbered jpayne@69: * arguments. If numbered, the formatName is the jpayne@69: * corresponding UnicodeStrings (e.g. "0", "1", "2"...). jpayne@69: * The returned Format object should not be deleted by the caller, jpayne@69: * nor should the ponter of other object . The pointer and its jpayne@69: * contents remain valid only until the next call to any method jpayne@69: * of this class is made with this object. jpayne@69: * @param formatName the name or number specifying a format jpayne@69: * @param status output param set to success/failure code. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets one subformat for given format name. jpayne@69: * See the class description about format name. jpayne@69: * This function supports both named and numbered jpayne@69: * arguments-- if numbered, the formatName is the jpayne@69: * corresponding UnicodeStrings (e.g. "0", "1", "2"...). jpayne@69: * If there is no matched formatName or wrong type, jpayne@69: * the item will be ignored. jpayne@69: * @param formatName Name of the subformat. jpayne@69: * @param format the format to be set. jpayne@69: * @param status output param set to success/failure code. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets one subformat for given format name. jpayne@69: * See the class description about format name. jpayne@69: * This function supports both named and numbered jpayne@69: * arguments-- if numbered, the formatName is the jpayne@69: * corresponding UnicodeStrings (e.g. "0", "1", "2"...). jpayne@69: * If there is no matched formatName or wrong type, jpayne@69: * the item will be ignored. jpayne@69: * The caller should not delete the Format object after this call. jpayne@69: * @param formatName Name of the subformat. jpayne@69: * @param formatToAdopt Format to be adopted. jpayne@69: * @param status output param set to success/failure code. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Gets an array of subformats of this object. The returned array jpayne@69: * should not be deleted by the caller, nor should the pointers jpayne@69: * within the array. The array and its contents remain valid only jpayne@69: * until the next call to this format. See the class description jpayne@69: * about format numbering. jpayne@69: * jpayne@69: * @param count output parameter to receive the size of the array jpayne@69: * @return an array of count Format* objects, or NULL if out of jpayne@69: * memory. Any or all of the array elements may be NULL. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual const Format** getFormats(int32_t& count) const; jpayne@69: jpayne@69: jpayne@69: using Format::format; jpayne@69: jpayne@69: /** jpayne@69: * Formats the given array of arguments into a user-readable string. jpayne@69: * Does not take ownership of the Formattable* array or its contents. jpayne@69: * jpayne@69: *

If this format uses named arguments, appendTo is unchanged and jpayne@69: * status is set to U_ILLEGAL_ARGUMENT_ERROR. jpayne@69: * jpayne@69: * @param source An array of objects to be formatted. jpayne@69: * @param count The number of elements of 'source'. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param ignore Not used; inherited from base class API. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& format(const Formattable* source, jpayne@69: int32_t count, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition& ignore, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Formats the given array of arguments into a user-readable string jpayne@69: * using the given pattern. jpayne@69: * jpayne@69: *

If this format uses named arguments, appendTo is unchanged and jpayne@69: * status is set to U_ILLEGAL_ARGUMENT_ERROR. jpayne@69: * jpayne@69: * @param pattern The pattern. jpayne@69: * @param arguments An array of objects to be formatted. jpayne@69: * @param count The number of elements of 'source'. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UnicodeString& format(const UnicodeString& pattern, jpayne@69: const Formattable* arguments, jpayne@69: int32_t count, jpayne@69: UnicodeString& appendTo, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Formats the given array of arguments into a user-readable jpayne@69: * string. The array must be stored within a single Formattable jpayne@69: * object of type kArray. If the Formattable object type is not of jpayne@69: * type kArray, then returns a failing UErrorCode. jpayne@69: * jpayne@69: *

If this format uses named arguments, appendTo is unchanged and jpayne@69: * status is set to U_ILLEGAL_ARGUMENT_ERROR. jpayne@69: * jpayne@69: * @param obj A Formattable of type kArray containing jpayne@69: * arguments to be formatted. 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 Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UnicodeString& format(const Formattable& obj, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition& pos, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Formats the given array of arguments into a user-defined argument name jpayne@69: * array. This function supports both named and numbered jpayne@69: * arguments-- if numbered, the formatName is the jpayne@69: * corresponding UnicodeStrings (e.g. "0", "1", "2"...). jpayne@69: * jpayne@69: * @param argumentNames argument name array jpayne@69: * @param arguments An array of objects to be formatted. jpayne@69: * @param count The number of elements of 'argumentNames' and jpayne@69: * arguments. The number of argumentNames and arguments jpayne@69: * must be the same. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UnicodeString& format(const UnicodeString* argumentNames, jpayne@69: const Formattable* arguments, jpayne@69: int32_t count, jpayne@69: UnicodeString& appendTo, jpayne@69: UErrorCode& status) const; jpayne@69: /** jpayne@69: * Parses the given string into an array of output arguments. jpayne@69: * jpayne@69: * @param source String to be parsed. jpayne@69: * @param pos On input, starting position for parse. On output, jpayne@69: * final position after parse. Unchanged if parse jpayne@69: * fails. jpayne@69: * @param count Output parameter to receive the number of arguments jpayne@69: * parsed. jpayne@69: * @return an array of parsed arguments. The caller owns both jpayne@69: * the array and its contents. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual Formattable* parse(const UnicodeString& source, jpayne@69: ParsePosition& pos, jpayne@69: int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Parses the given string into an array of output arguments. jpayne@69: * jpayne@69: *

If this format uses named arguments, status is set to jpayne@69: * U_ARGUMENT_TYPE_MISMATCH. jpayne@69: * jpayne@69: * @param source String to be parsed. jpayne@69: * @param count Output param to receive size of returned array. jpayne@69: * @param status Input/output error code. If the jpayne@69: * pattern cannot be parsed, set to failure code. jpayne@69: * @return an array of parsed arguments. The caller owns both jpayne@69: * the array and its contents. Returns NULL if status is not U_ZERO_ERROR. jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual Formattable* parse(const UnicodeString& source, jpayne@69: int32_t& count, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Parses the given string into an array of output arguments jpayne@69: * stored within a single Formattable of type kArray. 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 pos On input, starting position for parse. On output, jpayne@69: * final position after parse. Unchanged if parse jpayne@69: * fails. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void parseObject(const UnicodeString& source, jpayne@69: Formattable& result, jpayne@69: ParsePosition& pos) const; jpayne@69: jpayne@69: /** jpayne@69: * Convert an 'apostrophe-friendly' pattern into a standard jpayne@69: * pattern. Standard patterns treat all apostrophes as jpayne@69: * quotes, which is problematic in some languages, e.g. jpayne@69: * French, where apostrophe is commonly used. This utility jpayne@69: * assumes that only an unpaired apostrophe immediately before jpayne@69: * a brace is a true quote. Other unpaired apostrophes are paired, jpayne@69: * and the resulting standard pattern string is returned. jpayne@69: * jpayne@69: *

Note it is not guaranteed that the returned pattern jpayne@69: * is indeed a valid pattern. The only effect is to convert jpayne@69: * between patterns having different quoting semantics. jpayne@69: * jpayne@69: * @param pattern the 'apostrophe-friendly' patttern to convert jpayne@69: * @param status Input/output error code. If the pattern jpayne@69: * cannot be parsed, the failure code is set. jpayne@69: * @return the standard equivalent of the original pattern jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Returns true if this MessageFormat uses named arguments, jpayne@69: * and false otherwise. See class description. jpayne@69: * jpayne@69: * @return true if named arguments are used. jpayne@69: * @stable ICU 4.0 jpayne@69: */ jpayne@69: UBool usesNamedArguments() const; jpayne@69: jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * This API is for ICU internal use only. jpayne@69: * Please do not use it. jpayne@69: * jpayne@69: * Returns argument types count in the parsed pattern. jpayne@69: * Used to distinguish pattern "{0} d" and "d". jpayne@69: * jpayne@69: * @return The number of formattable types in the pattern jpayne@69: * @internal jpayne@69: */ jpayne@69: int32_t getArgTypeCount() const; jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. jpayne@69: * This method is to implement a simple version of RTTI, since not all jpayne@69: * C++ compilers support genuine RTTI. Polymorphic operator==() and jpayne@69: * clone() methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for jpayne@69: * comparing to a return value from getDynamicClassID(). For example: jpayne@69: *

jpayne@69:      * .   Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * .   if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      * .      Derived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Compares two Format objects. This is used for constructing the hash jpayne@69: * tables. jpayne@69: * jpayne@69: * @param left pointer to a Format object. Must not be NULL. jpayne@69: * @param right pointer to a Format object. Must not be NULL. jpayne@69: * jpayne@69: * @return whether the two objects are the same jpayne@69: * @internal jpayne@69: */ jpayne@69: static UBool equalFormats(const void* left, const void* right); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: Locale fLocale; jpayne@69: MessagePattern msgPattern; jpayne@69: Format** formatAliases; // see getFormats jpayne@69: int32_t formatAliasesCapacity; jpayne@69: jpayne@69: MessageFormat(); // default constructor not implemented jpayne@69: jpayne@69: /** jpayne@69: * This provider helps defer instantiation of a PluralRules object jpayne@69: * until we actually need to select a keyword. jpayne@69: * For example, if the number matches an explicit-value selector like "=1" jpayne@69: * we do not need any PluralRules. jpayne@69: */ jpayne@69: class U_I18N_API PluralSelectorProvider : public PluralFormat::PluralSelector { jpayne@69: public: jpayne@69: PluralSelectorProvider(const MessageFormat &mf, UPluralType type); jpayne@69: virtual ~PluralSelectorProvider(); jpayne@69: virtual UnicodeString select(void *ctx, double number, UErrorCode& ec) const; jpayne@69: jpayne@69: void reset(); jpayne@69: private: jpayne@69: const MessageFormat &msgFormat; jpayne@69: PluralRules* rules; jpayne@69: UPluralType type; jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * A MessageFormat formats an array of arguments. Each argument jpayne@69: * has an expected type, based on the pattern. For example, if jpayne@69: * the pattern contains the subformat "{3,number,integer}", then jpayne@69: * we expect argument 3 to have type Formattable::kLong. This jpayne@69: * array needs to grow dynamically if the MessageFormat is jpayne@69: * modified. jpayne@69: */ jpayne@69: Formattable::Type* argTypes; jpayne@69: int32_t argTypeCount; jpayne@69: int32_t argTypeCapacity; jpayne@69: jpayne@69: /** jpayne@69: * TRUE if there are different argTypes for the same argument. jpayne@69: * This only matters when the MessageFormat is used in the plain C (umsg_xxx) API jpayne@69: * where the pattern argTypes determine how the va_arg list is read. jpayne@69: */ jpayne@69: UBool hasArgTypeConflicts; jpayne@69: jpayne@69: // Variable-size array management jpayne@69: UBool allocateArgTypes(int32_t capacity, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Default Format objects used when no format is specified and a jpayne@69: * numeric or date argument is formatted. These are volatile jpayne@69: * cache objects maintained only for performance. They do not jpayne@69: * participate in operator=(), copy constructor(), nor jpayne@69: * operator==(). jpayne@69: */ jpayne@69: NumberFormat* defaultNumberFormat; jpayne@69: DateFormat* defaultDateFormat; jpayne@69: jpayne@69: UHashtable* cachedFormatters; jpayne@69: UHashtable* customFormatArgStarts; jpayne@69: jpayne@69: PluralSelectorProvider pluralProvider; jpayne@69: PluralSelectorProvider ordinalProvider; jpayne@69: jpayne@69: /** jpayne@69: * Method to retrieve default formats (or NULL on failure). jpayne@69: * These are semantically const, but may modify *this. jpayne@69: */ jpayne@69: const NumberFormat* getDefaultNumberFormat(UErrorCode&) const; jpayne@69: const DateFormat* getDefaultDateFormat(UErrorCode&) const; jpayne@69: jpayne@69: /** jpayne@69: * Finds the word s, in the keyword list and returns the located index. jpayne@69: * @param s the keyword to be searched for. jpayne@69: * @param list the list of keywords to be searched with. jpayne@69: * @return the index of the list which matches the keyword s. jpayne@69: */ jpayne@69: static int32_t findKeyword( const UnicodeString& s, jpayne@69: const char16_t * const *list); jpayne@69: jpayne@69: /** jpayne@69: * Thin wrapper around the format(... AppendableWrapper ...) variant. jpayne@69: * Wraps the destination UnicodeString into an AppendableWrapper and jpayne@69: * supplies default values for some other parameters. jpayne@69: */ jpayne@69: UnicodeString& format(const Formattable* arguments, jpayne@69: const UnicodeString *argumentNames, jpayne@69: int32_t cnt, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition* pos, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Formats the arguments and writes the result into the jpayne@69: * AppendableWrapper, updates the field position. jpayne@69: * jpayne@69: * @param msgStart Index to msgPattern part to start formatting from. jpayne@69: * @param plNumber NULL except when formatting a plural argument sub-message jpayne@69: * where a '#' is replaced by the format string for this number. jpayne@69: * @param arguments The formattable objects array. (Must not be NULL.) jpayne@69: * @param argumentNames NULL if numbered values are used. Otherwise the same jpayne@69: * length as "arguments", and each entry is the name of the jpayne@69: * corresponding argument in "arguments". jpayne@69: * @param cnt The length of arguments (and of argumentNames if that is not NULL). jpayne@69: * @param appendTo Output parameter to receive the result. jpayne@69: * The result string is appended to existing contents. jpayne@69: * @param pos Field position status. jpayne@69: * @param success The error code status. jpayne@69: */ jpayne@69: void format(int32_t msgStart, jpayne@69: const void *plNumber, jpayne@69: const Formattable* arguments, jpayne@69: const UnicodeString *argumentNames, jpayne@69: int32_t cnt, jpayne@69: AppendableWrapper& appendTo, jpayne@69: FieldPosition* pos, jpayne@69: UErrorCode& success) const; jpayne@69: jpayne@69: UnicodeString getArgName(int32_t partIndex); jpayne@69: jpayne@69: void setArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status); jpayne@69: jpayne@69: void setCustomArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status); jpayne@69: jpayne@69: int32_t nextTopLevelArgStart(int32_t partIndex) const; jpayne@69: jpayne@69: UBool argNameMatches(int32_t partIndex, const UnicodeString& argName, int32_t argNumber); jpayne@69: jpayne@69: void cacheExplicitFormats(UErrorCode& status); jpayne@69: jpayne@69: int32_t skipLeadingSpaces(UnicodeString& style); jpayne@69: jpayne@69: Format* createAppropriateFormat(UnicodeString& type, jpayne@69: UnicodeString& style, jpayne@69: Formattable::Type& formattableType, jpayne@69: UParseError& parseError, jpayne@69: UErrorCode& ec); jpayne@69: jpayne@69: const Formattable* getArgFromListByName(const Formattable* arguments, jpayne@69: const UnicodeString *argumentNames, jpayne@69: int32_t cnt, UnicodeString& name) const; jpayne@69: jpayne@69: Formattable* parse(int32_t msgStart, jpayne@69: const UnicodeString& source, jpayne@69: ParsePosition& pos, jpayne@69: int32_t& count, jpayne@69: UErrorCode& ec) const; jpayne@69: jpayne@69: FieldPosition* updateMetaData(AppendableWrapper& dest, int32_t prevLength, jpayne@69: FieldPosition* fp, const Formattable* argId) const; jpayne@69: jpayne@69: /** jpayne@69: * Finds the "other" sub-message. jpayne@69: * @param partIndex the index of the first PluralFormat argument style part. jpayne@69: * @return the "other" sub-message start part index. jpayne@69: */ jpayne@69: int32_t findOtherSubMessage(int32_t partIndex) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the ARG_START index of the first occurrence of the plural number in a sub-message. jpayne@69: * Returns -1 if it is a REPLACE_NUMBER. jpayne@69: * Returns 0 if there is neither. jpayne@69: */ jpayne@69: int32_t findFirstPluralNumberArg(int32_t msgStart, const UnicodeString &argName) const; jpayne@69: jpayne@69: Format* getCachedFormatter(int32_t argumentNumber) const; jpayne@69: jpayne@69: UnicodeString getLiteralStringUntilNextArgument(int32_t from) const; jpayne@69: jpayne@69: void copyObjects(const MessageFormat& that, UErrorCode& ec); jpayne@69: jpayne@69: void formatComplexSubMessage(int32_t msgStart, jpayne@69: const void *plNumber, jpayne@69: const Formattable* arguments, jpayne@69: const UnicodeString *argumentNames, jpayne@69: int32_t cnt, jpayne@69: AppendableWrapper& appendTo, jpayne@69: UErrorCode& success) const; jpayne@69: jpayne@69: /** jpayne@69: * Convenience method that ought to be in NumberFormat jpayne@69: */ jpayne@69: NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns array of argument types in the parsed pattern jpayne@69: * for use in C API. Only for the use of umsg_vformat(). Not jpayne@69: * for public consumption. jpayne@69: * @param listCount Output parameter to receive the size of array jpayne@69: * @return The array of formattable types in the pattern jpayne@69: */ jpayne@69: const Formattable::Type* getArgTypeList(int32_t& listCount) const { jpayne@69: listCount = argTypeCount; jpayne@69: return argTypes; jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * Resets the internal MessagePattern, and other associated caches. jpayne@69: */ jpayne@69: void resetPattern(); jpayne@69: jpayne@69: /** jpayne@69: * A DummyFormatter that we use solely to store a NULL value. UHash does jpayne@69: * not support storing NULL values. jpayne@69: */ jpayne@69: class U_I18N_API DummyFormat : public Format { jpayne@69: public: jpayne@69: virtual UBool operator==(const Format&) const; jpayne@69: virtual DummyFormat* clone() const; jpayne@69: virtual UnicodeString& format(const Formattable& obj, jpayne@69: UnicodeString& appendTo, jpayne@69: UErrorCode& status) const; jpayne@69: virtual UnicodeString& format(const Formattable&, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPosition&, jpayne@69: UErrorCode& status) const; jpayne@69: virtual UnicodeString& format(const Formattable& obj, jpayne@69: UnicodeString& appendTo, jpayne@69: FieldPositionIterator* posIter, jpayne@69: UErrorCode& status) const; jpayne@69: virtual void parseObject(const UnicodeString&, jpayne@69: Formattable&, jpayne@69: ParsePosition&) const; jpayne@69: }; jpayne@69: jpayne@69: friend class MessageFormatAdapter; // getFormatTypeList() access 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 // _MSGFMT jpayne@69: //eof