]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/main.cpp
1 /********************************************************************
3 * Copyright (c) 1999-2003, 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
;
37 UErrorCode status
= U_ZERO_ERROR
;
38 Locale
greece("el", "GR");
39 UnicodeString str
, str2
;
41 // Create a calendar in the Greek locale
42 cal
= Calendar::createInstance(greece
, status
);
43 check(status
, "Calendar::createInstance");
46 fmt
= DateFormat::createDateInstance(DateFormat::kFull
, greece
);
47 fmt
->setCalendar(*cal
);
49 // Create a default formatter
50 defFmt
= DateFormat::createDateInstance(DateFormat::kFull
);
51 defFmt
->setCalendar(*cal
);
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");
60 // Create a custom Transliterator
61 rbtUnaccent
= Transliterator::createFromRules("RBTUnaccent",
66 check(status
, "Transliterator::createFromRules");
68 // Create a custom Transliterator
69 unaccent
= new UnaccentTransliterator();
71 // Loop over various months
72 for (int32_t month
= Calendar::JANUARY
;
73 month
<= Calendar::DECEMBER
;
76 // Set the calendar to a date
78 cal
->set(1999, month
, 4);
80 // Format the date in default locale
82 defFmt
->format(cal
->getTime(status
), str
, status
);
83 check(status
, "DateFormat::format");
88 // Format the date for Greece
90 fmt
->format(cal
->getTime(status
), str
, status
);
91 check(status
, "DateFormat::format");
92 printf("Greek formatted date: ");
96 // Transliterate result
97 greek_latin
->transliterate(str
);
98 printf("Transliterated via Greek-Latin: ");
102 // Transliterate result
104 rbtUnaccent
->transliterate(str
);
105 printf("Transliterated via RBT unaccent: ");
106 uprintf(escape(str
));
109 unaccent
->transliterate(str2
);
110 printf("Transliterated via normalizer unaccent: ");
111 uprintf(escape(str2
));
122 printf("Exiting successfully\n");