]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/answers/main_2.cpp
1 /***********************************************************************
2 * © 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
4 ***********************************************************************
5 ***********************************************************************
7 * Copyright (c) 1999-2002, International Business Machines Corporation and
8 * others. All Rights Reserved.
9 ***********************************************************************/
11 #include "unicode/translit.h"
12 #include "unicode/rbt.h"
13 #include "unicode/unistr.h"
14 #include "unicode/calendar.h"
15 #include "unicode/datefmt.h"
21 int main(int argc
, char **argv
) {
26 Transliterator
*greek_latin
;
27 UErrorCode status
= U_ZERO_ERROR
;
28 Locale
greece("el", "GR");
29 UnicodeString str
, str2
;
31 // Create a calendar in the Greek locale
32 cal
= Calendar::createInstance(greece
, status
);
33 check(status
, "Calendar::createInstance");
36 fmt
= DateFormat::createDateInstance(DateFormat::kFull
, greece
);
37 fmt
->setCalendar(*cal
);
39 // Create a default formatter
40 defFmt
= DateFormat::createDateInstance(DateFormat::kFull
);
41 defFmt
->setCalendar(*cal
);
43 // Create a Greek-Latin Transliterator
44 greek_latin
= Transliterator::createInstance("Greek-Latin");
45 if (greek_latin
== 0) {
46 printf("ERROR: Transliterator::createInstance() failed\n");
50 // Loop over various months
51 for (int32_t month
= Calendar::JANUARY
;
52 month
<= Calendar::DECEMBER
;
55 // Set the calendar to a date
57 cal
->set(1999, month
, 4);
59 // Format the date in default locale
61 defFmt
->format(cal
->getTime(status
), str
, status
);
62 check(status
, "DateFormat::format");
67 // Format the date for Greece
69 fmt
->format(cal
->getTime(status
), str
, status
);
70 check(status
, "DateFormat::format");
71 printf("Greek formatted date: ");
75 // Transliterate result
76 greek_latin
->transliterate(str
);
77 printf("Transliterated via Greek-Latin: ");
87 printf("Exiting successfully\n");