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