Home | History | Annotate | Download | only in answers
      1 /**********************************************************************
      2  *  2016 and later: Unicode, Inc. and others.
      3  * License & terms of use: http://www.unicode.org/copyright.html#License
      4  ***********************************************************************
      5  ***********************************************************************
      6  * COPYRIGHT:
      7  * Copyright (c) 1999-2002, International Business Machines Corporation and
      8  * others. All Rights Reserved.
      9  ***********************************************************************/
     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.
     20 static UnicodeString PATTERN(
     21     "Received {0,choice,0#no|1#one|1& {0,number,integer}} arguments"
     22     " on {1,date,long}."
     23 );
     24 
     25 int 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 }
     51