intl/icu/source/i18n/unicode/msgfmt.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (C) 2007-2013, International Business Machines Corporation and
michael@0 3 * others. All Rights Reserved.
michael@0 4 ********************************************************************************
michael@0 5 *
michael@0 6 * File MSGFMT.H
michael@0 7 *
michael@0 8 * Modification History:
michael@0 9 *
michael@0 10 * Date Name Description
michael@0 11 * 02/19/97 aliu Converted from java.
michael@0 12 * 03/20/97 helena Finished first cut of implementation.
michael@0 13 * 07/22/98 stephen Removed operator!= (defined in Format)
michael@0 14 * 08/19/2002 srl Removing Javaisms
michael@0 15 *******************************************************************************/
michael@0 16
michael@0 17 #ifndef MSGFMT_H
michael@0 18 #define MSGFMT_H
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21
michael@0 22 /**
michael@0 23 * \file
michael@0 24 * \brief C++ API: Formats messages in a language-neutral way.
michael@0 25 */
michael@0 26
michael@0 27 #if !UCONFIG_NO_FORMATTING
michael@0 28
michael@0 29 #include "unicode/format.h"
michael@0 30 #include "unicode/locid.h"
michael@0 31 #include "unicode/messagepattern.h"
michael@0 32 #include "unicode/parseerr.h"
michael@0 33 #include "unicode/plurfmt.h"
michael@0 34 #include "unicode/plurrule.h"
michael@0 35
michael@0 36 U_CDECL_BEGIN
michael@0 37 // Forward declaration.
michael@0 38 struct UHashtable;
michael@0 39 typedef struct UHashtable UHashtable; /**< @internal */
michael@0 40 U_CDECL_END
michael@0 41
michael@0 42 U_NAMESPACE_BEGIN
michael@0 43
michael@0 44 class AppendableWrapper;
michael@0 45 class DateFormat;
michael@0 46 class NumberFormat;
michael@0 47
michael@0 48 /**
michael@0 49 * <p>MessageFormat prepares strings for display to users,
michael@0 50 * with optional arguments (variables/placeholders).
michael@0 51 * The arguments can occur in any order, which is necessary for translation
michael@0 52 * into languages with different grammars.
michael@0 53 *
michael@0 54 * <p>A MessageFormat is constructed from a <em>pattern</em> string
michael@0 55 * with arguments in {curly braces} which will be replaced by formatted values.
michael@0 56 *
michael@0 57 * <p><code>MessageFormat</code> differs from the other <code>Format</code>
michael@0 58 * classes in that you create a <code>MessageFormat</code> object with one
michael@0 59 * of its constructors (not with a <code>createInstance</code> style factory
michael@0 60 * method). Factory methods aren't necessary because <code>MessageFormat</code>
michael@0 61 * itself doesn't implement locale-specific behavior. Any locale-specific
michael@0 62 * behavior is defined by the pattern that you provide and the
michael@0 63 * subformats used for inserted arguments.
michael@0 64 *
michael@0 65 * <p>Arguments can be named (using identifiers) or numbered (using small ASCII-digit integers).
michael@0 66 * Some of the API methods work only with argument numbers and throw an exception
michael@0 67 * if the pattern has named arguments (see {@link #usesNamedArguments()}).
michael@0 68 *
michael@0 69 * <p>An argument might not specify any format type. In this case,
michael@0 70 * a Number value is formatted with a default (for the locale) NumberFormat,
michael@0 71 * a Date value is formatted with a default (for the locale) DateFormat,
michael@0 72 * and for any other value its toString() value is used.
michael@0 73 *
michael@0 74 * <p>An argument might specify a "simple" type for which the specified
michael@0 75 * Format object is created, cached and used.
michael@0 76 *
michael@0 77 * <p>An argument might have a "complex" type with nested MessageFormat sub-patterns.
michael@0 78 * During formatting, one of these sub-messages is selected according to the argument value
michael@0 79 * and recursively formatted.
michael@0 80 *
michael@0 81 * <p>After construction, a custom Format object can be set for
michael@0 82 * a top-level argument, overriding the default formatting and parsing behavior
michael@0 83 * for that argument.
michael@0 84 * However, custom formatting can be achieved more simply by writing
michael@0 85 * a typeless argument in the pattern string
michael@0 86 * and supplying it with a preformatted string value.
michael@0 87 *
michael@0 88 * <p>When formatting, MessageFormat takes a collection of argument values
michael@0 89 * and writes an output string.
michael@0 90 * The argument values may be passed as an array
michael@0 91 * (when the pattern contains only numbered arguments)
michael@0 92 * or as an array of names and and an array of arguments (which works for both named
michael@0 93 * and numbered arguments).
michael@0 94 *
michael@0 95 * <p>Each argument is matched with one of the input values by array index or argument name
michael@0 96 * and formatted according to its pattern specification
michael@0 97 * (or using a custom Format object if one was set).
michael@0 98 * A numbered pattern argument is matched with an argument name that contains that number
michael@0 99 * as an ASCII-decimal-digit string (without leading zero).
michael@0 100 *
michael@0 101 * <h4><a name="patterns">Patterns and Their Interpretation</a></h4>
michael@0 102 *
michael@0 103 * <code>MessageFormat</code> uses patterns of the following form:
michael@0 104 * <pre>
michael@0 105 * message = messageText (argument messageText)*
michael@0 106 * argument = noneArg | simpleArg | complexArg
michael@0 107 * complexArg = choiceArg | pluralArg | selectArg | selectordinalArg
michael@0 108 *
michael@0 109 * noneArg = '{' argNameOrNumber '}'
michael@0 110 * simpleArg = '{' argNameOrNumber ',' argType [',' argStyle] '}'
michael@0 111 * choiceArg = '{' argNameOrNumber ',' "choice" ',' choiceStyle '}'
michael@0 112 * pluralArg = '{' argNameOrNumber ',' "plural" ',' pluralStyle '}'
michael@0 113 * selectArg = '{' argNameOrNumber ',' "select" ',' selectStyle '}'
michael@0 114 * selectordinalArg = '{' argNameOrNumber ',' "selectordinal" ',' pluralStyle '}'
michael@0 115 *
michael@0 116 * choiceStyle: see {@link ChoiceFormat}
michael@0 117 * pluralStyle: see {@link PluralFormat}
michael@0 118 * selectStyle: see {@link SelectFormat}
michael@0 119 *
michael@0 120 * argNameOrNumber = argName | argNumber
michael@0 121 * argName = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
michael@0 122 * argNumber = '0' | ('1'..'9' ('0'..'9')*)
michael@0 123 *
michael@0 124 * argType = "number" | "date" | "time" | "spellout" | "ordinal" | "duration"
michael@0 125 * argStyle = "short" | "medium" | "long" | "full" | "integer" | "currency" | "percent" | argStyleText
michael@0 126 * </pre>
michael@0 127 *
michael@0 128 * <ul>
michael@0 129 * <li>messageText can contain quoted literal strings including syntax characters.
michael@0 130 * A quoted literal string begins with an ASCII apostrophe and a syntax character
michael@0 131 * (usually a {curly brace}) and continues until the next single apostrophe.
michael@0 132 * A double ASCII apostrohpe inside or outside of a quoted string represents
michael@0 133 * one literal apostrophe.
michael@0 134 * <li>Quotable syntax characters are the {curly braces} in all messageText parts,
michael@0 135 * plus the '#' sign in a messageText immediately inside a pluralStyle,
michael@0 136 * and the '|' symbol in a messageText immediately inside a choiceStyle.
michael@0 137 * <li>See also {@link #UMessagePatternApostropheMode}
michael@0 138 * <li>In argStyleText, every single ASCII apostrophe begins and ends quoted literal text,
michael@0 139 * and unquoted {curly braces} must occur in matched pairs.
michael@0 140 * </ul>
michael@0 141 *
michael@0 142 * <p>Recommendation: Use the real apostrophe (single quote) character
michael@0 143 * \htmlonly&#x2019;\endhtmlonly (U+2019) for
michael@0 144 * human-readable text, and use the ASCII apostrophe ' (U+0027)
michael@0 145 * only in program syntax, like quoting in MessageFormat.
michael@0 146 * See the annotations for U+0027 Apostrophe in The Unicode Standard.
michael@0 147 *
michael@0 148 * <p>The <code>choice</code> argument type is deprecated.
michael@0 149 * Use <code>plural</code> arguments for proper plural selection,
michael@0 150 * and <code>select</code> arguments for simple selection among a fixed set of choices.
michael@0 151 *
michael@0 152 * <p>The <code>argType</code> and <code>argStyle</code> values are used to create
michael@0 153 * a <code>Format</code> instance for the format element. The following
michael@0 154 * table shows how the values map to Format instances. Combinations not
michael@0 155 * shown in the table are illegal. Any <code>argStyleText</code> must
michael@0 156 * be a valid pattern string for the Format subclass used.
michael@0 157 *
michael@0 158 * <p><table border=1>
michael@0 159 * <tr>
michael@0 160 * <th>argType
michael@0 161 * <th>argStyle
michael@0 162 * <th>resulting Format object
michael@0 163 * <tr>
michael@0 164 * <td colspan=2><i>(none)</i>
michael@0 165 * <td><code>null</code>
michael@0 166 * <tr>
michael@0 167 * <td rowspan=5><code>number</code>
michael@0 168 * <td><i>(none)</i>
michael@0 169 * <td><code>NumberFormat.createInstance(getLocale(), status)</code>
michael@0 170 * <tr>
michael@0 171 * <td><code>integer</code>
michael@0 172 * <td><code>NumberFormat.createInstance(getLocale(), kNumberStyle, status)</code>
michael@0 173 * <tr>
michael@0 174 * <td><code>currency</code>
michael@0 175 * <td><code>NumberFormat.createCurrencyInstance(getLocale(), status)</code>
michael@0 176 * <tr>
michael@0 177 * <td><code>percent</code>
michael@0 178 * <td><code>NumberFormat.createPercentInstance(getLocale(), status)</code>
michael@0 179 * <tr>
michael@0 180 * <td><i>argStyleText</i>
michael@0 181 * <td><code>new DecimalFormat(argStyleText, new DecimalFormatSymbols(getLocale(), status), status)</code>
michael@0 182 * <tr>
michael@0 183 * <td rowspan=6><code>date</code>
michael@0 184 * <td><i>(none)</i>
michael@0 185 * <td><code>DateFormat.createDateInstance(kDefault, getLocale(), status)</code>
michael@0 186 * <tr>
michael@0 187 * <td><code>short</code>
michael@0 188 * <td><code>DateFormat.createDateInstance(kShort, getLocale(), status)</code>
michael@0 189 * <tr>
michael@0 190 * <td><code>medium</code>
michael@0 191 * <td><code>DateFormat.createDateInstance(kDefault, getLocale(), status)</code>
michael@0 192 * <tr>
michael@0 193 * <td><code>long</code>
michael@0 194 * <td><code>DateFormat.createDateInstance(kLong, getLocale(), status)</code>
michael@0 195 * <tr>
michael@0 196 * <td><code>full</code>
michael@0 197 * <td><code>DateFormat.createDateInstance(kFull, getLocale(), status)</code>
michael@0 198 * <tr>
michael@0 199 * <td><i>argStyleText</i>
michael@0 200 * <td><code>new SimpleDateFormat(argStyleText, getLocale(), status)
michael@0 201 * <tr>
michael@0 202 * <td rowspan=6><code>time</code>
michael@0 203 * <td><i>(none)</i>
michael@0 204 * <td><code>DateFormat.createTimeInstance(kDefault, getLocale(), status)</code>
michael@0 205 * <tr>
michael@0 206 * <td><code>short</code>
michael@0 207 * <td><code>DateFormat.createTimeInstance(kShort, getLocale(), status)</code>
michael@0 208 * <tr>
michael@0 209 * <td><code>medium</code>
michael@0 210 * <td><code>DateFormat.createTimeInstance(kDefault, getLocale(), status)</code>
michael@0 211 * <tr>
michael@0 212 * <td><code>long</code>
michael@0 213 * <td><code>DateFormat.createTimeInstance(kLong, getLocale(), status)</code>
michael@0 214 * <tr>
michael@0 215 * <td><code>full</code>
michael@0 216 * <td><code>DateFormat.createTimeInstance(kFull, getLocale(), status)</code>
michael@0 217 * <tr>
michael@0 218 * <td><i>argStyleText</i>
michael@0 219 * <td><code>new SimpleDateFormat(argStyleText, getLocale(), status)
michael@0 220 * <tr>
michael@0 221 * <td><code>spellout</code>
michael@0 222 * <td><i>argStyleText (optional)</i>
michael@0 223 * <td><code>new RuleBasedNumberFormat(URBNF_SPELLOUT, getLocale(), status)
michael@0 224 * <br/>&nbsp;&nbsp;&nbsp;&nbsp;.setDefaultRuleset(argStyleText, status);</code>
michael@0 225 * <tr>
michael@0 226 * <td><code>ordinal</code>
michael@0 227 * <td><i>argStyleText (optional)</i>
michael@0 228 * <td><code>new RuleBasedNumberFormat(URBNF_ORDINAL, getLocale(), status)
michael@0 229 * <br/>&nbsp;&nbsp;&nbsp;&nbsp;.setDefaultRuleset(argStyleText, status);</code>
michael@0 230 * <tr>
michael@0 231 * <td><code>duration</code>
michael@0 232 * <td><i>argStyleText (optional)</i>
michael@0 233 * <td><code>new RuleBasedNumberFormat(URBNF_DURATION, getLocale(), status)
michael@0 234 * <br/>&nbsp;&nbsp;&nbsp;&nbsp;.setDefaultRuleset(argStyleText, status);</code>
michael@0 235 * </table>
michael@0 236 * <p>
michael@0 237 *
michael@0 238 * <h4>Usage Information</h4>
michael@0 239 *
michael@0 240 * <p>Here are some examples of usage:
michael@0 241 * Example 1:
michael@0 242 *
michael@0 243 * <pre>
michael@0 244 * \code
michael@0 245 * UErrorCode success = U_ZERO_ERROR;
michael@0 246 * GregorianCalendar cal(success);
michael@0 247 * Formattable arguments[] = {
michael@0 248 * 7L,
michael@0 249 * Formattable( (Date) cal.getTime(success), Formattable::kIsDate),
michael@0 250 * "a disturbance in the Force"
michael@0 251 * };
michael@0 252 *
michael@0 253 * UnicodeString result;
michael@0 254 * MessageFormat::format(
michael@0 255 * "At {1,time} on {1,date}, there was {2} on planet {0,number}.",
michael@0 256 * arguments, 3, result, success );
michael@0 257 *
michael@0 258 * cout << "result: " << result << endl;
michael@0 259 * //<output>: At 4:34:20 PM on 23-Mar-98, there was a disturbance
michael@0 260 * // in the Force on planet 7.
michael@0 261 * \endcode
michael@0 262 * </pre>
michael@0 263 *
michael@0 264 * Typically, the message format will come from resources, and the
michael@0 265 * arguments will be dynamically set at runtime.
michael@0 266 *
michael@0 267 * <p>Example 2:
michael@0 268 *
michael@0 269 * <pre>
michael@0 270 * \code
michael@0 271 * success = U_ZERO_ERROR;
michael@0 272 * Formattable testArgs[] = {3L, "MyDisk"};
michael@0 273 *
michael@0 274 * MessageFormat form(
michael@0 275 * "The disk \"{1}\" contains {0} file(s).", success );
michael@0 276 *
michael@0 277 * UnicodeString string;
michael@0 278 * FieldPosition fpos = 0;
michael@0 279 * cout << "format: " << form.format(testArgs, 2, string, fpos, success ) << endl;
michael@0 280 *
michael@0 281 * // output, with different testArgs:
michael@0 282 * // output: The disk "MyDisk" contains 0 file(s).
michael@0 283 * // output: The disk "MyDisk" contains 1 file(s).
michael@0 284 * // output: The disk "MyDisk" contains 1,273 file(s).
michael@0 285 * \endcode
michael@0 286 * </pre>
michael@0 287 *
michael@0 288 *
michael@0 289 * <p>For messages that include plural forms, you can use a plural argument:
michael@0 290 * <pre>
michael@0 291 * \code
michael@0 292 * success = U_ZERO_ERROR;
michael@0 293 * MessageFormat msgFmt(
michael@0 294 * "{num_files, plural, "
michael@0 295 * "=0{There are no files on disk \"{disk_name}\".}"
michael@0 296 * "=1{There is one file on disk \"{disk_name}\".}"
michael@0 297 * "other{There are # files on disk \"{disk_name}\".}}",
michael@0 298 * Locale("en"),
michael@0 299 * success);
michael@0 300 * FieldPosition fpos = 0;
michael@0 301 * Formattable testArgs[] = {0L, "MyDisk"};
michael@0 302 * UnicodeString testArgsNames[] = {"num_files", "disk_name"};
michael@0 303 * UnicodeString result;
michael@0 304 * cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);
michael@0 305 * testArgs[0] = 3L;
michael@0 306 * cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);
michael@0 307 * \endcode
michael@0 308 * <em>output</em>:
michael@0 309 * There are no files on disk "MyDisk".
michael@0 310 * There are 3 files on "MyDisk".
michael@0 311 * </pre>
michael@0 312 * See {@link PluralFormat} and {@link PluralRules} for details.
michael@0 313 *
michael@0 314 * <h4><a name="synchronization">Synchronization</a></h4>
michael@0 315 *
michael@0 316 * <p>MessageFormats are not synchronized.
michael@0 317 * It is recommended to create separate format instances for each thread.
michael@0 318 * If multiple threads access a format concurrently, it must be synchronized
michael@0 319 * externally.
michael@0 320 *
michael@0 321 * @stable ICU 2.0
michael@0 322 */
michael@0 323 class U_I18N_API MessageFormat : public Format {
michael@0 324 public:
michael@0 325 #ifndef U_HIDE_OBSOLETE_API
michael@0 326 /**
michael@0 327 * Enum type for kMaxFormat.
michael@0 328 * @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6,
michael@0 329 * rendering this enum type obsolete.
michael@0 330 */
michael@0 331 enum EFormatNumber {
michael@0 332 /**
michael@0 333 * The maximum number of arguments.
michael@0 334 * @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6,
michael@0 335 * rendering this constant obsolete.
michael@0 336 */
michael@0 337 kMaxFormat = 10
michael@0 338 };
michael@0 339 #endif /* U_HIDE_OBSOLETE_API */
michael@0 340
michael@0 341 /**
michael@0 342 * Constructs a new MessageFormat using the given pattern and the
michael@0 343 * default locale.
michael@0 344 *
michael@0 345 * @param pattern Pattern used to construct object.
michael@0 346 * @param status Input/output error code. If the
michael@0 347 * pattern cannot be parsed, set to failure code.
michael@0 348 * @stable ICU 2.0
michael@0 349 */
michael@0 350 MessageFormat(const UnicodeString& pattern,
michael@0 351 UErrorCode &status);
michael@0 352
michael@0 353 /**
michael@0 354 * Constructs a new MessageFormat using the given pattern and locale.
michael@0 355 * @param pattern Pattern used to construct object.
michael@0 356 * @param newLocale The locale to use for formatting dates and numbers.
michael@0 357 * @param status Input/output error code. If the
michael@0 358 * pattern cannot be parsed, set to failure code.
michael@0 359 * @stable ICU 2.0
michael@0 360 */
michael@0 361 MessageFormat(const UnicodeString& pattern,
michael@0 362 const Locale& newLocale,
michael@0 363 UErrorCode& status);
michael@0 364 /**
michael@0 365 * Constructs a new MessageFormat using the given pattern and locale.
michael@0 366 * @param pattern Pattern used to construct object.
michael@0 367 * @param newLocale The locale to use for formatting dates and numbers.
michael@0 368 * @param parseError Struct to receive information on the position
michael@0 369 * of an error within the pattern.
michael@0 370 * @param status Input/output error code. If the
michael@0 371 * pattern cannot be parsed, set to failure code.
michael@0 372 * @stable ICU 2.0
michael@0 373 */
michael@0 374 MessageFormat(const UnicodeString& pattern,
michael@0 375 const Locale& newLocale,
michael@0 376 UParseError& parseError,
michael@0 377 UErrorCode& status);
michael@0 378 /**
michael@0 379 * Constructs a new MessageFormat from an existing one.
michael@0 380 * @stable ICU 2.0
michael@0 381 */
michael@0 382 MessageFormat(const MessageFormat&);
michael@0 383
michael@0 384 /**
michael@0 385 * Assignment operator.
michael@0 386 * @stable ICU 2.0
michael@0 387 */
michael@0 388 const MessageFormat& operator=(const MessageFormat&);
michael@0 389
michael@0 390 /**
michael@0 391 * Destructor.
michael@0 392 * @stable ICU 2.0
michael@0 393 */
michael@0 394 virtual ~MessageFormat();
michael@0 395
michael@0 396 /**
michael@0 397 * Clones this Format object polymorphically. The caller owns the
michael@0 398 * result and should delete it when done.
michael@0 399 * @stable ICU 2.0
michael@0 400 */
michael@0 401 virtual Format* clone(void) const;
michael@0 402
michael@0 403 /**
michael@0 404 * Returns true if the given Format objects are semantically equal.
michael@0 405 * Objects of different subclasses are considered unequal.
michael@0 406 * @param other the object to be compared with.
michael@0 407 * @return true if the given Format objects are semantically equal.
michael@0 408 * @stable ICU 2.0
michael@0 409 */
michael@0 410 virtual UBool operator==(const Format& other) const;
michael@0 411
michael@0 412 /**
michael@0 413 * Sets the locale to be used for creating argument Format objects.
michael@0 414 * @param theLocale the new locale value to be set.
michael@0 415 * @stable ICU 2.0
michael@0 416 */
michael@0 417 virtual void setLocale(const Locale& theLocale);
michael@0 418
michael@0 419 /**
michael@0 420 * Gets the locale used for creating argument Format objects.
michael@0 421 * format information.
michael@0 422 * @return the locale of the object.
michael@0 423 * @stable ICU 2.0
michael@0 424 */
michael@0 425 virtual const Locale& getLocale(void) const;
michael@0 426
michael@0 427 /**
michael@0 428 * Applies the given pattern string to this message format.
michael@0 429 *
michael@0 430 * @param pattern The pattern to be applied.
michael@0 431 * @param status Input/output error code. If the
michael@0 432 * pattern cannot be parsed, set to failure code.
michael@0 433 * @stable ICU 2.0
michael@0 434 */
michael@0 435 virtual void applyPattern(const UnicodeString& pattern,
michael@0 436 UErrorCode& status);
michael@0 437 /**
michael@0 438 * Applies the given pattern string to this message format.
michael@0 439 *
michael@0 440 * @param pattern The pattern to be applied.
michael@0 441 * @param parseError Struct to receive information on the position
michael@0 442 * of an error within the pattern.
michael@0 443 * @param status Input/output error code. If the
michael@0 444 * pattern cannot be parsed, set to failure code.
michael@0 445 * @stable ICU 2.0
michael@0 446 */
michael@0 447 virtual void applyPattern(const UnicodeString& pattern,
michael@0 448 UParseError& parseError,
michael@0 449 UErrorCode& status);
michael@0 450
michael@0 451 /**
michael@0 452 * Sets the UMessagePatternApostropheMode and the pattern used by this message format.
michael@0 453 * Parses the pattern and caches Format objects for simple argument types.
michael@0 454 * Patterns and their interpretation are specified in the
michael@0 455 * <a href="#patterns">class description</a>.
michael@0 456 * <p>
michael@0 457 * This method is best used only once on a given object to avoid confusion about the mode,
michael@0 458 * and after constructing the object with an empty pattern string to minimize overhead.
michael@0 459 *
michael@0 460 * @param pattern The pattern to be applied.
michael@0 461 * @param aposMode The new apostrophe mode.
michael@0 462 * @param parseError Struct to receive information on the position
michael@0 463 * of an error within the pattern.
michael@0 464 * Can be NULL.
michael@0 465 * @param status Input/output error code. If the
michael@0 466 * pattern cannot be parsed, set to failure code.
michael@0 467 * @stable ICU 4.8
michael@0 468 */
michael@0 469 virtual void applyPattern(const UnicodeString& pattern,
michael@0 470 UMessagePatternApostropheMode aposMode,
michael@0 471 UParseError* parseError,
michael@0 472 UErrorCode& status);
michael@0 473
michael@0 474 /**
michael@0 475 * @return this instance's UMessagePatternApostropheMode.
michael@0 476 * @stable ICU 4.8
michael@0 477 */
michael@0 478 UMessagePatternApostropheMode getApostropheMode() const {
michael@0 479 return msgPattern.getApostropheMode();
michael@0 480 }
michael@0 481
michael@0 482 /**
michael@0 483 * Returns a pattern that can be used to recreate this object.
michael@0 484 *
michael@0 485 * @param appendTo Output parameter to receive the pattern.
michael@0 486 * Result is appended to existing contents.
michael@0 487 * @return Reference to 'appendTo' parameter.
michael@0 488 * @stable ICU 2.0
michael@0 489 */
michael@0 490 virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
michael@0 491
michael@0 492 /**
michael@0 493 * Sets subformats.
michael@0 494 * See the class description about format numbering.
michael@0 495 * The caller should not delete the Format objects after this call.
michael@0 496 * <EM>The array formatsToAdopt is not itself adopted.</EM> Its
michael@0 497 * ownership is retained by the caller. If the call fails because
michael@0 498 * memory cannot be allocated, then the formats will be deleted
michael@0 499 * by this method, and this object will remain unchanged.
michael@0 500 *
michael@0 501 * <p>If this format uses named arguments, the new formats are discarded
michael@0 502 * and this format remains unchanged.
michael@0 503 *
michael@0 504 * @stable ICU 2.0
michael@0 505 * @param formatsToAdopt the format to be adopted.
michael@0 506 * @param count the size of the array.
michael@0 507 */
michael@0 508 virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
michael@0 509
michael@0 510 /**
michael@0 511 * Sets subformats.
michael@0 512 * See the class description about format numbering.
michael@0 513 * Each item in the array is cloned into the internal array.
michael@0 514 * If the call fails because memory cannot be allocated, then this
michael@0 515 * object will remain unchanged.
michael@0 516 *
michael@0 517 * <p>If this format uses named arguments, the new formats are discarded
michael@0 518 * and this format remains unchanged.
michael@0 519 *
michael@0 520 * @stable ICU 2.0
michael@0 521 * @param newFormats the new format to be set.
michael@0 522 * @param cnt the size of the array.
michael@0 523 */
michael@0 524 virtual void setFormats(const Format** newFormats, int32_t cnt);
michael@0 525
michael@0 526
michael@0 527 /**
michael@0 528 * Sets one subformat.
michael@0 529 * See the class description about format numbering.
michael@0 530 * The caller should not delete the Format object after this call.
michael@0 531 * If the number is over the number of formats already set,
michael@0 532 * the item will be deleted and ignored.
michael@0 533 *
michael@0 534 * <p>If this format uses named arguments, the new format is discarded
michael@0 535 * and this format remains unchanged.
michael@0 536 *
michael@0 537 * @stable ICU 2.0
michael@0 538 * @param formatNumber index of the subformat.
michael@0 539 * @param formatToAdopt the format to be adopted.
michael@0 540 */
michael@0 541 virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
michael@0 542
michael@0 543 /**
michael@0 544 * Sets one subformat.
michael@0 545 * See the class description about format numbering.
michael@0 546 * If the number is over the number of formats already set,
michael@0 547 * the item will be ignored.
michael@0 548 * @param formatNumber index of the subformat.
michael@0 549 * @param format the format to be set.
michael@0 550 * @stable ICU 2.0
michael@0 551 */
michael@0 552 virtual void setFormat(int32_t formatNumber, const Format& format);
michael@0 553
michael@0 554 /**
michael@0 555 * Gets format names. This function returns formatNames in StringEnumerations
michael@0 556 * which can be used with getFormat() and setFormat() to export formattable
michael@0 557 * array from current MessageFormat to another. It is the caller's responsibility
michael@0 558 * to delete the returned formatNames.
michael@0 559 * @param status output param set to success/failure code.
michael@0 560 * @stable ICU 4.0
michael@0 561 */
michael@0 562 virtual StringEnumeration* getFormatNames(UErrorCode& status);
michael@0 563
michael@0 564 /**
michael@0 565 * Gets subformat pointer for given format name.
michael@0 566 * This function supports both named and numbered
michael@0 567 * arguments. If numbered, the formatName is the
michael@0 568 * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
michael@0 569 * The returned Format object should not be deleted by the caller,
michael@0 570 * nor should the ponter of other object . The pointer and its
michael@0 571 * contents remain valid only until the next call to any method
michael@0 572 * of this class is made with this object.
michael@0 573 * @param formatName the name or number specifying a format
michael@0 574 * @param status output param set to success/failure code.
michael@0 575 * @stable ICU 4.0
michael@0 576 */
michael@0 577 virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
michael@0 578
michael@0 579 /**
michael@0 580 * Sets one subformat for given format name.
michael@0 581 * See the class description about format name.
michael@0 582 * This function supports both named and numbered
michael@0 583 * arguments-- if numbered, the formatName is the
michael@0 584 * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
michael@0 585 * If there is no matched formatName or wrong type,
michael@0 586 * the item will be ignored.
michael@0 587 * @param formatName Name of the subformat.
michael@0 588 * @param format the format to be set.
michael@0 589 * @param status output param set to success/failure code.
michael@0 590 * @stable ICU 4.0
michael@0 591 */
michael@0 592 virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status);
michael@0 593
michael@0 594 /**
michael@0 595 * Sets one subformat for given format name.
michael@0 596 * See the class description about format name.
michael@0 597 * This function supports both named and numbered
michael@0 598 * arguments-- if numbered, the formatName is the
michael@0 599 * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
michael@0 600 * If there is no matched formatName or wrong type,
michael@0 601 * the item will be ignored.
michael@0 602 * The caller should not delete the Format object after this call.
michael@0 603 * @param formatName Name of the subformat.
michael@0 604 * @param formatToAdopt Format to be adopted.
michael@0 605 * @param status output param set to success/failure code.
michael@0 606 * @stable ICU 4.0
michael@0 607 */
michael@0 608 virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status);
michael@0 609
michael@0 610 /**
michael@0 611 * Gets an array of subformats of this object. The returned array
michael@0 612 * should not be deleted by the caller, nor should the pointers
michael@0 613 * within the array. The array and its contents remain valid only
michael@0 614 * until the next call to this format. See the class description
michael@0 615 * about format numbering.
michael@0 616 *
michael@0 617 * @param count output parameter to receive the size of the array
michael@0 618 * @return an array of count Format* objects, or NULL if out of
michael@0 619 * memory. Any or all of the array elements may be NULL.
michael@0 620 * @stable ICU 2.0
michael@0 621 */
michael@0 622 virtual const Format** getFormats(int32_t& count) const;
michael@0 623
michael@0 624
michael@0 625 using Format::format;
michael@0 626
michael@0 627 /**
michael@0 628 * Formats the given array of arguments into a user-readable string.
michael@0 629 * Does not take ownership of the Formattable* array or its contents.
michael@0 630 *
michael@0 631 * <p>If this format uses named arguments, appendTo is unchanged and
michael@0 632 * status is set to U_ILLEGAL_ARGUMENT_ERROR.
michael@0 633 *
michael@0 634 * @param source An array of objects to be formatted.
michael@0 635 * @param count The number of elements of 'source'.
michael@0 636 * @param appendTo Output parameter to receive result.
michael@0 637 * Result is appended to existing contents.
michael@0 638 * @param ignore Not used; inherited from base class API.
michael@0 639 * @param status Input/output error code. If the
michael@0 640 * pattern cannot be parsed, set to failure code.
michael@0 641 * @return Reference to 'appendTo' parameter.
michael@0 642 * @stable ICU 2.0
michael@0 643 */
michael@0 644 UnicodeString& format(const Formattable* source,
michael@0 645 int32_t count,
michael@0 646 UnicodeString& appendTo,
michael@0 647 FieldPosition& ignore,
michael@0 648 UErrorCode& status) const;
michael@0 649
michael@0 650 /**
michael@0 651 * Formats the given array of arguments into a user-readable string
michael@0 652 * using the given pattern.
michael@0 653 *
michael@0 654 * <p>If this format uses named arguments, appendTo is unchanged and
michael@0 655 * status is set to U_ILLEGAL_ARGUMENT_ERROR.
michael@0 656 *
michael@0 657 * @param pattern The pattern.
michael@0 658 * @param arguments An array of objects to be formatted.
michael@0 659 * @param count The number of elements of 'source'.
michael@0 660 * @param appendTo Output parameter to receive result.
michael@0 661 * Result is appended to existing contents.
michael@0 662 * @param status Input/output error code. If the
michael@0 663 * pattern cannot be parsed, set to failure code.
michael@0 664 * @return Reference to 'appendTo' parameter.
michael@0 665 * @stable ICU 2.0
michael@0 666 */
michael@0 667 static UnicodeString& format(const UnicodeString& pattern,
michael@0 668 const Formattable* arguments,
michael@0 669 int32_t count,
michael@0 670 UnicodeString& appendTo,
michael@0 671 UErrorCode& status);
michael@0 672
michael@0 673 /**
michael@0 674 * Formats the given array of arguments into a user-readable
michael@0 675 * string. The array must be stored within a single Formattable
michael@0 676 * object of type kArray. If the Formattable object type is not of
michael@0 677 * type kArray, then returns a failing UErrorCode.
michael@0 678 *
michael@0 679 * <p>If this format uses named arguments, appendTo is unchanged and
michael@0 680 * status is set to U_ILLEGAL_ARGUMENT_ERROR.
michael@0 681 *
michael@0 682 * @param obj A Formattable of type kArray containing
michael@0 683 * arguments to be formatted.
michael@0 684 * @param appendTo Output parameter to receive result.
michael@0 685 * Result is appended to existing contents.
michael@0 686 * @param pos On input: an alignment field, if desired.
michael@0 687 * On output: the offsets of the alignment field.
michael@0 688 * @param status Input/output error code. If the
michael@0 689 * pattern cannot be parsed, set to failure code.
michael@0 690 * @return Reference to 'appendTo' parameter.
michael@0 691 * @stable ICU 2.0
michael@0 692 */
michael@0 693 virtual UnicodeString& format(const Formattable& obj,
michael@0 694 UnicodeString& appendTo,
michael@0 695 FieldPosition& pos,
michael@0 696 UErrorCode& status) const;
michael@0 697
michael@0 698 /**
michael@0 699 * Formats the given array of arguments into a user-defined argument name
michael@0 700 * array. This function supports both named and numbered
michael@0 701 * arguments-- if numbered, the formatName is the
michael@0 702 * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
michael@0 703 *
michael@0 704 * @param argumentNames argument name array
michael@0 705 * @param arguments An array of objects to be formatted.
michael@0 706 * @param count The number of elements of 'argumentNames' and
michael@0 707 * arguments. The number of argumentNames and arguments
michael@0 708 * must be the same.
michael@0 709 * @param appendTo Output parameter to receive result.
michael@0 710 * Result is appended to existing contents.
michael@0 711 * @param status Input/output error code. If the
michael@0 712 * pattern cannot be parsed, set to failure code.
michael@0 713 * @return Reference to 'appendTo' parameter.
michael@0 714 * @stable ICU 4.0
michael@0 715 */
michael@0 716 UnicodeString& format(const UnicodeString* argumentNames,
michael@0 717 const Formattable* arguments,
michael@0 718 int32_t count,
michael@0 719 UnicodeString& appendTo,
michael@0 720 UErrorCode& status) const;
michael@0 721 /**
michael@0 722 * Parses the given string into an array of output arguments.
michael@0 723 *
michael@0 724 * @param source String to be parsed.
michael@0 725 * @param pos On input, starting position for parse. On output,
michael@0 726 * final position after parse. Unchanged if parse
michael@0 727 * fails.
michael@0 728 * @param count Output parameter to receive the number of arguments
michael@0 729 * parsed.
michael@0 730 * @return an array of parsed arguments. The caller owns both
michael@0 731 * the array and its contents.
michael@0 732 * @stable ICU 2.0
michael@0 733 */
michael@0 734 virtual Formattable* parse(const UnicodeString& source,
michael@0 735 ParsePosition& pos,
michael@0 736 int32_t& count) const;
michael@0 737
michael@0 738 /**
michael@0 739 * Parses the given string into an array of output arguments.
michael@0 740 *
michael@0 741 * <p>If this format uses named arguments, status is set to
michael@0 742 * U_ARGUMENT_TYPE_MISMATCH.
michael@0 743 *
michael@0 744 * @param source String to be parsed.
michael@0 745 * @param count Output param to receive size of returned array.
michael@0 746 * @param status Input/output error code. If the
michael@0 747 * pattern cannot be parsed, set to failure code.
michael@0 748 * @return an array of parsed arguments. The caller owns both
michael@0 749 * the array and its contents. Returns NULL if status is not U_ZERO_ERROR.
michael@0 750 *
michael@0 751 * @stable ICU 2.0
michael@0 752 */
michael@0 753 virtual Formattable* parse(const UnicodeString& source,
michael@0 754 int32_t& count,
michael@0 755 UErrorCode& status) const;
michael@0 756
michael@0 757 /**
michael@0 758 * Parses the given string into an array of output arguments
michael@0 759 * stored within a single Formattable of type kArray.
michael@0 760 *
michael@0 761 * @param source The string to be parsed into an object.
michael@0 762 * @param result Formattable to be set to the parse result.
michael@0 763 * If parse fails, return contents are undefined.
michael@0 764 * @param pos On input, starting position for parse. On output,
michael@0 765 * final position after parse. Unchanged if parse
michael@0 766 * fails.
michael@0 767 * @stable ICU 2.0
michael@0 768 */
michael@0 769 virtual void parseObject(const UnicodeString& source,
michael@0 770 Formattable& result,
michael@0 771 ParsePosition& pos) const;
michael@0 772
michael@0 773 /**
michael@0 774 * Convert an 'apostrophe-friendly' pattern into a standard
michael@0 775 * pattern. Standard patterns treat all apostrophes as
michael@0 776 * quotes, which is problematic in some languages, e.g.
michael@0 777 * French, where apostrophe is commonly used. This utility
michael@0 778 * assumes that only an unpaired apostrophe immediately before
michael@0 779 * a brace is a true quote. Other unpaired apostrophes are paired,
michael@0 780 * and the resulting standard pattern string is returned.
michael@0 781 *
michael@0 782 * <p><b>Note</b> it is not guaranteed that the returned pattern
michael@0 783 * is indeed a valid pattern. The only effect is to convert
michael@0 784 * between patterns having different quoting semantics.
michael@0 785 *
michael@0 786 * @param pattern the 'apostrophe-friendly' patttern to convert
michael@0 787 * @param status Input/output error code. If the pattern
michael@0 788 * cannot be parsed, the failure code is set.
michael@0 789 * @return the standard equivalent of the original pattern
michael@0 790 * @stable ICU 3.4
michael@0 791 */
michael@0 792 static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern,
michael@0 793 UErrorCode& status);
michael@0 794
michael@0 795
michael@0 796 /**
michael@0 797 * Returns true if this MessageFormat uses named arguments,
michael@0 798 * and false otherwise. See class description.
michael@0 799 *
michael@0 800 * @return true if named arguments are used.
michael@0 801 * @stable ICU 4.0
michael@0 802 */
michael@0 803 UBool usesNamedArguments() const;
michael@0 804
michael@0 805
michael@0 806 #ifndef U_HIDE_INTERNAL_API
michael@0 807 /**
michael@0 808 * This API is for ICU internal use only.
michael@0 809 * Please do not use it.
michael@0 810 *
michael@0 811 * Returns argument types count in the parsed pattern.
michael@0 812 * Used to distinguish pattern "{0} d" and "d".
michael@0 813 *
michael@0 814 * @return The number of formattable types in the pattern
michael@0 815 * @internal
michael@0 816 */
michael@0 817 int32_t getArgTypeCount() const;
michael@0 818 #endif /* U_HIDE_INTERNAL_API */
michael@0 819
michael@0 820 /**
michael@0 821 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
michael@0 822 * This method is to implement a simple version of RTTI, since not all
michael@0 823 * C++ compilers support genuine RTTI. Polymorphic operator==() and
michael@0 824 * clone() methods call this method.
michael@0 825 *
michael@0 826 * @return The class ID for this object. All objects of a
michael@0 827 * given class have the same class ID. Objects of
michael@0 828 * other classes have different class IDs.
michael@0 829 * @stable ICU 2.0
michael@0 830 */
michael@0 831 virtual UClassID getDynamicClassID(void) const;
michael@0 832
michael@0 833 /**
michael@0 834 * Return the class ID for this class. This is useful only for
michael@0 835 * comparing to a return value from getDynamicClassID(). For example:
michael@0 836 * <pre>
michael@0 837 * . Base* polymorphic_pointer = createPolymorphicObject();
michael@0 838 * . if (polymorphic_pointer->getDynamicClassID() ==
michael@0 839 * . Derived::getStaticClassID()) ...
michael@0 840 * </pre>
michael@0 841 * @return The class ID for all objects of this class.
michael@0 842 * @stable ICU 2.0
michael@0 843 */
michael@0 844 static UClassID U_EXPORT2 getStaticClassID(void);
michael@0 845
michael@0 846 #ifndef U_HIDE_INTERNAL_API
michael@0 847 /**
michael@0 848 * Compares two Format objects. This is used for constructing the hash
michael@0 849 * tables.
michael@0 850 *
michael@0 851 * @param left pointer to a Format object. Must not be NULL.
michael@0 852 * @param right pointer to a Format object. Must not be NULL.
michael@0 853 *
michael@0 854 * @return whether the two objects are the same
michael@0 855 * @internal
michael@0 856 */
michael@0 857 static UBool equalFormats(const void* left, const void* right);
michael@0 858 #endif /* U_HIDE_INTERNAL_API */
michael@0 859
michael@0 860 private:
michael@0 861
michael@0 862 Locale fLocale;
michael@0 863 MessagePattern msgPattern;
michael@0 864 Format** formatAliases; // see getFormats
michael@0 865 int32_t formatAliasesCapacity;
michael@0 866
michael@0 867 MessageFormat(); // default constructor not implemented
michael@0 868
michael@0 869 /**
michael@0 870 * This provider helps defer instantiation of a PluralRules object
michael@0 871 * until we actually need to select a keyword.
michael@0 872 * For example, if the number matches an explicit-value selector like "=1"
michael@0 873 * we do not need any PluralRules.
michael@0 874 */
michael@0 875 class U_I18N_API PluralSelectorProvider : public PluralFormat::PluralSelector {
michael@0 876 public:
michael@0 877 PluralSelectorProvider(const MessageFormat &mf, UPluralType type);
michael@0 878 virtual ~PluralSelectorProvider();
michael@0 879 virtual UnicodeString select(void *ctx, double number, UErrorCode& ec) const;
michael@0 880
michael@0 881 void reset();
michael@0 882 private:
michael@0 883 const MessageFormat &msgFormat;
michael@0 884 PluralRules* rules;
michael@0 885 UPluralType type;
michael@0 886 };
michael@0 887
michael@0 888 /**
michael@0 889 * A MessageFormat formats an array of arguments. Each argument
michael@0 890 * has an expected type, based on the pattern. For example, if
michael@0 891 * the pattern contains the subformat "{3,number,integer}", then
michael@0 892 * we expect argument 3 to have type Formattable::kLong. This
michael@0 893 * array needs to grow dynamically if the MessageFormat is
michael@0 894 * modified.
michael@0 895 */
michael@0 896 Formattable::Type* argTypes;
michael@0 897 int32_t argTypeCount;
michael@0 898 int32_t argTypeCapacity;
michael@0 899
michael@0 900 /**
michael@0 901 * TRUE if there are different argTypes for the same argument.
michael@0 902 * This only matters when the MessageFormat is used in the plain C (umsg_xxx) API
michael@0 903 * where the pattern argTypes determine how the va_arg list is read.
michael@0 904 */
michael@0 905 UBool hasArgTypeConflicts;
michael@0 906
michael@0 907 // Variable-size array management
michael@0 908 UBool allocateArgTypes(int32_t capacity, UErrorCode& status);
michael@0 909
michael@0 910 /**
michael@0 911 * Default Format objects used when no format is specified and a
michael@0 912 * numeric or date argument is formatted. These are volatile
michael@0 913 * cache objects maintained only for performance. They do not
michael@0 914 * participate in operator=(), copy constructor(), nor
michael@0 915 * operator==().
michael@0 916 */
michael@0 917 NumberFormat* defaultNumberFormat;
michael@0 918 DateFormat* defaultDateFormat;
michael@0 919
michael@0 920 UHashtable* cachedFormatters;
michael@0 921 UHashtable* customFormatArgStarts;
michael@0 922
michael@0 923 PluralSelectorProvider pluralProvider;
michael@0 924 PluralSelectorProvider ordinalProvider;
michael@0 925
michael@0 926 /**
michael@0 927 * Method to retrieve default formats (or NULL on failure).
michael@0 928 * These are semantically const, but may modify *this.
michael@0 929 */
michael@0 930 const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
michael@0 931 const DateFormat* getDefaultDateFormat(UErrorCode&) const;
michael@0 932
michael@0 933 /**
michael@0 934 * Finds the word s, in the keyword list and returns the located index.
michael@0 935 * @param s the keyword to be searched for.
michael@0 936 * @param list the list of keywords to be searched with.
michael@0 937 * @return the index of the list which matches the keyword s.
michael@0 938 */
michael@0 939 static int32_t findKeyword( const UnicodeString& s,
michael@0 940 const UChar * const *list);
michael@0 941
michael@0 942 /**
michael@0 943 * Thin wrapper around the format(... AppendableWrapper ...) variant.
michael@0 944 * Wraps the destination UnicodeString into an AppendableWrapper and
michael@0 945 * supplies default values for some other parameters.
michael@0 946 */
michael@0 947 UnicodeString& format(const Formattable* arguments,
michael@0 948 const UnicodeString *argumentNames,
michael@0 949 int32_t cnt,
michael@0 950 UnicodeString& appendTo,
michael@0 951 FieldPosition* pos,
michael@0 952 UErrorCode& status) const;
michael@0 953
michael@0 954 /**
michael@0 955 * Formats the arguments and writes the result into the
michael@0 956 * AppendableWrapper, updates the field position.
michael@0 957 *
michael@0 958 * @param msgStart Index to msgPattern part to start formatting from.
michael@0 959 * @param plNumber NULL except when formatting a plural argument sub-message
michael@0 960 * where a '#' is replaced by the format string for this number.
michael@0 961 * @param arguments The formattable objects array. (Must not be NULL.)
michael@0 962 * @param argumentNames NULL if numbered values are used. Otherwise the same
michael@0 963 * length as "arguments", and each entry is the name of the
michael@0 964 * corresponding argument in "arguments".
michael@0 965 * @param cnt The length of arguments (and of argumentNames if that is not NULL).
michael@0 966 * @param appendTo Output parameter to receive the result.
michael@0 967 * The result string is appended to existing contents.
michael@0 968 * @param pos Field position status.
michael@0 969 * @param success The error code status.
michael@0 970 */
michael@0 971 void format(int32_t msgStart,
michael@0 972 const void *plNumber,
michael@0 973 const Formattable* arguments,
michael@0 974 const UnicodeString *argumentNames,
michael@0 975 int32_t cnt,
michael@0 976 AppendableWrapper& appendTo,
michael@0 977 FieldPosition* pos,
michael@0 978 UErrorCode& success) const;
michael@0 979
michael@0 980 UnicodeString getArgName(int32_t partIndex);
michael@0 981
michael@0 982 void setArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
michael@0 983
michael@0 984 void setCustomArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
michael@0 985
michael@0 986 int32_t nextTopLevelArgStart(int32_t partIndex) const;
michael@0 987
michael@0 988 UBool argNameMatches(int32_t partIndex, const UnicodeString& argName, int32_t argNumber);
michael@0 989
michael@0 990 void cacheExplicitFormats(UErrorCode& status);
michael@0 991
michael@0 992 Format* createAppropriateFormat(UnicodeString& type,
michael@0 993 UnicodeString& style,
michael@0 994 Formattable::Type& formattableType,
michael@0 995 UParseError& parseError,
michael@0 996 UErrorCode& ec);
michael@0 997
michael@0 998 const Formattable* getArgFromListByName(const Formattable* arguments,
michael@0 999 const UnicodeString *argumentNames,
michael@0 1000 int32_t cnt, UnicodeString& name) const;
michael@0 1001
michael@0 1002 Formattable* parse(int32_t msgStart,
michael@0 1003 const UnicodeString& source,
michael@0 1004 ParsePosition& pos,
michael@0 1005 int32_t& count,
michael@0 1006 UErrorCode& ec) const;
michael@0 1007
michael@0 1008 FieldPosition* updateMetaData(AppendableWrapper& dest, int32_t prevLength,
michael@0 1009 FieldPosition* fp, const Formattable* argId) const;
michael@0 1010
michael@0 1011 /**
michael@0 1012 * Finds the "other" sub-message.
michael@0 1013 * @param partIndex the index of the first PluralFormat argument style part.
michael@0 1014 * @return the "other" sub-message start part index.
michael@0 1015 */
michael@0 1016 int32_t findOtherSubMessage(int32_t partIndex) const;
michael@0 1017
michael@0 1018 /**
michael@0 1019 * Returns the ARG_START index of the first occurrence of the plural number in a sub-message.
michael@0 1020 * Returns -1 if it is a REPLACE_NUMBER.
michael@0 1021 * Returns 0 if there is neither.
michael@0 1022 */
michael@0 1023 int32_t findFirstPluralNumberArg(int32_t msgStart, const UnicodeString &argName) const;
michael@0 1024
michael@0 1025 Format* getCachedFormatter(int32_t argumentNumber) const;
michael@0 1026
michael@0 1027 UnicodeString getLiteralStringUntilNextArgument(int32_t from) const;
michael@0 1028
michael@0 1029 void copyObjects(const MessageFormat& that, UErrorCode& ec);
michael@0 1030
michael@0 1031 void formatComplexSubMessage(int32_t msgStart,
michael@0 1032 const void *plNumber,
michael@0 1033 const Formattable* arguments,
michael@0 1034 const UnicodeString *argumentNames,
michael@0 1035 int32_t cnt,
michael@0 1036 AppendableWrapper& appendTo,
michael@0 1037 UErrorCode& success) const;
michael@0 1038
michael@0 1039 /**
michael@0 1040 * Convenience method that ought to be in NumberFormat
michael@0 1041 */
michael@0 1042 NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
michael@0 1043
michael@0 1044 /**
michael@0 1045 * Returns array of argument types in the parsed pattern
michael@0 1046 * for use in C API. Only for the use of umsg_vformat(). Not
michael@0 1047 * for public consumption.
michael@0 1048 * @param listCount Output parameter to receive the size of array
michael@0 1049 * @return The array of formattable types in the pattern
michael@0 1050 */
michael@0 1051 const Formattable::Type* getArgTypeList(int32_t& listCount) const {
michael@0 1052 listCount = argTypeCount;
michael@0 1053 return argTypes;
michael@0 1054 }
michael@0 1055
michael@0 1056 /**
michael@0 1057 * Resets the internal MessagePattern, and other associated caches.
michael@0 1058 */
michael@0 1059 void resetPattern();
michael@0 1060
michael@0 1061 /**
michael@0 1062 * A DummyFormatter that we use solely to store a NULL value. UHash does
michael@0 1063 * not support storing NULL values.
michael@0 1064 */
michael@0 1065 class U_I18N_API DummyFormat : public Format {
michael@0 1066 public:
michael@0 1067 virtual UBool operator==(const Format&) const;
michael@0 1068 virtual Format* clone() const;
michael@0 1069 virtual UnicodeString& format(const Formattable& obj,
michael@0 1070 UnicodeString& appendTo,
michael@0 1071 UErrorCode& status) const;
michael@0 1072 virtual UnicodeString& format(const Formattable&,
michael@0 1073 UnicodeString& appendTo,
michael@0 1074 FieldPosition&,
michael@0 1075 UErrorCode& status) const;
michael@0 1076 virtual UnicodeString& format(const Formattable& obj,
michael@0 1077 UnicodeString& appendTo,
michael@0 1078 FieldPositionIterator* posIter,
michael@0 1079 UErrorCode& status) const;
michael@0 1080 virtual void parseObject(const UnicodeString&,
michael@0 1081 Formattable&,
michael@0 1082 ParsePosition&) const;
michael@0 1083 };
michael@0 1084
michael@0 1085 friend class MessageFormatAdapter; // getFormatTypeList() access
michael@0 1086 };
michael@0 1087
michael@0 1088 U_NAMESPACE_END
michael@0 1089
michael@0 1090 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 1091
michael@0 1092 #endif // _MSGFMT
michael@0 1093 //eof

mercurial