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/rbt.h"
13 #include "unicode/unistr.h"
14 #include "unicode/calendar.h"
15 #include "unicode/datefmt.h"
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include "util.h"
19 #include "unaccent.h"
20
21 // RuleBasedTransliterator rules to remove accents from characters
22 // so they can be displayed as ASCIIx
23 UnicodeString UNACCENT_RULES(
24 "[\\u00C0-\\u00C5] > A;"
25 "[\\u00C8-\\u00CB] > E;"
26 "[\\u00CC-\\u00CF] > I;"
27 "[\\u00E0-\\u00E5] > a;"
28 "[\\u00E8-\\u00EB] > e;"
29 "[\\u00EC-\\u00EF] > i;"
30 );
31
main(int argc,char ** argv)32 int main(int argc, char **argv) {
33
34 Calendar *cal;
35 DateFormat *fmt;
36 DateFormat *defFmt;
37 Transliterator *greek_latin;
38 Transliterator *rbtUnaccent;
39 Transliterator *unaccent;
40 UErrorCode status = U_ZERO_ERROR;
41 Locale greece("el", "GR");
42 UnicodeString str, str2;
43
44 // Create a calendar in the Greek locale
45 cal = Calendar::createInstance(greece, status);
46 check(status, "Calendar::createInstance");
47
48 // Create a formatter
49 fmt = DateFormat::createDateInstance(DateFormat::kFull, greece);
50 fmt->setCalendar(*cal);
51
52 // Create a default formatter
53 defFmt = DateFormat::createDateInstance(DateFormat::kFull);
54 defFmt->setCalendar(*cal);
55
56 // Create a Greek-Latin Transliterator
57 greek_latin = Transliterator::createInstance("Greek-Latin");
58 if (greek_latin == 0) {
59 printf("ERROR: Transliterator::createInstance() failed\n");
60 exit(1);
61 }
62
63 // Create a custom Transliterator
64 rbtUnaccent = new RuleBasedTransliterator("RBTUnaccent",
65 UNACCENT_RULES,
66 UTRANS_FORWARD,
67 status);
68 check(status, "RuleBasedTransliterator::ct");
69
70 // Create a custom Transliterator
71 unaccent = new UnaccentTransliterator();
72
73 // Loop over various months
74 for (int32_t month = Calendar::JANUARY;
75 month <= Calendar::DECEMBER;
76 ++month) {
77
78 // Set the calendar to a date
79 cal->clear();
80 cal->set(1999, month, 4);
81
82 // Format the date in default locale
83 str.remove();
84 defFmt->format(cal->getTime(status), str, status);
85 check(status, "DateFormat::format");
86 printf("Date: ");
87 uprintf(escape(str));
88 printf("\n");
89
90 // Format the date for Greece
91 str.remove();
92 fmt->format(cal->getTime(status), str, status);
93 check(status, "DateFormat::format");
94 printf("Greek formatted date: ");
95 uprintf(escape(str));
96 printf("\n");
97
98 // Transliterate result
99 greek_latin->transliterate(str);
100 printf("Transliterated via Greek-Latin: ");
101 uprintf(escape(str));
102 printf("\n");
103
104 // Transliterate result
105 str2 = str;
106 rbtUnaccent->transliterate(str);
107 printf("Transliterated via RBT unaccent: ");
108 uprintf(escape(str));
109 printf("\n");
110
111 unaccent->transliterate(str2);
112 printf("Transliterated via normalizer unaccent: ");
113 uprintf(escape(str2));
114 printf("\n\n");
115 }
116
117 // Clean up
118 delete fmt;
119 delete cal;
120 delete greek_latin;
121 delete unaccent;
122 delete rbtUnaccent;
123
124 printf("Exiting successfully\n");
125 return 0;
126 }
127