~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/samples/msgfmt/answers/main_3.cpp

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

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