1 /******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 1999-2002, 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 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 UErrorCode status = U_ZERO_ERROR; 36 Locale greece("el", "GR"); 37 UnicodeString str, str2; 38 39 // Create a calendar in the Greek locale 40 cal = Calendar::createInstance(greece, status); 41 check(status, "Calendar::createInstance"); 42 43 // Create a formatter 44 fmt = DateFormat::createDateInstance(DateFormat::kFull, greece); 45 fmt->setCalendar(*cal); 46 47 // Create a default formatter 48 defFmt = DateFormat::createDateInstance(DateFormat::kFull); 49 defFmt->setCalendar(*cal); 50 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"); 55 exit(1); 56 } 57 58 // Create a custom Transliterator 59 rbtUnaccent = new RuleBasedTransliterator("RBTUnaccent", 60 UNACCENT_RULES, 61 UTRANS_FORWARD, 62 status); 63 check(status, "RuleBasedTransliterator::ct"); 64 65 // Loop over various months 66 for (int32_t month = Calendar::JANUARY; 67 month <= Calendar::DECEMBER; 68 ++month) { 69 70 // Set the calendar to a date 71 cal->clear(); 72 cal->set(1999, month, 4); 73 74 // Format the date in default locale 75 str.remove(); 76 defFmt->format(cal->getTime(status), str, status); 77 check(status, "DateFormat::format"); 78 printf("Date: "); 79 uprintf(escape(str)); 80 printf("\n"); 81 82 // Format the date for Greece 83 str.remove(); 84 fmt->format(cal->getTime(status), str, status); 85 check(status, "DateFormat::format"); 86 printf("Greek formatted date: "); 87 uprintf(escape(str)); 88 printf("\n"); 89 90 // Transliterate result 91 greek_latin->transliterate(str); 92 printf("Transliterated via Greek-Latin: "); 93 uprintf(escape(str)); 94 printf("\n"); 95 96 // Transliterate result 97 str2 = str; 98 rbtUnaccent->transliterate(str); 99 printf("Transliterated via RBT unaccent: "); 100 uprintf(escape(str)); 101 printf("\n\n"); 102 } 103 104 // Clean up 105 delete fmt; 106 delete cal; 107 delete greek_latin; 108 delete rbtUnaccent; 109 110 printf("Exiting successfully\n"); 111 return 0; 112 } 113