ICU 72.1 72.1
|
#include <msgfmt.h>
Public Types | |
enum | EFormatNumber { kMaxFormat = 10 } |
Enum type for kMaxFormat. More... | |
Public Member Functions | |
MessageFormat (const UnicodeString &pattern, UErrorCode &status) | |
Constructs a new MessageFormat using the given pattern and the default locale. More... | |
MessageFormat (const UnicodeString &pattern, const Locale &newLocale, UErrorCode &status) | |
Constructs a new MessageFormat using the given pattern and locale. More... | |
MessageFormat (const UnicodeString &pattern, const Locale &newLocale, UParseError &parseError, UErrorCode &status) | |
Constructs a new MessageFormat using the given pattern and locale. More... | |
MessageFormat (const MessageFormat &) | |
Constructs a new MessageFormat from an existing one. More... | |
const MessageFormat & | operator= (const MessageFormat &) |
Assignment operator. More... | |
virtual | ~MessageFormat () |
Destructor. More... | |
virtual MessageFormat * | clone () const override |
Clones this Format object polymorphically. More... | |
virtual bool | operator== (const Format &other) const override |
Returns true if the given Format objects are semantically equal. More... | |
virtual void | setLocale (const Locale &theLocale) |
Sets the locale to be used for creating argument Format objects. More... | |
virtual const Locale & | getLocale (void) const |
Gets the locale used for creating argument Format objects. More... | |
virtual void | applyPattern (const UnicodeString &pattern, UErrorCode &status) |
Applies the given pattern string to this message format. More... | |
virtual void | applyPattern (const UnicodeString &pattern, UParseError &parseError, UErrorCode &status) |
Applies the given pattern string to this message format. More... | |
virtual void | applyPattern (const UnicodeString &pattern, UMessagePatternApostropheMode aposMode, UParseError *parseError, UErrorCode &status) |
Sets the UMessagePatternApostropheMode and the pattern used by this message format. More... | |
UMessagePatternApostropheMode | getApostropheMode () const |
virtual UnicodeString & | toPattern (UnicodeString &appendTo) const |
Returns a pattern that can be used to recreate this object. More... | |
virtual void | adoptFormats (Format **formatsToAdopt, int32_t count) |
Sets subformats. More... | |
virtual void | setFormats (const Format **newFormats, int32_t cnt) |
Sets subformats. More... | |
virtual void | adoptFormat (int32_t formatNumber, Format *formatToAdopt) |
Sets one subformat. More... | |
virtual void | setFormat (int32_t formatNumber, const Format &format) |
Sets one subformat. More... | |
virtual StringEnumeration * | getFormatNames (UErrorCode &status) |
Gets format names. More... | |
virtual Format * | getFormat (const UnicodeString &formatName, UErrorCode &status) |
Gets subformat pointer for given format name. More... | |
virtual void | setFormat (const UnicodeString &formatName, const Format &format, UErrorCode &status) |
Sets one subformat for given format name. More... | |
virtual void | adoptFormat (const UnicodeString &formatName, Format *formatToAdopt, UErrorCode &status) |
Sets one subformat for given format name. More... | |
virtual const Format ** | getFormats (int32_t &count) const |
Gets an array of subformats of this object. More... | |
UnicodeString & | format (const Formattable *source, int32_t count, UnicodeString &appendTo, FieldPosition &ignore, UErrorCode &status) const |
Formats the given array of arguments into a user-readable string. More... | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override |
Formats the given array of arguments into a user-readable string. More... | |
UnicodeString & | format (const UnicodeString *argumentNames, const Formattable *arguments, int32_t count, UnicodeString &appendTo, UErrorCode &status) const |
Formats the given array of arguments into a user-defined argument name array. More... | |
virtual Formattable * | parse (const UnicodeString &source, ParsePosition &pos, int32_t &count) const |
Parses the given string into an array of output arguments. More... | |
virtual Formattable * | parse (const UnicodeString &source, int32_t &count, UErrorCode &status) const |
Parses the given string into an array of output arguments. More... | |
virtual void | parseObject (const UnicodeString &source, Formattable &result, ParsePosition &pos) const override |
Parses the given string into an array of output arguments stored within a single Formattable of type kArray. More... | |
UBool | usesNamedArguments () const |
Returns true if this MessageFormat uses named arguments, and false otherwise. More... | |
int32_t | getArgTypeCount () const |
This API is for ICU internal use only. More... | |
virtual UClassID | getDynamicClassID (void) const override |
Returns a unique class ID POLYMORPHICALLY. More... | |
UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const |
Formats an object to produce a string. More... | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const=0 |
Format an object to produce a string. More... | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format an object to produce a string. More... | |
Public Member Functions inherited from icu::Format | |
virtual | ~Format () |
Destructor. More... | |
virtual bool | operator== (const Format &other) const =0 |
Return true if the given Format objects are semantically equal. More... | |
bool | operator!= (const Format &other) const |
Return true if the given Format objects are not semantically equal. More... | |
virtual Format * | clone () const =0 |
Clone this object polymorphically. More... | |
UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const |
Formats an object to produce a string. More... | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const =0 |
Format an object to produce a string. More... | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format an object to produce a string. More... | |
virtual void | parseObject (const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0 |
Parse a string to produce an object. More... | |
void | parseObject (const UnicodeString &source, Formattable &result, UErrorCode &status) const |
Parses a string to produce an object. More... | |
Locale | getLocale (ULocDataLocaleType type, UErrorCode &status) const |
Get the locale for this format object. More... | |
const char * | getLocaleID (ULocDataLocaleType type, UErrorCode &status) const |
Get the locale for this format object. More... | |
Public Member Functions inherited from icu::UObject | |
virtual | ~UObject () |
Destructor. More... | |
virtual UClassID | getDynamicClassID () const |
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More... | |
Static Public Member Functions | |
static UnicodeString & | format (const UnicodeString &pattern, const Formattable *arguments, int32_t count, UnicodeString &appendTo, UErrorCode &status) |
Formats the given array of arguments into a user-readable string using the given pattern. More... | |
static UnicodeString | autoQuoteApostrophe (const UnicodeString &pattern, UErrorCode &status) |
Convert an 'apostrophe-friendly' pattern into a standard pattern. More... | |
static UClassID | getStaticClassID (void) |
Return the class ID for this class. More... | |
static UBool | equalFormats (const void *left, const void *right) |
Compares two Format objects. More... | |
Friends | |
class | MessageFormatAdapter |
Additional Inherited Members | |
Protected Member Functions inherited from icu::Format | |
void | setLocaleIDs (const char *valid, const char *actual) |
Format () | |
Default constructor for subclass use only. More... | |
Format (const Format &) | |
Format & | operator= (const Format &) |
Static Protected Member Functions inherited from icu::Format | |
static void | syntaxError (const UnicodeString &pattern, int32_t pos, UParseError &parseError) |
Simple function for initializing a UParseError from a UnicodeString. More... | |
MessageFormat prepares strings for display to users, with optional arguments (variables/placeholders). The arguments can occur in any order, which is necessary for translation into languages with different grammars.
A MessageFormat is constructed from a pattern string with arguments in {curly braces} which will be replaced by formatted values.
MessageFormat
differs from the other Format
classes in that you create a MessageFormat
object with one of its constructors (not with a createInstance
style factory method). Factory methods aren't necessary because MessageFormat
itself doesn't implement locale-specific behavior. Any locale-specific behavior is defined by the pattern that you provide and the subformats used for inserted arguments.
Arguments can be named (using identifiers) or numbered (using small ASCII-digit integers). Some of the API methods work only with argument numbers and throw an exception if the pattern has named arguments (see usesNamedArguments()
).
An argument might not specify any format type. In this case, a numeric value is formatted with a default (for the locale) NumberFormat, and a date/time value is formatted with a default (for the locale) DateFormat.
An argument might specify a "simple" type for which the specified Format object is created, cached and used.
An argument might have a "complex" type with nested MessageFormat sub-patterns. During formatting, one of these sub-messages is selected according to the argument value and recursively formatted.
After construction, a custom Format object can be set for a top-level argument, overriding the default formatting and parsing behavior for that argument. However, custom formatting can be achieved more simply by writing a typeless argument in the pattern string and supplying it with a preformatted string value.
When formatting, MessageFormat takes a collection of argument values and writes an output string. The argument values may be passed as an array (when the pattern contains only numbered arguments) or as an array of names and and an array of arguments (which works for both named and numbered arguments).
Each argument is matched with one of the input values by array index or argument name and formatted according to its pattern specification (or using a custom Format object if one was set). A numbered pattern argument is matched with an argument name that contains that number as an ASCII-decimal-digit string (without leading zero).
MessageFormat
uses patterns of the following form:
message = messageText (argument messageText)* argument = noneArg | simpleArg | complexArg complexArg = choiceArg | pluralArg | selectArg | selectordinalArg noneArg = '{' argNameOrNumber '}' simpleArg = '{' argNameOrNumber ',' argType [',' argStyle] '}' choiceArg = '{' argNameOrNumber ',' "choice" ',' choiceStyle '}' pluralArg = '{' argNameOrNumber ',' "plural" ',' pluralStyle '}' selectArg = '{' argNameOrNumber ',' "select" ',' selectStyle '}' selectordinalArg = '{' argNameOrNumber ',' "selectordinal" ',' pluralStyle '}' choiceStyle: seeChoiceFormat
pluralStyle: seePluralFormat
selectStyle: seeSelectFormat
argNameOrNumber = argName | argNumber argName = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+ argNumber = '0' | ('1'..'9' ('0'..'9')*) argType = "number" | "date" | "time" | "spellout" | "ordinal" | "duration" argStyle = "short" | "medium" | "long" | "full" | "integer" | "currency" | "percent" | argStyleText | "::" argSkeletonText
UMessagePatternApostropheMode
Recommendation: Use the real apostrophe (single quote) character ’ (U+2019) for human-readable text, and use the ASCII apostrophe ' (U+0027) only in program syntax, like quoting in MessageFormat. See the annotations for U+0027 Apostrophe in The Unicode Standard.
The choice
argument type is deprecated. Use plural
arguments for proper plural selection, and select
arguments for simple selection among a fixed set of choices.
The argType
and argStyle
values are used to create a Format
instance for the format element. The following table shows how the values map to Format instances. Combinations not shown in the table are illegal. Any argStyleText
must be a valid pattern string for the Format subclass used.
argType | argStyle | resulting Format object |
---|---|---|
(none) | null | |
number | (none) | NumberFormat.createInstance(getLocale(), status) |
integer | NumberFormat.createInstance(getLocale(), kNumberStyle, status) | |
currency | NumberFormat.createCurrencyInstance(getLocale(), status) | |
percent | NumberFormat.createPercentInstance(getLocale(), status) | |
argStyleText | new DecimalFormat(argStyleText, new DecimalFormatSymbols(getLocale(), status), status) | |
argSkeletonText | NumberFormatter::forSkeleton(argSkeletonText, status).locale(getLocale()).toFormat(status) | |
date | (none) | DateFormat.createDateInstance(kDefault, getLocale(), status) |
short | DateFormat.createDateInstance(kShort, getLocale(), status) | |
medium | DateFormat.createDateInstance(kDefault, getLocale(), status) | |
long | DateFormat.createDateInstance(kLong, getLocale(), status) | |
full | DateFormat.createDateInstance(kFull, getLocale(), status) | |
argStyleText | new SimpleDateFormat(argStyleText, getLocale(), status) | |
argSkeletonText | DateFormat::createInstanceForSkeleton(argSkeletonText, getLocale(), status) | |
time | (none) | DateFormat.createTimeInstance(kDefault, getLocale(), status) |
short | DateFormat.createTimeInstance(kShort, getLocale(), status) | |
medium | DateFormat.createTimeInstance(kDefault, getLocale(), status) | |
long | DateFormat.createTimeInstance(kLong, getLocale(), status) | |
full | DateFormat.createTimeInstance(kFull, getLocale(), status) | |
argStyleText | new SimpleDateFormat(argStyleText, getLocale(), status) | |
spellout | argStyleText (optional) | new RuleBasedNumberFormat(URBNF_SPELLOUT, getLocale(), status) |
ordinal | argStyleText (optional) | new RuleBasedNumberFormat(URBNF_ORDINAL, getLocale(), status) |
duration | argStyleText (optional) | new RuleBasedNumberFormat(URBNF_DURATION, getLocale(), status) |
Arguments are formatted according to their type, using the default ICU formatters for those types, unless otherwise specified.
There are also several ways to control the formatting.
We recommend you use default styles, predefined style values, skeletons, or preformatted values, but not pattern strings or custom format objects.
For more details, see the ICU User Guide.
Here are some examples of usage: Example 1:
UErrorCode success = U_ZERO_ERROR;GregorianCalendar cal(success);Formattable arguments[] = {7L,Formattable( (Date) cal.getTime(success), Formattable::kIsDate),"a disturbance in the Force"};UnicodeString result;"At {1,time,::jmm} on {1,date,::dMMMM}, there was {2} on planet {0,number}.",arguments, 3, result, success );cout << "result: " << result << endl;//<output>: At 4:34 PM on March 23, there was a disturbance// in the Force on planet 7.Formattable objects can be passed to the Format class or its subclasses for formatting.Definition: fmtable.h:64Concrete class which provides the standard calendar used by most of the world.Definition: gregocal.h:153UnicodeString & format(const Formattable *source, int32_t count, UnicodeString &appendTo, FieldPosition &ignore, UErrorCode &status) constFormats the given array of arguments into a user-readable string.UnicodeString is a string class that stores Unicode characters directly and provides similar function...Definition: unistr.h:296
Typically, the message format will come from resources, and the arguments will be dynamically set at runtime.
Example 2:
success = U_ZERO_ERROR;Formattable testArgs[] = {3L, "MyDisk"};MessageFormat form("The disk \"{1}\" contains {0} file(s).", success );UnicodeString string;FieldPosition fpos = 0;cout << "format: " << form.format(testArgs, 2, string, fpos, success ) << endl;// output, with different testArgs:// output: The disk "MyDisk" contains 0 file(s).// output: The disk "MyDisk" contains 1 file(s).// output: The disk "MyDisk" contains 1,273 file(s).FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...Definition: fieldpos.h:110Definition: msgfmt.h:345
For messages that include plural forms, you can use a plural argument:
output: There are no files on disk "MyDisk". There are 3 files on "MyDisk".success = U_ZERO_ERROR;MessageFormat msgFmt("{num_files, plural, ""=0{There are no files on disk \"{disk_name}\".}""=1{There is one file on disk \"{disk_name}\".}""other{There are # files on disk \"{disk_name}\".}}",Locale("en"),success);FieldPosition fpos = 0;Formattable testArgs[] = {0L, "MyDisk"};UnicodeString result;cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);testArgs[0] = 3L;cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);A Locale object represents a specific geographical, political, or cultural region.Definition: locid.h:195
See PluralFormat
and PluralRules
for details.
MessageFormats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
icu::MessageFormat::MessageFormat | ( | const UnicodeString & | pattern, |
UErrorCode & | status | ||
) |
Constructs a new MessageFormat using the given pattern and the default locale.
pattern | Pattern used to construct object. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
icu::MessageFormat::MessageFormat | ( | const UnicodeString & | pattern, |
const Locale & | newLocale, | ||
UErrorCode & | status | ||
) |
Constructs a new MessageFormat using the given pattern and locale.
pattern | Pattern used to construct object. |
newLocale | The locale to use for formatting dates and numbers. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
icu::MessageFormat::MessageFormat | ( | const UnicodeString & | pattern, |
const Locale & | newLocale, | ||
UParseError & | parseError, | ||
UErrorCode & | status | ||
) |
Constructs a new MessageFormat using the given pattern and locale.
pattern | Pattern used to construct object. |
newLocale | The locale to use for formatting dates and numbers. |
parseError | Struct to receive information on the position of an error within the pattern. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
icu::MessageFormat::MessageFormat | ( | const MessageFormat & | ) |
Constructs a new MessageFormat from an existing one.
|
virtual |
Destructor.
|
virtual |
Sets one subformat for given format name.
See the class description about format name. This function supports both named and numbered arguments– if numbered, the formatName is the corresponding UnicodeStrings (e.g. "0", "1", "2"...). If there is no matched formatName or wrong type, the item will be ignored. The caller should not delete the Format object after this call.
formatName | Name of the subformat. |
formatToAdopt | Format to be adopted. |
status | output param set to success/failure code. |
|
virtual |
Sets one subformat.
See the class description about format numbering. The caller should not delete the Format object after this call. If the number is over the number of formats already set, the item will be deleted and ignored.
If this format uses named arguments, the new format is discarded and this format remains unchanged.
formatNumber | index of the subformat. |
formatToAdopt | the format to be adopted. |
|
virtual |
Sets subformats.
See the class description about format numbering. The caller should not delete the Format objects after this call. The array formatsToAdopt is not itself adopted. Its ownership is retained by the caller. If the call fails because memory cannot be allocated, then the formats will be deleted by this method, and this object will remain unchanged.
If this format uses named arguments, the new formats are discarded and this format remains unchanged.
formatsToAdopt | the format to be adopted. |
count | the size of the array. |
|
virtual |
Applies the given pattern string to this message format.
pattern | The pattern to be applied. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
|
virtual |
Sets the UMessagePatternApostropheMode and the pattern used by this message format.
Parses the pattern and caches Format objects for simple argument types. Patterns and their interpretation are specified in the class description.
This method is best used only once on a given object to avoid confusion about the mode, and after constructing the object with an empty pattern string to minimize overhead.
pattern | The pattern to be applied. |
aposMode | The new apostrophe mode. |
parseError | Struct to receive information on the position of an error within the pattern. Can be NULL. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
|
virtual |
Applies the given pattern string to this message format.
pattern | The pattern to be applied. |
parseError | Struct to receive information on the position of an error within the pattern. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
|
static |
Convert an 'apostrophe-friendly' pattern into a standard pattern.
Standard patterns treat all apostrophes as quotes, which is problematic in some languages, e.g. French, where apostrophe is commonly used. This utility assumes that only an unpaired apostrophe immediately before a brace is a true quote. Other unpaired apostrophes are paired, and the resulting standard pattern string is returned.
Note it is not guaranteed that the returned pattern is indeed a valid pattern. The only effect is to convert between patterns having different quoting semantics.
pattern | the 'apostrophe-friendly' patttern to convert |
status | Input/output error code. If the pattern cannot be parsed, the failure code is set. |
|
overridevirtual |
Clones this Format object polymorphically.
The caller owns the result and should delete it when done.
Implements icu::Format.
|
static |
|
overridevirtual |
Formats the given array of arguments into a user-readable string.
The array must be stored within a single Formattable object of type kArray. If the Formattable object type is not of type kArray, then returns a failing UErrorCode.
If this format uses named arguments, appendTo is unchanged and status is set to U_ILLEGAL_ARGUMENT_ERROR.
obj | A Formattable of type kArray containing arguments to be formatted. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
pos | On input: an alignment field, if desired. On output: the offsets of the alignment field. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
Implements icu::Format.
|
virtual |
Format an object to produce a string.
This is a pure virtual method which subclasses must implement. This method allows polymorphic formatting of Formattable objects. If a subclass of Format receives a Formattable object type it doesn't handle (e.g., if a numeric Formattable is passed to a DateFormat object) then it returns a failing UErrorCode.
obj | The object to format. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
pos | On input: an alignment field, if desired. On output: the offsets of the alignment field. |
status | Output param filled with success/failure status. |
Implements icu::Format.
|
virtual |
Format an object to produce a string.
Subclasses should override this method. This method allows polymorphic formatting of Formattable objects. If a subclass of Format receives a Formattable object type it doesn't handle (e.g., if a numeric Formattable is passed to a DateFormat object) then it returns a failing UErrorCode.
obj | The object to format. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
posIter | On return, can be used to iterate over positions of fields generated by this format call. |
status | Output param filled with success/failure status. |
Reimplemented from icu::Format.
UnicodeString & icu::Format::format | ( | const Formattable & | obj, |
UnicodeString & | appendTo, | ||
UErrorCode & | status | ||
) | const |
Formats an object to produce a string.
obj | The object to format. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
status | Output parameter filled in with success or failure status. |
UnicodeString & icu::MessageFormat::format | ( | const Formattable * | source, |
int32_t | count, | ||
UnicodeString & | appendTo, | ||
FieldPosition & | ignore, | ||
UErrorCode & | status | ||
) | const |
Formats the given array of arguments into a user-readable string.
Does not take ownership of the Formattable* array or its contents.
If this format uses named arguments, appendTo is unchanged and status is set to U_ILLEGAL_ARGUMENT_ERROR.
source | An array of objects to be formatted. |
count | The number of elements of 'source'. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
ignore | Not used; inherited from base class API. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
|
static |
Formats the given array of arguments into a user-readable string using the given pattern.
If this format uses named arguments, appendTo is unchanged and status is set to U_ILLEGAL_ARGUMENT_ERROR.
pattern | The pattern. |
arguments | An array of objects to be formatted. |
count | The number of elements of 'source'. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
UnicodeString & icu::MessageFormat::format | ( | const UnicodeString * | argumentNames, |
const Formattable * | arguments, | ||
int32_t | count, | ||
UnicodeString & | appendTo, | ||
UErrorCode & | status | ||
) | const |
Formats the given array of arguments into a user-defined argument name array.
This function supports both named and numbered arguments– if numbered, the formatName is the corresponding UnicodeStrings (e.g. "0", "1", "2"...).
argumentNames | argument name array |
arguments | An array of objects to be formatted. |
count | The number of elements of 'argumentNames' and arguments. The number of argumentNames and arguments must be the same. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
|
inline |
int32_t icu::MessageFormat::getArgTypeCount | ( | ) | const |
This API is for ICU internal use only.
Please do not use it.
Returns argument types count in the parsed pattern. Used to distinguish pattern "{0} d" and "d".
|
overridevirtual |
Returns a unique class ID POLYMORPHICALLY.
Pure virtual override. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphic operator==() and clone() methods call this method.
Reimplemented from icu::UObject.
|
virtual |
Gets subformat pointer for given format name.
This function supports both named and numbered arguments. If numbered, the formatName is the corresponding UnicodeStrings (e.g. "0", "1", "2"...). The returned Format object should not be deleted by the caller, nor should the pointer of other object . The pointer and its contents remain valid only until the next call to any method of this class is made with this object.
formatName | the name or number specifying a format |
status | output param set to success/failure code. |
|
virtual |
Gets format names.
This function returns formatNames in StringEnumerations which can be used with getFormat() and setFormat() to export formattable array from current MessageFormat to another. It is the caller's responsibility to delete the returned formatNames.
status | output param set to success/failure code. |
|
virtual |
Gets an array of subformats of this object.
The returned array should not be deleted by the caller, nor should the pointers within the array. The array and its contents remain valid only until the next call to this format. See the class description about format numbering.
count | output parameter to receive the size of the array |
|
virtual |
|
static |
Return the class ID for this class.
This is useful only for comparing to a return value from getDynamicClassID(). For example:
. Base* polymorphic_pointer = createPolymorphicObject(); . if (polymorphic_pointer->getDynamicClassID() == . Derived::getStaticClassID()) ...
const MessageFormat & icu::MessageFormat::operator= | ( | const MessageFormat & | ) |
Assignment operator.
|
overridevirtual |
Returns true if the given Format objects are semantically equal.
Objects of different subclasses are considered unequal.
other | the object to be compared with. |
Implements icu::Format.
|
virtual |
Parses the given string into an array of output arguments.
If this format uses named arguments, status is set to U_ARGUMENT_TYPE_MISMATCH.
source | String to be parsed. |
count | Output param to receive size of returned array. |
status | Input/output error code. If the pattern cannot be parsed, set to failure code. |
|
virtual |
Parses the given string into an array of output arguments.
source | String to be parsed. |
pos | On input, starting position for parse. On output, final position after parse. Unchanged if parse fails. |
count | Output parameter to receive the number of arguments parsed. |
|
overridevirtual |
Parses the given string into an array of output arguments stored within a single Formattable of type kArray.
source | The string to be parsed into an object. |
result | Formattable to be set to the parse result. If parse fails, return contents are undefined. |
pos | On input, starting position for parse. On output, final position after parse. Unchanged if parse fails. |
Implements icu::Format.
|
virtual |
Sets one subformat for given format name.
See the class description about format name. This function supports both named and numbered arguments– if numbered, the formatName is the corresponding UnicodeStrings (e.g. "0", "1", "2"...). If there is no matched formatName or wrong type, the item will be ignored.
formatName | Name of the subformat. |
format | the format to be set. |
status | output param set to success/failure code. |
|
virtual |
Sets one subformat.
See the class description about format numbering. If the number is over the number of formats already set, the item will be ignored.
formatNumber | index of the subformat. |
format | the format to be set. |
|
virtual |
Sets subformats.
See the class description about format numbering. Each item in the array is cloned into the internal array. If the call fails because memory cannot be allocated, then this object will remain unchanged.
If this format uses named arguments, the new formats are discarded and this format remains unchanged.
newFormats | the new format to be set. |
cnt | the size of the array. |
|
virtual |
|
virtual |
Returns a pattern that can be used to recreate this object.
appendTo | Output parameter to receive the pattern. Result is appended to existing contents. |
UBool icu::MessageFormat::usesNamedArguments | ( | ) | const |
Returns true if this MessageFormat uses named arguments, and false otherwise.
See class description.