]> git.saurik.com Git - apple/icu.git/blame - icuSources/samples/msgfmt/main.cpp
ICU-59180.0.1.tar.gz
[apple/icu.git] / icuSources / samples / msgfmt / main.cpp
CommitLineData
f3c0d7a5
A
1/**********************************************************************
2 * © 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
4 ***********************************************************************
5 ***********************************************************************
b75a7d8f
A
6 * COPYRIGHT:
7 * Copyright (c) 1999-2003, International Business Machines Corporation and
8 * others. All Rights Reserved.
f3c0d7a5 9 ***********************************************************************/
b75a7d8f
A
10
11#include "unicode/unistr.h"
12#include "unicode/msgfmt.h"
13#include "unicode/calendar.h"
14#include <stdio.h>
15#include <stdlib.h>
16#include "util.h"
17
18// The message format pattern. It takes a single argument, an integer,
19// and formats it as "no", "one", or a number, using a NumberFormat.
20static UnicodeString PATTERN(
21 "Received {0,choice,0#no arguments|1#one argument|2#{0,number,integer} arguments}"
22 " on {1,date,long}."
23);
24
25int main(int argc, char **argv) {
26
27 UErrorCode status = U_ZERO_ERROR;
28 UnicodeString str;
29 FieldPosition pos;
30
31 // Create a message format
32 MessageFormat msg(PATTERN, status);
33 check(status, "MessageFormat::ct");
34
35 // Create the argument list
36 Formattable msgArgs[2];
37 msgArgs[0].setLong(argc-1);
38 msgArgs[1].setDate(Calendar::getNow());
39
40 // Format the arguments
41 msg.format(msgArgs, 2, str, pos, status);
42 check(status, "MessageFormat::format");
43
44 printf("Message: ");
45 uprintf(str);
46 printf("\n");
47
48 printf("Exiting successfully\n");
49 return 0;
50}