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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /********************************************************************
michael@0 2 * COPYRIGHT:
michael@0 3 * Copyright (c) 1997-2011, International Business Machines Corporation and
michael@0 4 * others. All Rights Reserved.
michael@0 5 * Copyright (C) 2010 , Yahoo! Inc.
michael@0 6 ********************************************************************
michael@0 7 *
michael@0 8 * file name: umsg.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * Change history:
michael@0 14 *
michael@0 15 * 08/5/2001 Ram Added C wrappers for C++ API.
michael@0 16 ********************************************************************/
michael@0 17
michael@0 18 #ifndef UMSG_H
michael@0 19 #define UMSG_H
michael@0 20
michael@0 21 #include "unicode/utypes.h"
michael@0 22
michael@0 23 #if !UCONFIG_NO_FORMATTING
michael@0 24
michael@0 25 #include "unicode/localpointer.h"
michael@0 26 #include "unicode/uloc.h"
michael@0 27 #include "unicode/parseerr.h"
michael@0 28 #include <stdarg.h>
michael@0 29
michael@0 30 /**
michael@0 31 * \file
michael@0 32 * \brief C API: MessageFormat
michael@0 33 *
michael@0 34 * <h2>MessageFormat C API </h2>
michael@0 35 *
michael@0 36 * <p>MessageFormat prepares strings for display to users,
michael@0 37 * with optional arguments (variables/placeholders).
michael@0 38 * The arguments can occur in any order, which is necessary for translation
michael@0 39 * into languages with different grammars.
michael@0 40 *
michael@0 41 * <p>The opaque UMessageFormat type is a thin C wrapper around
michael@0 42 * a C++ MessageFormat. It is constructed from a <em>pattern</em> string
michael@0 43 * with arguments in {curly braces} which will be replaced by formatted values.
michael@0 44 *
michael@0 45 * <p>Currently, the C API supports only numbered arguments.
michael@0 46 *
michael@0 47 * <p>For details about the pattern syntax and behavior,
michael@0 48 * especially about the ASCII apostrophe vs. the
michael@0 49 * real apostrophe (single quote) character \htmlonly&#x2019;\endhtmlonly (U+2019),
michael@0 50 * see the C++ MessageFormat class documentation.
michael@0 51 *
michael@0 52 * <p>Here are some examples of C API usage:
michael@0 53 * Example 1:
michael@0 54 * <pre>
michael@0 55 * \code
michael@0 56 * UChar *result, *tzID, *str;
michael@0 57 * UChar pattern[100];
michael@0 58 * int32_t resultLengthOut, resultlength;
michael@0 59 * UCalendar *cal;
michael@0 60 * UDate d1;
michael@0 61 * UDateFormat *def1;
michael@0 62 * UErrorCode status = U_ZERO_ERROR;
michael@0 63 *
michael@0 64 * str=(UChar*)malloc(sizeof(UChar) * (strlen("disturbance in force") +1));
michael@0 65 * u_uastrcpy(str, "disturbance in force");
michael@0 66 * tzID=(UChar*)malloc(sizeof(UChar) * 4);
michael@0 67 * u_uastrcpy(tzID, "PST");
michael@0 68 * cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
michael@0 69 * ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
michael@0 70 * d1=ucal_getMillis(cal, &status);
michael@0 71 * u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
michael@0 72 * resultlength=0;
michael@0 73 * resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, d1, str, 7);
michael@0 74 * if(status==U_BUFFER_OVERFLOW_ERROR){
michael@0 75 * status=U_ZERO_ERROR;
michael@0 76 * resultlength=resultLengthOut+1;
michael@0 77 * result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
michael@0 78 * u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, d1, str, 7);
michael@0 79 * }
michael@0 80 * printf("%s\n", austrdup(result) );//austrdup( a function used to convert UChar* to char*)
michael@0 81 * //output>: "On March 18, 1999, there was a disturbance in force on planet 7
michael@0 82 * \endcode
michael@0 83 * </pre>
michael@0 84 * Typically, the message format will come from resources, and the
michael@0 85 * arguments will be dynamically set at runtime.
michael@0 86 * <P>
michael@0 87 * Example 2:
michael@0 88 * <pre>
michael@0 89 * \code
michael@0 90 * UChar* str;
michael@0 91 * UErrorCode status = U_ZERO_ERROR;
michael@0 92 * UChar *result;
michael@0 93 * UChar pattern[100];
michael@0 94 * int32_t resultlength, resultLengthOut, i;
michael@0 95 * double testArgs= { 100.0, 1.0, 0.0};
michael@0 96 *
michael@0 97 * str=(UChar*)malloc(sizeof(UChar) * 10);
michael@0 98 * u_uastrcpy(str, "MyDisk");
michael@0 99 * u_uastrcpy(pattern, "The disk {1} contains {0,choice,0#no files|1#one file|1<{0,number,integer} files}");
michael@0 100 * for(i=0; i<3; i++){
michael@0 101 * resultlength=0;
michael@0 102 * resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, testArgs[i], str);
michael@0 103 * if(status==U_BUFFER_OVERFLOW_ERROR){
michael@0 104 * status=U_ZERO_ERROR;
michael@0 105 * resultlength=resultLengthOut+1;
michael@0 106 * result=(UChar*)malloc(sizeof(UChar) * resultlength);
michael@0 107 * u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, testArgs[i], str);
michael@0 108 * }
michael@0 109 * printf("%s\n", austrdup(result) ); //austrdup( a function used to convert UChar* to char*)
michael@0 110 * free(result);
michael@0 111 * }
michael@0 112 * // output, with different testArgs:
michael@0 113 * // output: The disk "MyDisk" contains 100 files.
michael@0 114 * // output: The disk "MyDisk" contains one file.
michael@0 115 * // output: The disk "MyDisk" contains no files.
michael@0 116 * \endcode
michael@0 117 * </pre>
michael@0 118 *
michael@0 119 *
michael@0 120 * Example 3:
michael@0 121 * <pre>
michael@0 122 * \code
michael@0 123 * UChar* str;
michael@0 124 * UChar* str1;
michael@0 125 * UErrorCode status = U_ZERO_ERROR;
michael@0 126 * UChar *result;
michael@0 127 * UChar pattern[100];
michael@0 128 * UChar expected[100];
michael@0 129 * int32_t resultlength,resultLengthOut;
michael@0 130
michael@0 131 * str=(UChar*)malloc(sizeof(UChar) * 25);
michael@0 132 * u_uastrcpy(str, "Kirti");
michael@0 133 * str1=(UChar*)malloc(sizeof(UChar) * 25);
michael@0 134 * u_uastrcpy(str1, "female");
michael@0 135 * log_verbose("Testing message format with Select test #1\n:");
michael@0 136 * u_uastrcpy(pattern, "{0} est {1, select, female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.");
michael@0 137 * u_uastrcpy(expected, "Kirti est all\\u00E9e \\u00E0 Paris.");
michael@0 138 * resultlength=0;
michael@0 139 * resultLengthOut=u_formatMessage( "fr", pattern, u_strlen(pattern), NULL, resultlength, &status, str , str1);
michael@0 140 * if(status==U_BUFFER_OVERFLOW_ERROR)
michael@0 141 * {
michael@0 142 * status=U_ZERO_ERROR;
michael@0 143 * resultlength=resultLengthOut+1;
michael@0 144 * result=(UChar*)malloc(sizeof(UChar) * resultlength);
michael@0 145 * u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1);
michael@0 146 * if(u_strcmp(result, expected)==0)
michael@0 147 * log_verbose("PASS: MessagFormat successful on Select test#1\n");
michael@0 148 * else{
michael@0 149 * log_err("FAIL: Error in MessageFormat on Select test#1\n GOT %s EXPECTED %s\n", austrdup(result),
michael@0 150 * austrdup(expected) );
michael@0 151 * }
michael@0 152 * free(result);
michael@0 153 * }
michael@0 154 * \endcode
michael@0 155 * </pre>
michael@0 156 */
michael@0 157
michael@0 158 /**
michael@0 159 * Format a message for a locale.
michael@0 160 * This function may perform re-ordering of the arguments depending on the
michael@0 161 * locale. For all numeric arguments, double is assumed unless the type is
michael@0 162 * explicitly integer. All choice format arguments must be of type double.
michael@0 163 * @param locale The locale for which the message will be formatted
michael@0 164 * @param pattern The pattern specifying the message's format
michael@0 165 * @param patternLength The length of pattern
michael@0 166 * @param result A pointer to a buffer to receive the formatted message.
michael@0 167 * @param resultLength The maximum size of result.
michael@0 168 * @param status A pointer to an UErrorCode to receive any errors
michael@0 169 * @param ... A variable-length argument list containing the arguments specified
michael@0 170 * in pattern.
michael@0 171 * @return The total buffer size needed; if greater than resultLength, the
michael@0 172 * output was truncated.
michael@0 173 * @see u_parseMessage
michael@0 174 * @stable ICU 2.0
michael@0 175 */
michael@0 176 U_STABLE int32_t U_EXPORT2
michael@0 177 u_formatMessage(const char *locale,
michael@0 178 const UChar *pattern,
michael@0 179 int32_t patternLength,
michael@0 180 UChar *result,
michael@0 181 int32_t resultLength,
michael@0 182 UErrorCode *status,
michael@0 183 ...);
michael@0 184
michael@0 185 /**
michael@0 186 * Format a message for a locale.
michael@0 187 * This function may perform re-ordering of the arguments depending on the
michael@0 188 * locale. For all numeric arguments, double is assumed unless the type is
michael@0 189 * explicitly integer. All choice format arguments must be of type double.
michael@0 190 * @param locale The locale for which the message will be formatted
michael@0 191 * @param pattern The pattern specifying the message's format
michael@0 192 * @param patternLength The length of pattern
michael@0 193 * @param result A pointer to a buffer to receive the formatted message.
michael@0 194 * @param resultLength The maximum size of result.
michael@0 195 * @param ap A variable-length argument list containing the arguments specified
michael@0 196 * @param status A pointer to an UErrorCode to receive any errors
michael@0 197 * in pattern.
michael@0 198 * @return The total buffer size needed; if greater than resultLength, the
michael@0 199 * output was truncated.
michael@0 200 * @see u_parseMessage
michael@0 201 * @stable ICU 2.0
michael@0 202 */
michael@0 203 U_STABLE int32_t U_EXPORT2
michael@0 204 u_vformatMessage( const char *locale,
michael@0 205 const UChar *pattern,
michael@0 206 int32_t patternLength,
michael@0 207 UChar *result,
michael@0 208 int32_t resultLength,
michael@0 209 va_list ap,
michael@0 210 UErrorCode *status);
michael@0 211
michael@0 212 /**
michael@0 213 * Parse a message.
michael@0 214 * For numeric arguments, this function will always use doubles. Integer types
michael@0 215 * should not be passed.
michael@0 216 * This function is not able to parse all output from {@link #u_formatMessage }.
michael@0 217 * @param locale The locale for which the message is formatted
michael@0 218 * @param pattern The pattern specifying the message's format
michael@0 219 * @param patternLength The length of pattern
michael@0 220 * @param source The text to parse.
michael@0 221 * @param sourceLength The length of source, or -1 if null-terminated.
michael@0 222 * @param status A pointer to an UErrorCode to receive any errors
michael@0 223 * @param ... A variable-length argument list containing the arguments
michael@0 224 * specified in pattern.
michael@0 225 * @see u_formatMessage
michael@0 226 * @stable ICU 2.0
michael@0 227 */
michael@0 228 U_STABLE void U_EXPORT2
michael@0 229 u_parseMessage( const char *locale,
michael@0 230 const UChar *pattern,
michael@0 231 int32_t patternLength,
michael@0 232 const UChar *source,
michael@0 233 int32_t sourceLength,
michael@0 234 UErrorCode *status,
michael@0 235 ...);
michael@0 236
michael@0 237 /**
michael@0 238 * Parse a message.
michael@0 239 * For numeric arguments, this function will always use doubles. Integer types
michael@0 240 * should not be passed.
michael@0 241 * This function is not able to parse all output from {@link #u_formatMessage }.
michael@0 242 * @param locale The locale for which the message is formatted
michael@0 243 * @param pattern The pattern specifying the message's format
michael@0 244 * @param patternLength The length of pattern
michael@0 245 * @param source The text to parse.
michael@0 246 * @param sourceLength The length of source, or -1 if null-terminated.
michael@0 247 * @param ap A variable-length argument list containing the arguments
michael@0 248 * @param status A pointer to an UErrorCode to receive any errors
michael@0 249 * specified in pattern.
michael@0 250 * @see u_formatMessage
michael@0 251 * @stable ICU 2.0
michael@0 252 */
michael@0 253 U_STABLE void U_EXPORT2
michael@0 254 u_vparseMessage(const char *locale,
michael@0 255 const UChar *pattern,
michael@0 256 int32_t patternLength,
michael@0 257 const UChar *source,
michael@0 258 int32_t sourceLength,
michael@0 259 va_list ap,
michael@0 260 UErrorCode *status);
michael@0 261
michael@0 262 /**
michael@0 263 * Format a message for a locale.
michael@0 264 * This function may perform re-ordering of the arguments depending on the
michael@0 265 * locale. For all numeric arguments, double is assumed unless the type is
michael@0 266 * explicitly integer. All choice format arguments must be of type double.
michael@0 267 * @param locale The locale for which the message will be formatted
michael@0 268 * @param pattern The pattern specifying the message's format
michael@0 269 * @param patternLength The length of pattern
michael@0 270 * @param result A pointer to a buffer to receive the formatted message.
michael@0 271 * @param resultLength The maximum size of result.
michael@0 272 * @param status A pointer to an UErrorCode to receive any errors
michael@0 273 * @param ... A variable-length argument list containing the arguments specified
michael@0 274 * in pattern.
michael@0 275 * @param parseError A pointer to UParseError to receive information about errors
michael@0 276 * occurred during parsing.
michael@0 277 * @return The total buffer size needed; if greater than resultLength, the
michael@0 278 * output was truncated.
michael@0 279 * @see u_parseMessage
michael@0 280 * @stable ICU 2.0
michael@0 281 */
michael@0 282 U_STABLE int32_t U_EXPORT2
michael@0 283 u_formatMessageWithError( const char *locale,
michael@0 284 const UChar *pattern,
michael@0 285 int32_t patternLength,
michael@0 286 UChar *result,
michael@0 287 int32_t resultLength,
michael@0 288 UParseError *parseError,
michael@0 289 UErrorCode *status,
michael@0 290 ...);
michael@0 291
michael@0 292 /**
michael@0 293 * Format a message for a locale.
michael@0 294 * This function may perform re-ordering of the arguments depending on the
michael@0 295 * locale. For all numeric arguments, double is assumed unless the type is
michael@0 296 * explicitly integer. All choice format arguments must be of type double.
michael@0 297 * @param locale The locale for which the message will be formatted
michael@0 298 * @param pattern The pattern specifying the message's format
michael@0 299 * @param patternLength The length of pattern
michael@0 300 * @param result A pointer to a buffer to receive the formatted message.
michael@0 301 * @param resultLength The maximum size of result.
michael@0 302 * @param parseError A pointer to UParseError to receive information about errors
michael@0 303 * occurred during parsing.
michael@0 304 * @param ap A variable-length argument list containing the arguments specified
michael@0 305 * @param status A pointer to an UErrorCode to receive any errors
michael@0 306 * in pattern.
michael@0 307 * @return The total buffer size needed; if greater than resultLength, the
michael@0 308 * output was truncated.
michael@0 309 * @stable ICU 2.0
michael@0 310 */
michael@0 311 U_STABLE int32_t U_EXPORT2
michael@0 312 u_vformatMessageWithError( const char *locale,
michael@0 313 const UChar *pattern,
michael@0 314 int32_t patternLength,
michael@0 315 UChar *result,
michael@0 316 int32_t resultLength,
michael@0 317 UParseError* parseError,
michael@0 318 va_list ap,
michael@0 319 UErrorCode *status);
michael@0 320
michael@0 321 /**
michael@0 322 * Parse a message.
michael@0 323 * For numeric arguments, this function will always use doubles. Integer types
michael@0 324 * should not be passed.
michael@0 325 * This function is not able to parse all output from {@link #u_formatMessage }.
michael@0 326 * @param locale The locale for which the message is formatted
michael@0 327 * @param pattern The pattern specifying the message's format
michael@0 328 * @param patternLength The length of pattern
michael@0 329 * @param source The text to parse.
michael@0 330 * @param sourceLength The length of source, or -1 if null-terminated.
michael@0 331 * @param parseError A pointer to UParseError to receive information about errors
michael@0 332 * occurred during parsing.
michael@0 333 * @param status A pointer to an UErrorCode to receive any errors
michael@0 334 * @param ... A variable-length argument list containing the arguments
michael@0 335 * specified in pattern.
michael@0 336 * @see u_formatMessage
michael@0 337 * @stable ICU 2.0
michael@0 338 */
michael@0 339 U_STABLE void U_EXPORT2
michael@0 340 u_parseMessageWithError(const char *locale,
michael@0 341 const UChar *pattern,
michael@0 342 int32_t patternLength,
michael@0 343 const UChar *source,
michael@0 344 int32_t sourceLength,
michael@0 345 UParseError *parseError,
michael@0 346 UErrorCode *status,
michael@0 347 ...);
michael@0 348
michael@0 349 /**
michael@0 350 * Parse a message.
michael@0 351 * For numeric arguments, this function will always use doubles. Integer types
michael@0 352 * should not be passed.
michael@0 353 * This function is not able to parse all output from {@link #u_formatMessage }.
michael@0 354 * @param locale The locale for which the message is formatted
michael@0 355 * @param pattern The pattern specifying the message's format
michael@0 356 * @param patternLength The length of pattern
michael@0 357 * @param source The text to parse.
michael@0 358 * @param sourceLength The length of source, or -1 if null-terminated.
michael@0 359 * @param ap A variable-length argument list containing the arguments
michael@0 360 * @param parseError A pointer to UParseError to receive information about errors
michael@0 361 * occurred during parsing.
michael@0 362 * @param status A pointer to an UErrorCode to receive any errors
michael@0 363 * specified in pattern.
michael@0 364 * @see u_formatMessage
michael@0 365 * @stable ICU 2.0
michael@0 366 */
michael@0 367 U_STABLE void U_EXPORT2
michael@0 368 u_vparseMessageWithError(const char *locale,
michael@0 369 const UChar *pattern,
michael@0 370 int32_t patternLength,
michael@0 371 const UChar *source,
michael@0 372 int32_t sourceLength,
michael@0 373 va_list ap,
michael@0 374 UParseError *parseError,
michael@0 375 UErrorCode* status);
michael@0 376
michael@0 377 /*----------------------- New experimental API --------------------------- */
michael@0 378 /**
michael@0 379 * The message format object
michael@0 380 * @stable ICU 2.0
michael@0 381 */
michael@0 382 typedef void* UMessageFormat;
michael@0 383
michael@0 384
michael@0 385 /**
michael@0 386 * Open a message formatter with given pattern and for the given locale.
michael@0 387 * @param pattern A pattern specifying the format to use.
michael@0 388 * @param patternLength Length of the pattern to use
michael@0 389 * @param locale The locale for which the messages are formatted.
michael@0 390 * @param parseError A pointer to UParseError struct to receive any errors
michael@0 391 * occured during parsing. Can be NULL.
michael@0 392 * @param status A pointer to an UErrorCode to receive any errors.
michael@0 393 * @return A pointer to a UMessageFormat to use for formatting
michael@0 394 * messages, or 0 if an error occurred.
michael@0 395 * @stable ICU 2.0
michael@0 396 */
michael@0 397 U_STABLE UMessageFormat* U_EXPORT2
michael@0 398 umsg_open( const UChar *pattern,
michael@0 399 int32_t patternLength,
michael@0 400 const char *locale,
michael@0 401 UParseError *parseError,
michael@0 402 UErrorCode *status);
michael@0 403
michael@0 404 /**
michael@0 405 * Close a UMessageFormat.
michael@0 406 * Once closed, a UMessageFormat may no longer be used.
michael@0 407 * @param format The formatter to close.
michael@0 408 * @stable ICU 2.0
michael@0 409 */
michael@0 410 U_STABLE void U_EXPORT2
michael@0 411 umsg_close(UMessageFormat* format);
michael@0 412
michael@0 413 #if U_SHOW_CPLUSPLUS_API
michael@0 414
michael@0 415 U_NAMESPACE_BEGIN
michael@0 416
michael@0 417 /**
michael@0 418 * \class LocalUMessageFormatPointer
michael@0 419 * "Smart pointer" class, closes a UMessageFormat via umsg_close().
michael@0 420 * For most methods see the LocalPointerBase base class.
michael@0 421 *
michael@0 422 * @see LocalPointerBase
michael@0 423 * @see LocalPointer
michael@0 424 * @stable ICU 4.4
michael@0 425 */
michael@0 426 U_DEFINE_LOCAL_OPEN_POINTER(LocalUMessageFormatPointer, UMessageFormat, umsg_close);
michael@0 427
michael@0 428 U_NAMESPACE_END
michael@0 429
michael@0 430 #endif
michael@0 431
michael@0 432 /**
michael@0 433 * Open a copy of a UMessageFormat.
michael@0 434 * This function performs a deep copy.
michael@0 435 * @param fmt The formatter to copy
michael@0 436 * @param status A pointer to an UErrorCode to receive any errors.
michael@0 437 * @return A pointer to a UDateFormat identical to fmt.
michael@0 438 * @stable ICU 2.0
michael@0 439 */
michael@0 440 U_STABLE UMessageFormat U_EXPORT2
michael@0 441 umsg_clone(const UMessageFormat *fmt,
michael@0 442 UErrorCode *status);
michael@0 443
michael@0 444 /**
michael@0 445 * Sets the locale. This locale is used for fetching default number or date
michael@0 446 * format information.
michael@0 447 * @param fmt The formatter to set
michael@0 448 * @param locale The locale the formatter should use.
michael@0 449 * @stable ICU 2.0
michael@0 450 */
michael@0 451 U_STABLE void U_EXPORT2
michael@0 452 umsg_setLocale(UMessageFormat *fmt,
michael@0 453 const char* locale);
michael@0 454
michael@0 455 /**
michael@0 456 * Gets the locale. This locale is used for fetching default number or date
michael@0 457 * format information.
michael@0 458 * @param fmt The formatter to querry
michael@0 459 * @return the locale.
michael@0 460 * @stable ICU 2.0
michael@0 461 */
michael@0 462 U_STABLE const char* U_EXPORT2
michael@0 463 umsg_getLocale(const UMessageFormat *fmt);
michael@0 464
michael@0 465 /**
michael@0 466 * Sets the pattern.
michael@0 467 * @param fmt The formatter to use
michael@0 468 * @param pattern The pattern to be applied.
michael@0 469 * @param patternLength Length of the pattern to use
michael@0 470 * @param parseError Struct to receive information on position
michael@0 471 * of error if an error is encountered.Can be NULL.
michael@0 472 * @param status Output param set to success/failure code on
michael@0 473 * exit. If the pattern is invalid, this will be
michael@0 474 * set to a failure result.
michael@0 475 * @stable ICU 2.0
michael@0 476 */
michael@0 477 U_STABLE void U_EXPORT2
michael@0 478 umsg_applyPattern( UMessageFormat *fmt,
michael@0 479 const UChar* pattern,
michael@0 480 int32_t patternLength,
michael@0 481 UParseError* parseError,
michael@0 482 UErrorCode* status);
michael@0 483
michael@0 484 /**
michael@0 485 * Gets the pattern.
michael@0 486 * @param fmt The formatter to use
michael@0 487 * @param result A pointer to a buffer to receive the pattern.
michael@0 488 * @param resultLength The maximum size of result.
michael@0 489 * @param status Output param set to success/failure code on
michael@0 490 * exit. If the pattern is invalid, this will be
michael@0 491 * set to a failure result.
michael@0 492 * @return the pattern of the format
michael@0 493 * @stable ICU 2.0
michael@0 494 */
michael@0 495 U_STABLE int32_t U_EXPORT2
michael@0 496 umsg_toPattern(const UMessageFormat *fmt,
michael@0 497 UChar* result,
michael@0 498 int32_t resultLength,
michael@0 499 UErrorCode* status);
michael@0 500
michael@0 501 /**
michael@0 502 * Format a message for a locale.
michael@0 503 * This function may perform re-ordering of the arguments depending on the
michael@0 504 * locale. For all numeric arguments, double is assumed unless the type is
michael@0 505 * explicitly integer. All choice format arguments must be of type double.
michael@0 506 * @param fmt The formatter to use
michael@0 507 * @param result A pointer to a buffer to receive the formatted message.
michael@0 508 * @param resultLength The maximum size of result.
michael@0 509 * @param status A pointer to an UErrorCode to receive any errors
michael@0 510 * @param ... A variable-length argument list containing the arguments
michael@0 511 * specified in pattern.
michael@0 512 * @return The total buffer size needed; if greater than resultLength,
michael@0 513 * the output was truncated.
michael@0 514 * @stable ICU 2.0
michael@0 515 */
michael@0 516 U_STABLE int32_t U_EXPORT2
michael@0 517 umsg_format( const UMessageFormat *fmt,
michael@0 518 UChar *result,
michael@0 519 int32_t resultLength,
michael@0 520 UErrorCode *status,
michael@0 521 ...);
michael@0 522
michael@0 523 /**
michael@0 524 * Format a message for a locale.
michael@0 525 * This function may perform re-ordering of the arguments depending on the
michael@0 526 * locale. For all numeric arguments, double is assumed unless the type is
michael@0 527 * explicitly integer. All choice format arguments must be of type double.
michael@0 528 * @param fmt The formatter to use
michael@0 529 * @param result A pointer to a buffer to receive the formatted message.
michael@0 530 * @param resultLength The maximum size of result.
michael@0 531 * @param ap A variable-length argument list containing the arguments
michael@0 532 * @param status A pointer to an UErrorCode to receive any errors
michael@0 533 * specified in pattern.
michael@0 534 * @return The total buffer size needed; if greater than resultLength,
michael@0 535 * the output was truncated.
michael@0 536 * @stable ICU 2.0
michael@0 537 */
michael@0 538 U_STABLE int32_t U_EXPORT2
michael@0 539 umsg_vformat( const UMessageFormat *fmt,
michael@0 540 UChar *result,
michael@0 541 int32_t resultLength,
michael@0 542 va_list ap,
michael@0 543 UErrorCode *status);
michael@0 544
michael@0 545 /**
michael@0 546 * Parse a message.
michael@0 547 * For numeric arguments, this function will always use doubles. Integer types
michael@0 548 * should not be passed.
michael@0 549 * This function is not able to parse all output from {@link #umsg_format }.
michael@0 550 * @param fmt The formatter to use
michael@0 551 * @param source The text to parse.
michael@0 552 * @param sourceLength The length of source, or -1 if null-terminated.
michael@0 553 * @param count Output param to receive number of elements returned.
michael@0 554 * @param status A pointer to an UErrorCode to receive any errors
michael@0 555 * @param ... A variable-length argument list containing the arguments
michael@0 556 * specified in pattern.
michael@0 557 * @stable ICU 2.0
michael@0 558 */
michael@0 559 U_STABLE void U_EXPORT2
michael@0 560 umsg_parse( const UMessageFormat *fmt,
michael@0 561 const UChar *source,
michael@0 562 int32_t sourceLength,
michael@0 563 int32_t *count,
michael@0 564 UErrorCode *status,
michael@0 565 ...);
michael@0 566
michael@0 567 /**
michael@0 568 * Parse a message.
michael@0 569 * For numeric arguments, this function will always use doubles. Integer types
michael@0 570 * should not be passed.
michael@0 571 * This function is not able to parse all output from {@link #umsg_format }.
michael@0 572 * @param fmt The formatter to use
michael@0 573 * @param source The text to parse.
michael@0 574 * @param sourceLength The length of source, or -1 if null-terminated.
michael@0 575 * @param count Output param to receive number of elements returned.
michael@0 576 * @param ap A variable-length argument list containing the arguments
michael@0 577 * @param status A pointer to an UErrorCode to receive any errors
michael@0 578 * specified in pattern.
michael@0 579 * @see u_formatMessage
michael@0 580 * @stable ICU 2.0
michael@0 581 */
michael@0 582 U_STABLE void U_EXPORT2
michael@0 583 umsg_vparse(const UMessageFormat *fmt,
michael@0 584 const UChar *source,
michael@0 585 int32_t sourceLength,
michael@0 586 int32_t *count,
michael@0 587 va_list ap,
michael@0 588 UErrorCode *status);
michael@0 589
michael@0 590
michael@0 591 /**
michael@0 592 * Convert an 'apostrophe-friendly' pattern into a standard
michael@0 593 * pattern. Standard patterns treat all apostrophes as
michael@0 594 * quotes, which is problematic in some languages, e.g.
michael@0 595 * French, where apostrophe is commonly used. This utility
michael@0 596 * assumes that only an unpaired apostrophe immediately before
michael@0 597 * a brace is a true quote. Other unpaired apostrophes are paired,
michael@0 598 * and the resulting standard pattern string is returned.
michael@0 599 *
michael@0 600 * <p><b>Note</b> it is not guaranteed that the returned pattern
michael@0 601 * is indeed a valid pattern. The only effect is to convert
michael@0 602 * between patterns having different quoting semantics.
michael@0 603 *
michael@0 604 * @param pattern the 'apostrophe-friendly' patttern to convert
michael@0 605 * @param patternLength the length of pattern, or -1 if unknown and pattern is null-terminated
michael@0 606 * @param dest the buffer for the result, or NULL if preflight only
michael@0 607 * @param destCapacity the length of the buffer, or 0 if preflighting
michael@0 608 * @param ec the error code
michael@0 609 * @return the length of the resulting text, not including trailing null
michael@0 610 * if buffer has room for the trailing null, it is provided, otherwise
michael@0 611 * not
michael@0 612 * @stable ICU 3.4
michael@0 613 */
michael@0 614 U_STABLE int32_t U_EXPORT2
michael@0 615 umsg_autoQuoteApostrophe(const UChar* pattern,
michael@0 616 int32_t patternLength,
michael@0 617 UChar* dest,
michael@0 618 int32_t destCapacity,
michael@0 619 UErrorCode* ec);
michael@0 620
michael@0 621 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 622
michael@0 623 #endif

mercurial