1999-12-28 23:57:50 +00:00
|
|
|
/*
|
2004-05-19 20:42:44 +00:00
|
|
|
* Copyright (C) {1997-2004}, International Business Machines Corporation and others. All Rights Reserved.
|
1999-12-28 23:57:50 +00:00
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
* File MSGFMT.H
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/19/97 aliu Converted from java.
|
|
|
|
* 03/20/97 helena Finished first cut of implementation.
|
2001-08-16 00:55:51 +00:00
|
|
|
* 07/22/98 stephen Removed operator!= (defined in Format)
|
2002-08-20 15:59:07 +00:00
|
|
|
* 08/19/2002 srl Removing Javaisms
|
1999-12-28 23:57:50 +00:00
|
|
|
********************************************************************************
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#ifndef MSGFMT_H
|
|
|
|
#define MSGFMT_H
|
2001-03-22 00:09:10 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/format.h"
|
|
|
|
#include "unicode/locid.h"
|
2001-08-16 00:55:51 +00:00
|
|
|
#include "unicode/parseerr.h"
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
class NumberFormat;
|
2003-02-05 00:53:44 +00:00
|
|
|
class DateFormat;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* A MessageFormat produces concatenated messages in a
|
|
|
|
* language-neutral way. It should be used for all string
|
|
|
|
* concatenations that are visible to end users.
|
1999-12-28 23:57:50 +00:00
|
|
|
* <P>
|
2003-01-28 22:16:10 +00:00
|
|
|
* A MessageFormat contains an array of <EM>subformats</EM> arranged
|
|
|
|
* within a <EM>template string</EM>. Together, the subformats and
|
|
|
|
* template string determine how the MessageFormat will operate during
|
|
|
|
* formatting and parsing.
|
1999-12-28 23:57:50 +00:00
|
|
|
* <P>
|
2003-01-28 22:16:10 +00:00
|
|
|
* Typically, both the subformats and the template string are
|
|
|
|
* specified at once in a <EM>pattern</EM>. By using different
|
|
|
|
* patterns for different locales, messages may be localized.
|
|
|
|
* <P>
|
|
|
|
* During formatting, the MessageFormat takes an array of arguments
|
|
|
|
* and produces a user-readable string. Each argument is a
|
|
|
|
* Formattable object; they may be passed in in an array, or as a
|
|
|
|
* single Formattable object which itself contains an array. Each
|
|
|
|
* argument is matched up with its corresponding subformat, which then
|
|
|
|
* formats it into a string. The resultant strings are then assembled
|
|
|
|
* within the string template of the MessageFormat to produce the
|
|
|
|
* final output string.
|
|
|
|
* <P>
|
|
|
|
* During parsing, an input string is matched against the string
|
|
|
|
* template of the MessageFormat to produce an array of Formattable
|
|
|
|
* objects. Plain text of the template string is matched directly
|
|
|
|
* against intput text. At each position in the template string where
|
|
|
|
* a subformat is located, the subformat is called to parse the
|
|
|
|
* corresponding segment of input text to produce an output argument.
|
|
|
|
* In this way, an array of arguments is created which together
|
|
|
|
* constitute the parse result.
|
|
|
|
* <P>
|
|
|
|
* Parsing may fail or produce unexpected results in a number of
|
|
|
|
* circumstances.
|
|
|
|
* <UL>
|
|
|
|
* <LI>If one of the arguments does not occur in the pattern, it
|
|
|
|
* will be returned as a default Formattable.
|
|
|
|
* <LI>If the format of an argument is loses information, such as with
|
|
|
|
* a choice format where a large number formats to "many", then the
|
|
|
|
* parse may not correspond to the originally formatted argument.
|
|
|
|
* <LI>MessageFormat does not handle ChoiceFormat recursion during
|
|
|
|
* parsing; such parses will fail.
|
|
|
|
* <LI>Parsing will not always find a match (or the correct match) if
|
|
|
|
* some part of the parse is ambiguous. For example, if the pattern
|
|
|
|
* "{1},{2}" is used with the string arguments {"a,b", "c"}, it will
|
|
|
|
* format as "a,b,c". When the result is parsed, it will return {"a",
|
|
|
|
* "b,c"}.
|
|
|
|
* <LI>If a single argument is formatted more than once in the string,
|
|
|
|
* then the rightmost subformat in the pattern string will produce the
|
|
|
|
* parse result; prior subformats with the same argument index will
|
|
|
|
* have no effect.
|
|
|
|
* </UL>
|
1999-12-28 23:57:50 +00:00
|
|
|
* Here are some examples of usage:
|
2003-01-28 22:16:10 +00:00
|
|
|
* <P>
|
1999-12-28 23:57:50 +00:00
|
|
|
* Example 1:
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* UErrorCode success = U_ZERO_ERROR;
|
|
|
|
* GregorianCalendar cal(success);
|
|
|
|
* Formattable arguments[] = {
|
|
|
|
* 7L,
|
|
|
|
* Formattable( (Date) cal.getTime(success), Formattable::kIsDate),
|
|
|
|
* "a disturbance in the Force"
|
|
|
|
* };
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* UnicodeString result;
|
|
|
|
* MessageFormat::format(
|
|
|
|
* "At {1,time} on {1,date}, there was {2} on planet {0,number}.",
|
|
|
|
* arguments, 3, result, success );
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2001-03-19 22:30:38 +00:00
|
|
|
* cout << "result: " << result << endl;
|
|
|
|
* //<output>: At 4:34:20 PM on 23-Mar-98, there was a disturbance
|
2000-12-08 18:46:55 +00:00
|
|
|
* // in the Force on planet 7.
|
|
|
|
* \endcode
|
2001-03-22 00:09:10 +00:00
|
|
|
* </pre>
|
1999-12-28 23:57:50 +00:00
|
|
|
* Typically, the message format will come from resources, and the
|
|
|
|
* arguments will be dynamically set at runtime.
|
|
|
|
* <P>
|
|
|
|
* Example 2:
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* success = U_ZERO_ERROR;
|
|
|
|
* Formattable testArgs[] = {3L, "MyDisk"};
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2003-01-28 22:16:10 +00:00
|
|
|
* MessageFormat form(
|
2000-12-08 18:46:55 +00:00
|
|
|
* "The disk \"{1}\" contains {0} file(s).", success );
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* UnicodeString string;
|
|
|
|
* FieldPosition fpos = 0;
|
2003-01-28 22:16:10 +00:00
|
|
|
* cout << "format: " << form.format(testArgs, 2, string, fpos, success ) << endl;
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* // 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).
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* The pattern is of the following form. Legend:
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* {optional item}
|
|
|
|
* (group that may be repeated)*
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
|
|
|
* Do not confuse optional items with items inside quotes braces, such
|
|
|
|
* as this: "{". Quoted braces are literals.
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* messageFormatPattern := string ( "{" messageFormatElement "}" string )*
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2003-01-28 22:16:10 +00:00
|
|
|
* messageFormatElement := argumentIndex { "," elementFormat }
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* elementFormat := "time" { "," datetimeStyle }
|
|
|
|
* | "date" { "," datetimeStyle }
|
|
|
|
* | "number" { "," numberStyle }
|
|
|
|
* | "choice" "," choiceStyle
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* datetimeStyle := "short"
|
|
|
|
* | "medium"
|
|
|
|
* | "long"
|
|
|
|
* | "full"
|
|
|
|
* | dateFormatPattern
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* numberStyle := "currency"
|
|
|
|
* | "percent"
|
|
|
|
* | "integer"
|
|
|
|
* | numberFormatPattern
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* choiceStyle := choiceFormatPattern
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
|
|
|
* If there is no elementFormat, then the argument must be a string,
|
|
|
|
* which is substituted. If there is no dateTimeStyle or numberStyle,
|
2002-08-20 15:59:07 +00:00
|
|
|
* then the default format is used (e.g. NumberFormat::createInstance(),
|
|
|
|
* DateFormat::createTimeInstance(DateFormat::kDefault, ...) or DateFormat::createDateInstance(DateFormat::kDefault, ...). For
|
1999-12-28 23:57:50 +00:00
|
|
|
* a ChoiceFormat, the pattern must always be specified, since there
|
|
|
|
* is no default.
|
|
|
|
* <P>
|
2003-01-28 22:16:10 +00:00
|
|
|
* In strings, single quotes can be used to quote syntax characters.
|
|
|
|
* A literal single quote is represented by '', both within and outside
|
|
|
|
* of single-quoted segments. Inside a
|
|
|
|
* messageFormatElement, quotes are <EM>not</EM> removed. For example,
|
1999-12-28 23:57:50 +00:00
|
|
|
* {1,number,$'#',##} will produce a number format with the pound-sign
|
|
|
|
* quoted, with a result such as: "$#31,45".
|
|
|
|
* <P>
|
|
|
|
* If a pattern is used, then unquoted braces in the pattern, if any,
|
|
|
|
* must match: that is, "ab {0} de" and "ab '}' de" are ok, but "ab
|
|
|
|
* {0'}' de" and "ab } de" are not.
|
|
|
|
* <P>
|
2003-01-28 22:16:10 +00:00
|
|
|
* The argumentIndex is a non-negative integer, which corresponds to the
|
|
|
|
* index of the arguments presented in an array to be formatted. The
|
|
|
|
* first argument has argumentIndex 0.
|
1999-12-28 23:57:50 +00:00
|
|
|
* <P>
|
2003-01-28 22:16:10 +00:00
|
|
|
* It is acceptable to have unused arguments in the array. With missing
|
1999-12-28 23:57:50 +00:00
|
|
|
* arguments or arguments that are not of the right class for the
|
|
|
|
* specified format, a failing UErrorCode result is set.
|
|
|
|
* <P>
|
|
|
|
* For more sophisticated patterns, you can use a ChoiceFormat to get
|
2003-01-28 22:16:10 +00:00
|
|
|
* output:
|
1999-12-28 23:57:50 +00:00
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* UErrorCode success = U_ZERO_ERROR;
|
2003-01-28 22:16:10 +00:00
|
|
|
* MessageFormat* form("The disk \"{1}\" contains {0}.", success);
|
2000-12-08 18:46:55 +00:00
|
|
|
* double filelimits[] = {0,1,2};
|
|
|
|
* UnicodeString filepart[] = {"no files","one file","{0,number} files"};
|
|
|
|
* ChoiceFormat* fileform = new ChoiceFormat(filelimits, filepart, 3);
|
2003-01-28 22:16:10 +00:00
|
|
|
* form.setFormat(1, *fileform); // NOT zero, see below
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* Formattable testArgs[] = {1273L, "MyDisk"};
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* UnicodeString string;
|
|
|
|
* FieldPosition fpos = 0;
|
2003-01-28 22:16:10 +00:00
|
|
|
* cout << form.format(testArgs, 2, string, fpos, success) << endl;
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* // output, with different testArgs
|
|
|
|
* // output: The disk "MyDisk" contains no files.
|
|
|
|
* // output: The disk "MyDisk" contains one file.
|
|
|
|
* // output: The disk "MyDisk" contains 1,273 files.
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
|
|
|
* You can either do this programmatically, as in the above example,
|
|
|
|
* or by using a pattern (see ChoiceFormat for more information) as in:
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
2003-01-28 22:16:10 +00:00
|
|
|
* form.applyPattern(
|
2001-03-19 22:30:38 +00:00
|
|
|
* "There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.");
|
2000-12-08 18:46:55 +00:00
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
|
|
|
* <P>
|
2003-01-28 22:16:10 +00:00
|
|
|
* <EM>Note:</EM> As we see above, the string produced by a ChoiceFormat in
|
|
|
|
* MessageFormat is treated specially; occurences of '{' are used to
|
1999-12-28 23:57:50 +00:00
|
|
|
* indicated subformats, and cause recursion. If you create both a
|
|
|
|
* MessageFormat and ChoiceFormat programmatically (instead of using
|
|
|
|
* the string patterns), then be careful not to produce a format that
|
|
|
|
* recurses on itself, which will cause an infinite loop.
|
|
|
|
* <P>
|
2004-04-01 19:05:57 +00:00
|
|
|
* <EM>Note:</EM> Subformats are numbered by their order in the pattern.
|
2003-01-28 22:16:10 +00:00
|
|
|
* This is <EM>not</EM> the same as the argumentIndex.
|
1999-12-28 23:57:50 +00:00
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* For example: with "abc{2}def{3}ghi{0}...",
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
* format0 affects the first variable {2}
|
|
|
|
* format1 affects the second variable {3}
|
|
|
|
* format2 affects the second variable {0}
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
2004-04-01 19:05:57 +00:00
|
|
|
*
|
|
|
|
* <p><em>User subclasses are not supported.</em> While clients may write
|
|
|
|
* subclasses, such code will not necessarily work and will not be
|
|
|
|
* guaranteed to work stably from release to release.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
class U_I18N_API MessageFormat : public Format {
|
|
|
|
public:
|
2003-01-27 17:27:40 +00:00
|
|
|
/**
|
|
|
|
* Enum type for kMaxFormat.
|
|
|
|
* @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6,
|
|
|
|
* rendering this enum type obsolete.
|
|
|
|
*/
|
|
|
|
enum EFormatNumber {
|
|
|
|
/**
|
|
|
|
* The maximum number of arguments.
|
|
|
|
* @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6,
|
|
|
|
* rendering this constant obsolete.
|
|
|
|
*/
|
|
|
|
kMaxFormat = 10
|
|
|
|
};
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Constructs a new MessageFormat using the given pattern and the
|
|
|
|
* default locale.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
|
|
|
* @param pattern Pattern used to construct object.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param status Input/output error code. If the
|
1999-12-28 23:57:50 +00:00
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
MessageFormat(const UnicodeString& pattern,
|
|
|
|
UErrorCode &status);
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Constructs a new MessageFormat using the given pattern and locale.
|
1999-12-28 23:57:50 +00:00
|
|
|
* @param pattern Pattern used to construct object.
|
|
|
|
* @param newLocale The locale to use for formatting dates and numbers.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param status Input/output error code. If the
|
1999-12-28 23:57:50 +00:00
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
MessageFormat(const UnicodeString& pattern,
|
|
|
|
const Locale& newLocale,
|
2003-05-09 23:55:38 +00:00
|
|
|
UErrorCode& status);
|
2001-08-16 00:55:51 +00:00
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Constructs a new MessageFormat using the given pattern and locale.
|
2001-08-16 00:55:51 +00:00
|
|
|
* @param pattern Pattern used to construct object.
|
|
|
|
* @param newLocale The locale to use for formatting dates and numbers.
|
|
|
|
* @param parseError Struct to recieve information on position
|
2003-01-28 22:16:10 +00:00
|
|
|
* of error within the pattern.
|
|
|
|
* @param status Input/output error code. If the
|
2001-08-16 00:55:51 +00:00
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2001-08-16 00:55:51 +00:00
|
|
|
*/
|
|
|
|
MessageFormat(const UnicodeString& pattern,
|
|
|
|
const Locale& newLocale,
|
|
|
|
UParseError& parseError,
|
2003-05-09 23:55:38 +00:00
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Constructs a new MessageFormat from an existing one.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
MessageFormat(const MessageFormat&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
const MessageFormat& operator=(const MessageFormat&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual ~MessageFormat();
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Clones this Format object polymorphically. The caller owns the
|
1999-12-28 23:57:50 +00:00
|
|
|
* result and should delete it when done.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual Format* clone(void) const;
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Returns true if the given Format objects are semantically equal.
|
1999-12-28 23:57:50 +00:00
|
|
|
* Objects of different subclasses are considered unequal.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param other the object to be compared with.
|
|
|
|
* @return true if the given Format objects are semantically equal.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool operator==(const Format& other) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the locale. This locale is used for fetching default number or date
|
|
|
|
* format information.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param theLocale the new locale value to be set.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual void setLocale(const Locale& theLocale);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the locale. This locale is used for fetching default number or date
|
|
|
|
* format information.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the locale of the object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual const Locale& getLocale(void) const;
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Applies the given pattern string to this message format.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
|
|
|
* @param pattern The pattern to be applied.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param status Input/output error code. If the
|
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual void applyPattern(const UnicodeString& pattern,
|
|
|
|
UErrorCode& status);
|
2001-08-16 00:55:51 +00:00
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Applies the given pattern string to this message format.
|
|
|
|
*
|
2001-08-16 00:55:51 +00:00
|
|
|
* @param pattern The pattern to be applied.
|
|
|
|
* @param parseError Struct to recieve information on position
|
2003-01-28 22:16:10 +00:00
|
|
|
* of error within pattern.
|
|
|
|
* @param status Input/output error code. If the
|
|
|
|
* pattern cannot be parsed, set to failure code.
|
2003-06-04 00:04:35 +00:00
|
|
|
* @stable ICU 2.0
|
2001-08-16 00:55:51 +00:00
|
|
|
*/
|
|
|
|
virtual void applyPattern(const UnicodeString& pattern,
|
|
|
|
UParseError& parseError,
|
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Returns a pattern that can be used to recreate this object.
|
|
|
|
*
|
2002-11-23 01:11:50 +00:00
|
|
|
* @param appendTo Output parameter to receive the pattern.
|
|
|
|
* Result is appended to existing contents.
|
|
|
|
* @return Reference to 'appendTo' parameter.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-11-23 01:11:50 +00:00
|
|
|
virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Sets subformats.
|
1999-12-28 23:57:50 +00:00
|
|
|
* See the class description about format numbering.
|
|
|
|
* The caller should not delete the Format objects after this call.
|
2003-01-28 22:16:10 +00:00
|
|
|
* <EM>The array formatsToAdopt is not itself adopted.</EM> Its
|
2003-01-27 17:27:40 +00:00
|
|
|
* 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.
|
2002-08-12 15:20:40 +00:00
|
|
|
*
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param formatsToAdopt the format to be adopted.
|
|
|
|
* @param count the size of the array.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Sets subformats.
|
1999-12-28 23:57:50 +00:00
|
|
|
* See the class description about format numbering.
|
2002-08-12 15:20:40 +00:00
|
|
|
* Each item in the array is cloned into the internal array.
|
2003-01-27 17:27:40 +00:00
|
|
|
* If the call fails because memory cannot be allocated, then this
|
|
|
|
* object will remain unchanged.
|
2002-08-12 15:20:40 +00:00
|
|
|
*
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param newFormats the new format to be set.
|
|
|
|
* @param cnt the size of the array.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual void setFormats(const Format** newFormats,int32_t cnt);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Sets one subformat.
|
1999-12-28 23:57:50 +00:00
|
|
|
* See the class description about format numbering.
|
|
|
|
* The caller should not delete the Format object after this call.
|
2002-08-12 15:20:40 +00:00
|
|
|
* If the number is over the number of formats already set,
|
|
|
|
* the item will be deleted and ignored.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param formatNumber index of the subformat.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param formatToAdopt the format to be adopted.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Sets one subformat.
|
1999-12-28 23:57:50 +00:00
|
|
|
* See the class description about format numbering.
|
2002-08-12 15:20:40 +00:00
|
|
|
* If the number is over the number of formats already set,
|
|
|
|
* the item will be ignored.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param formatNumber index of the subformat.
|
|
|
|
* @param format the format to be set.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-01-28 22:16:10 +00:00
|
|
|
virtual void setFormat(int32_t formatNumber, const Format& format);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* 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 any method of this class is made with
|
|
|
|
* this object. See the class description about format numbering.
|
|
|
|
* @param count output parameter to receive the size of the array
|
|
|
|
* @return an array of count Format* objects, or NULL if out of
|
|
|
|
* memory. Any or all of the array elements may be NULL.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual const Format** getFormats(int32_t& count) const;
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Formats the given array of arguments into a user-readable string.
|
|
|
|
* Does not take ownership of the Formattable* array or its contents.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param source An array of objects to be formatted.
|
|
|
|
* @param count The number of elements of 'source'.
|
2002-11-23 01:11:50 +00:00
|
|
|
* @param appendTo Output parameter to receive result.
|
|
|
|
* Result is appended to existing contents.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param ignore Not used; inherited from base class API.
|
|
|
|
* @param status Input/output error code. If the
|
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-11-23 01:11:50 +00:00
|
|
|
* @return Reference to 'appendTo' parameter.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeString& format( const Formattable* source,
|
|
|
|
int32_t count,
|
2002-11-23 01:11:50 +00:00
|
|
|
UnicodeString& appendTo,
|
1999-12-28 23:57:50 +00:00
|
|
|
FieldPosition& ignore,
|
2003-01-28 22:16:10 +00:00
|
|
|
UErrorCode& status) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Formats the given array of arguments into a user-readable string
|
|
|
|
* using the given pattern.
|
|
|
|
*
|
|
|
|
* @param pattern The pattern.
|
2003-05-09 23:55:38 +00:00
|
|
|
* @param arguments An array of objects to be formatted.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param count The number of elements of 'source'.
|
2002-11-23 01:11:50 +00:00
|
|
|
* @param appendTo Output parameter to receive result.
|
|
|
|
* Result is appended to existing contents.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param status Input/output error code. If the
|
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-11-23 01:11:50 +00:00
|
|
|
* @return Reference to 'appendTo' parameter.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
static UnicodeString& format( const UnicodeString& pattern,
|
|
|
|
const Formattable* arguments,
|
|
|
|
int32_t count,
|
2002-11-23 01:11:50 +00:00
|
|
|
UnicodeString& appendTo,
|
2003-01-28 22:16:10 +00:00
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* 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.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param obj A Formattable of type kArray containing
|
|
|
|
* arguments to be formatted.
|
2002-11-23 01:11:50 +00:00
|
|
|
* @param appendTo Output parameter to receive result.
|
|
|
|
* Result is appended to existing contents.
|
|
|
|
* @param pos On input: an alignment field, if desired.
|
|
|
|
* On output: the offsets of the alignment field.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param status Input/output error code. If the
|
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-11-23 01:11:50 +00:00
|
|
|
* @return Reference to 'appendTo' parameter.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual UnicodeString& format(const Formattable& obj,
|
2002-11-23 01:11:50 +00:00
|
|
|
UnicodeString& appendTo,
|
1999-12-28 23:57:50 +00:00
|
|
|
FieldPosition& pos,
|
|
|
|
UErrorCode& status) const;
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2002-11-23 01:11:50 +00:00
|
|
|
* @param obj The object to format
|
|
|
|
* @param appendTo Output parameter to receive result.
|
|
|
|
* Result is appended to existing contents.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param status Input/output error code. If the
|
|
|
|
* pattern cannot be parsed, set to failure code.
|
2002-11-23 01:11:50 +00:00
|
|
|
* @return Reference to 'appendTo' parameter.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeString& format(const Formattable& obj,
|
2002-11-23 01:11:50 +00:00
|
|
|
UnicodeString& appendTo,
|
1999-12-28 23:57:50 +00:00
|
|
|
UErrorCode& status) const;
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Parses the given string into an array of output arguments.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
|
|
|
* @param source String to be parsed.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param pos On input, starting position for parse. On output,
|
|
|
|
* final position after parse. Unchanged if parse
|
|
|
|
* fails.
|
|
|
|
* @param count Output parameter to receive the number of arguments
|
|
|
|
* parsed.
|
|
|
|
* @return an array of parsed arguments. The caller owns both
|
|
|
|
* the array and its contents.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual Formattable* parse( const UnicodeString& source,
|
2003-01-28 22:16:10 +00:00
|
|
|
ParsePosition& pos,
|
1999-12-28 23:57:50 +00:00
|
|
|
int32_t& count) const;
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Parses the given string into an array of output arguments.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
|
|
|
* @param source String to be parsed.
|
|
|
|
* @param count Output param to receive size of returned array.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param status Input/output error code. If the
|
|
|
|
* pattern cannot be parsed, set to failure code.
|
|
|
|
* @return an array of parsed arguments. The caller owns both
|
|
|
|
* the array and its contents.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual Formattable* parse( const UnicodeString& source,
|
|
|
|
int32_t& count,
|
|
|
|
UErrorCode& status) const;
|
|
|
|
|
|
|
|
/**
|
2003-01-28 22:16:10 +00:00
|
|
|
* Parses the given string into an array of output arguments
|
|
|
|
* stored within a single Formattable of type kArray.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
|
|
|
* @param source The string to be parsed into an object.
|
|
|
|
* @param result Formattable to be set to the parse result.
|
|
|
|
* If parse fails, return contents are undefined.
|
2003-01-28 22:16:10 +00:00
|
|
|
* @param pos On input, starting position for parse. On output,
|
|
|
|
* final position after parse. Unchanged if parse
|
|
|
|
* fails.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual void parseObject(const UnicodeString& source,
|
|
|
|
Formattable& result,
|
2003-01-28 22:16:10 +00:00
|
|
|
ParsePosition& pos) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @return The class ID for this object. All objects of a
|
|
|
|
* given class have the same class ID. Objects of
|
|
|
|
* other classes have different class IDs.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the class ID for this class. This is useful only for
|
|
|
|
* comparing to a return value from getDynamicClassID(). For example:
|
|
|
|
* <pre>
|
|
|
|
* . Base* polymorphic_pointer = createPolymorphicObject();
|
|
|
|
* . if (polymorphic_pointer->getDynamicClassID() ==
|
|
|
|
* . Derived::getStaticClassID()) ...
|
|
|
|
* </pre>
|
|
|
|
* @return The class ID for all objects of this class.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2004-08-24 17:38:33 +00:00
|
|
|
static UClassID U_EXPORT2 getStaticClassID(void);
|
2001-08-16 00:55:51 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
private:
|
2001-08-16 00:55:51 +00:00
|
|
|
|
2003-01-27 17:27:40 +00:00
|
|
|
Locale fLocale;
|
|
|
|
UnicodeString fPattern;
|
2003-01-28 22:16:10 +00:00
|
|
|
Format** formatAliases; // see getFormats
|
|
|
|
int32_t formatAliasesCapacity;
|
2003-01-27 17:27:40 +00:00
|
|
|
|
2003-05-04 01:40:40 +00:00
|
|
|
MessageFormat(); // default constructor not implemented
|
|
|
|
|
2003-12-16 21:26:12 +00:00
|
|
|
/*
|
2003-01-27 17:27:40 +00:00
|
|
|
* A structure representing one subformat of this MessageFormat.
|
|
|
|
* Each subformat has a Format object, an offset into the plain
|
|
|
|
* pattern text fPattern, and an argument number. The argument
|
|
|
|
* number corresponds to the array of arguments to be formatted.
|
2003-06-03 01:58:15 +00:00
|
|
|
* @internal
|
2003-01-27 17:27:40 +00:00
|
|
|
*/
|
2003-12-19 01:18:58 +00:00
|
|
|
class Subformat {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
Format* format; // formatter
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
int32_t offset; // offset into fPattern
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
int32_t arg; // 0-based argument number
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clone that.format and assign it to this.format
|
|
|
|
* Do NOT delete this.format
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
Subformat& operator=(const Subformat& that) {
|
|
|
|
format = that.format ? that.format->clone() : NULL;
|
|
|
|
offset = that.offset;
|
|
|
|
arg = that.arg;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
UBool operator==(const Subformat& that) const {
|
|
|
|
// Do cheap comparisons first
|
|
|
|
return offset == that.offset &&
|
|
|
|
arg == that.arg &&
|
|
|
|
((format == that.format) || // handles NULL
|
|
|
|
(*format == *that.format));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
UBool operator!=(const Subformat& that) const {
|
|
|
|
return !operator==(that);
|
|
|
|
}
|
|
|
|
};
|
2003-01-27 17:27:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A MessageFormat contains an array of subformats. This array
|
|
|
|
* needs to grow dynamically if the MessageFormat is modified.
|
2001-08-16 00:55:51 +00:00
|
|
|
*/
|
2003-01-27 17:27:40 +00:00
|
|
|
Subformat* subformats;
|
|
|
|
int32_t subformatCount;
|
|
|
|
int32_t subformatCapacity;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2002-07-01 11:04:45 +00:00
|
|
|
/**
|
2003-01-27 17:27:40 +00:00
|
|
|
* A MessageFormat formats an array of arguments. Each argument
|
|
|
|
* has an expected type, based on the pattern. For example, if
|
|
|
|
* the pattern contains the subformat "{3,number,integer}", then
|
|
|
|
* we expect argument 3 to have type Formattable::kLong. This
|
|
|
|
* array needs to grow dynamically if the MessageFormat is
|
|
|
|
* modified.
|
2002-07-01 11:04:45 +00:00
|
|
|
*/
|
2003-01-27 17:27:40 +00:00
|
|
|
Formattable::Type* argTypes;
|
|
|
|
int32_t argTypeCount;
|
|
|
|
int32_t argTypeCapacity;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2003-01-27 17:27:40 +00:00
|
|
|
// Variable-size array management
|
|
|
|
UBool allocateSubformats(int32_t capacity);
|
|
|
|
UBool allocateArgTypes(int32_t capacity);
|
2001-03-22 00:09:10 +00:00
|
|
|
|
2003-02-05 00:53:44 +00:00
|
|
|
/**
|
|
|
|
* Default Format objects used when no format is specified and a
|
|
|
|
* numeric or date argument is formatted. These are volatile
|
|
|
|
* cache objects maintained only for performance. They do not
|
|
|
|
* participate in operator=(), copy constructor(), nor
|
|
|
|
* operator==().
|
|
|
|
*/
|
|
|
|
NumberFormat* defaultNumberFormat;
|
|
|
|
DateFormat* defaultDateFormat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to retrieve default formats (or NULL on failure).
|
|
|
|
* These are semantically const, but may modify *this.
|
|
|
|
*/
|
2003-02-14 22:16:14 +00:00
|
|
|
const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
|
|
|
|
const DateFormat* getDefaultDateFormat(UErrorCode&) const;
|
2003-02-05 00:53:44 +00:00
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
/**
|
1999-12-28 23:57:50 +00:00
|
|
|
* Finds the word s, in the keyword list and returns the located index.
|
|
|
|
* @param s the keyword to be searched for.
|
|
|
|
* @param list the list of keywords to be searched with.
|
|
|
|
* @return the index of the list which matches the keyword s.
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
static int32_t findKeyword( const UnicodeString& s,
|
2003-01-27 17:27:40 +00:00
|
|
|
const UChar * const *list);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2002-11-23 01:11:50 +00:00
|
|
|
* Formats the array of arguments and copies the result into the
|
|
|
|
* result buffer, updates the field position.
|
|
|
|
*
|
|
|
|
* @param arguments The formattable objects array.
|
|
|
|
* @param cnt The array count.
|
|
|
|
* @param appendTo Output parameter to receive result.
|
|
|
|
* Result is appended to existing contents.
|
|
|
|
* @param status Field position status.
|
|
|
|
* @param recursionProtection
|
|
|
|
* Initially zero. Bits 0..9 are used to indicate
|
|
|
|
* that a parameter has already been seen, to
|
|
|
|
* avoid recursion. Currently unused.
|
|
|
|
* @param success The error code status.
|
|
|
|
* @return Reference to 'appendTo' parameter.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
UnicodeString& format( const Formattable* arguments,
|
|
|
|
int32_t cnt,
|
2002-11-23 01:11:50 +00:00
|
|
|
UnicodeString& appendTo,
|
2001-03-22 00:09:10 +00:00
|
|
|
FieldPosition& status,
|
1999-12-28 23:57:50 +00:00
|
|
|
int32_t recursionProtection,
|
|
|
|
UErrorCode& success) const;
|
|
|
|
|
2003-01-27 17:27:40 +00:00
|
|
|
void makeFormat(int32_t offsetNumber,
|
2001-03-22 00:09:10 +00:00
|
|
|
UnicodeString* segments,
|
2001-08-16 00:55:51 +00:00
|
|
|
UParseError& parseError,
|
1999-12-28 23:57:50 +00:00
|
|
|
UErrorCode& success);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method that ought to be in NumberFormat
|
|
|
|
*/
|
|
|
|
NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the range of the source text to quote the special
|
|
|
|
* characters, { and ' and copy to target buffer.
|
|
|
|
* @param source
|
|
|
|
* @param start the text offset to start the process of in the source string
|
|
|
|
* @param end the text offset to end the process of in the source string
|
2002-11-23 01:11:50 +00:00
|
|
|
* @param appendTo Output parameter to receive result.
|
|
|
|
* Result is appended to existing contents.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-11-23 01:11:50 +00:00
|
|
|
static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target);
|
2003-01-28 22:16:10 +00:00
|
|
|
|
|
|
|
/**
|
2003-01-28 22:21:57 +00:00
|
|
|
* Returns array of argument types in the parsed pattern
|
2003-01-28 22:16:10 +00:00
|
|
|
* for use in C API. Only for the use of umsg_vformat(). Not
|
|
|
|
* for public consumption.
|
|
|
|
* @param listCount Output parameter to receive the size of array
|
|
|
|
* @return The array of formattable types in the pattern
|
|
|
|
* @internal
|
|
|
|
*/
|
2003-01-28 22:21:57 +00:00
|
|
|
const Formattable::Type* getArgTypeList(int32_t& listCount) const {
|
2003-01-28 22:16:10 +00:00
|
|
|
listCount = argTypeCount;
|
|
|
|
return argTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class MessageFormatAdapter; // getFormatTypeList() access
|
1999-12-28 23:57:50 +00:00
|
|
|
};
|
2001-03-22 00:09:10 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
inline UnicodeString&
|
|
|
|
MessageFormat::format(const Formattable& obj,
|
2002-11-23 01:11:50 +00:00
|
|
|
UnicodeString& appendTo,
|
1999-12-28 23:57:50 +00:00
|
|
|
UErrorCode& status) const {
|
2002-11-23 01:11:50 +00:00
|
|
|
return Format::format(obj, appendTo, status);
|
1999-12-28 23:57:50 +00:00
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#endif // _MSGFMT
|
|
|
|
//eof
|
2003-12-19 01:18:58 +00:00
|
|
|
|