]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/answers/main_3.cpp
1 /***********************************************************************
2 * © 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
4 ***********************************************************************
5 ***********************************************************************
7 * Copyright (c) 1999-2002, International Business Machines Corporation and
8 * others. All Rights Reserved.
9 ***********************************************************************/
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"
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;"
32 int main(int argc
, char **argv
) {
37 Transliterator
*greek_latin
;
38 Transliterator
*rbtUnaccent
;
39 UErrorCode status
= U_ZERO_ERROR
;
40 Locale
greece("el", "GR");
41 UnicodeString str
, str2
;
43 // Create a calendar in the Greek locale
44 cal
= Calendar::createInstance(greece
, status
);
45 check(status
, "Calendar::createInstance");
48 fmt
= DateFormat::createDateInstance(DateFormat::kFull
, greece
);
49 fmt
->setCalendar(*cal
);
51 // Create a default formatter
52 defFmt
= DateFormat::createDateInstance(DateFormat::kFull
);
53 defFmt
->setCalendar(*cal
);
55 // Create a Greek-Latin Transliterator
56 greek_latin
= Transliterator::createInstance("Greek-Latin");
57 if (greek_latin
== 0) {
58 printf("ERROR: Transliterator::createInstance() failed\n");
62 // Create a custom Transliterator
63 rbtUnaccent
= new RuleBasedTransliterator("RBTUnaccent",
67 check(status
, "RuleBasedTransliterator::ct");
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
));
114 printf("Exiting successfully\n");