• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***********************************************************************
2  * © 2016 and later: Unicode, Inc. and others.
3  * License & terms of use: http://www.unicode.org/copyright.html
4  ***********************************************************************
5  ***********************************************************************
6  * COPYRIGHT:
7  * Copyright (c) 1999-2002, International Business Machines Corporation and
8  * others. All Rights Reserved.
9  ***********************************************************************/
10 
11 #include "unicode/translit.h"
12 #include "unicode/unistr.h"
13 #include "unicode/calendar.h"
14 #include "unicode/datefmt.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "util.h"
18 #include "unaccent.h"
19 
20 using icu::Transliterator;
21 
main(int argc,char ** argv)22 int main(int argc, char **argv) {
23 
24     Calendar *cal;
25     DateFormat *fmt;
26     DateFormat *defFmt;
27     Transliterator *greek_latin;
28     UErrorCode status = U_ZERO_ERROR;
29     Locale greece("el", "GR");
30     UnicodeString str, str2;
31 
32     // Create a calendar in the Greek locale
33     cal = Calendar::createInstance(greece, status);
34     check(status, "Calendar::createInstance");
35 
36     // Create a formatter
37     fmt = DateFormat::createDateInstance(DateFormat::kFull, greece);
38     fmt->setCalendar(*cal);
39 
40     // Create a default formatter
41     defFmt = DateFormat::createDateInstance(DateFormat::kFull);
42     defFmt->setCalendar(*cal);
43 
44     // Create a Greek-Latin Transliterator
45     greek_latin = Transliterator::createInstance("Greek-Latin", UTRANS_FORWARD, status);
46     if (greek_latin == nullptr) {
47         printf("ERROR: Transliterator::createInstance() failed\n");
48         exit(1);
49     }
50 
51     // Loop over various months
52     for (int32_t month = Calendar::JANUARY;
53          month <= Calendar::DECEMBER;
54          ++month) {
55 
56         // Set the calendar to a date
57         cal->clear();
58         cal->set(1999, month, 4);
59 
60         // Format the date in default locale
61         str.remove();
62         defFmt->format(cal->getTime(status), str, status);
63         check(status, "DateFormat::format");
64         printf("Date: ");
65         uprintf(escape(str));
66         printf("\n");
67 
68         // Format the date for Greece
69         str.remove();
70         fmt->format(cal->getTime(status), str, status);
71         check(status, "DateFormat::format");
72         printf("Greek formatted date: ");
73         uprintf(escape(str));
74         printf("\n");
75 
76         // Transliterate result
77         greek_latin->transliterate(str);
78         printf("Transliterated via Greek-Latin: ");
79         uprintf(escape(str));
80         printf("\n\n");
81     }
82 
83     // Clean up
84     delete fmt;
85     delete cal;
86     delete greek_latin;
87 
88     printf("Exiting successfully\n");
89     return 0;
90 }
91