]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/answers/main_4.cpp
1 /********************************************************************
3 * Copyright (c) 1999-2002, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
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"
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;"
28 int main(int argc
, char **argv
) {
33 Transliterator
*greek_latin
;
34 Transliterator
*rbtUnaccent
;
35 Transliterator
*unaccent
;
36 UErrorCode status
= U_ZERO_ERROR
;
37 Locale
greece("el", "GR");
38 UnicodeString str
, str2
;
40 // Create a calendar in the Greek locale
41 cal
= Calendar::createInstance(greece
, status
);
42 check(status
, "Calendar::createInstance");
45 fmt
= DateFormat::createDateInstance(DateFormat::kFull
, greece
);
46 fmt
->setCalendar(*cal
);
48 // Create a default formatter
49 defFmt
= DateFormat::createDateInstance(DateFormat::kFull
);
50 defFmt
->setCalendar(*cal
);
52 // Create a Greek-Latin Transliterator
53 greek_latin
= Transliterator::createInstance("Greek-Latin");
54 if (greek_latin
== 0) {
55 printf("ERROR: Transliterator::createInstance() failed\n");
59 // Create a custom Transliterator
60 rbtUnaccent
= new RuleBasedTransliterator("RBTUnaccent",
64 check(status
, "RuleBasedTransliterator::ct");
66 // Create a custom Transliterator
67 unaccent
= new UnaccentTransliterator();
69 // Loop over various months
70 for (int32_t month
= Calendar::JANUARY
;
71 month
<= Calendar::DECEMBER
;
74 // Set the calendar to a date
76 cal
->set(1999, month
, 4);
78 // Format the date in default locale
80 defFmt
->format(cal
->getTime(status
), str
, status
);
81 check(status
, "DateFormat::format");
86 // Format the date for Greece
88 fmt
->format(cal
->getTime(status
), str
, status
);
89 check(status
, "DateFormat::format");
90 printf("Greek formatted date: ");
94 // Transliterate result
95 greek_latin
->transliterate(str
);
96 printf("Transliterated via Greek-Latin: ");
100 // Transliterate result
102 rbtUnaccent
->transliterate(str
);
103 printf("Transliterated via RBT unaccent: ");
104 uprintf(escape(str
));
107 unaccent
->transliterate(str2
);
108 printf("Transliterated via normalizer unaccent: ");
109 uprintf(escape(str2
));
120 printf("Exiting successfully\n");