]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/answers/main_3.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 UErrorCode status
= U_ZERO_ERROR
;
36 Locale
greece("el", "GR");
37 UnicodeString str
, str2
;
39 // Create a calendar in the Greek locale
40 cal
= Calendar::createInstance(greece
, status
);
41 check(status
, "Calendar::createInstance");
44 fmt
= DateFormat::createDateInstance(DateFormat::kFull
, greece
);
45 fmt
->setCalendar(*cal
);
47 // Create a default formatter
48 defFmt
= DateFormat::createDateInstance(DateFormat::kFull
);
49 defFmt
->setCalendar(*cal
);
51 // Create a Greek-Latin Transliterator
52 greek_latin
= Transliterator::createInstance("Greek-Latin");
53 if (greek_latin
== 0) {
54 printf("ERROR: Transliterator::createInstance() failed\n");
58 // Create a custom Transliterator
59 rbtUnaccent
= new RuleBasedTransliterator("RBTUnaccent",
63 check(status
, "RuleBasedTransliterator::ct");
65 // Loop over various months
66 for (int32_t month
= Calendar::JANUARY
;
67 month
<= Calendar::DECEMBER
;
70 // Set the calendar to a date
72 cal
->set(1999, month
, 4);
74 // Format the date in default locale
76 defFmt
->format(cal
->getTime(status
), str
, status
);
77 check(status
, "DateFormat::format");
82 // Format the date for Greece
84 fmt
->format(cal
->getTime(status
), str
, status
);
85 check(status
, "DateFormat::format");
86 printf("Greek formatted date: ");
90 // Transliterate result
91 greek_latin
->transliterate(str
);
92 printf("Transliterated via Greek-Latin: ");
96 // Transliterate result
98 rbtUnaccent
->transliterate(str
);
99 printf("Transliterated via RBT unaccent: ");
100 uprintf(escape(str
));
110 printf("Exiting successfully\n");