1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copyright (c) 1999-2003, International Business Machines Corporation and
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h"
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/msgfmt.h"
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/calendar.h"
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "util.h"
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// The message format pattern.  It takes a single argument, an integer,
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// and formats it as "no", "one", or a number, using a NumberFormat.
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UnicodeString PATTERN(
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    "Received {0,choice,0#no arguments|1#one argument|2#{0,number,integer} arguments}"
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    " on {1,date,long}."
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru);
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint main(int argc, char **argv) {
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString str;
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    FieldPosition pos;
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Create a message format
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    MessageFormat msg(PATTERN, status);
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    check(status, "MessageFormat::ct");
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Create the argument list
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Formattable msgArgs[2];
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    msgArgs[0].setLong(argc-1);
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    msgArgs[1].setDate(Calendar::getNow());
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Format the arguments
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    msg.format(msgArgs, 2, str, pos, status);
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    check(status, "MessageFormat::format");
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("Message: ");
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprintf(str);
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("\n");
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("Exiting successfully\n");
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return 0;
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
47