1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copyright (c) 1999-2002, International Business Machines Corporation and 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/translit.h" 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/rbt.h" 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h" 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/calendar.h" 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/datefmt.h" 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h> 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "util.h" 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unaccent.h" 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// RuleBasedTransliterator rules to remove accents from characters 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// so they can be displayed as ASCIIx 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUnicodeString UNACCENT_RULES( 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00C0-\\u00C5] > A;" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00C8-\\u00CB] > E;" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00CC-\\u00CF] > I;" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00E0-\\u00E5] > a;" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00E8-\\u00EB] > e;" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00EC-\\u00EF] > i;" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ); 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint main(int argc, char **argv) { 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Calendar *cal; 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DateFormat *fmt; 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DateFormat *defFmt; 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator *greek_latin; 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator *rbtUnaccent; 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale greece("el", "GR"); 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString str, str2; 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Create a calendar in the Greek locale 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cal = Calendar::createInstance(greece, status); 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru check(status, "Calendar::createInstance"); 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Create a formatter 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fmt = DateFormat::createDateInstance(DateFormat::kFull, greece); 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fmt->setCalendar(*cal); 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Create a default formatter 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru defFmt = DateFormat::createDateInstance(DateFormat::kFull); 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru defFmt->setCalendar(*cal); 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Create a Greek-Latin Transliterator 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru greek_latin = Transliterator::createInstance("Greek-Latin"); 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (greek_latin == 0) { 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("ERROR: Transliterator::createInstance() failed\n"); 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(1); 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Create a custom Transliterator 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rbtUnaccent = new RuleBasedTransliterator("RBTUnaccent", 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UNACCENT_RULES, 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTRANS_FORWARD, 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status); 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru check(status, "RuleBasedTransliterator::ct"); 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Loop over various months 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int32_t month = Calendar::JANUARY; 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru month <= Calendar::DECEMBER; 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++month) { 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Set the calendar to a date 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cal->clear(); 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cal->set(1999, month, 4); 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Format the date in default locale 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru str.remove(); 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru defFmt->format(cal->getTime(status), str, status); 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru check(status, "DateFormat::format"); 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("Date: "); 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprintf(escape(str)); 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("\n"); 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Format the date for Greece 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru str.remove(); 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fmt->format(cal->getTime(status), str, status); 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru check(status, "DateFormat::format"); 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("Greek formatted date: "); 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprintf(escape(str)); 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("\n"); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Transliterate result 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru greek_latin->transliterate(str); 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("Transliterated via Greek-Latin: "); 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprintf(escape(str)); 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("\n"); 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Transliterate result 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru str2 = str; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rbtUnaccent->transliterate(str); 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("Transliterated via RBT unaccent: "); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprintf(escape(str)); 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("\n\n"); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Clean up 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete fmt; 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete cal; 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete greek_latin; 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete rbtUnaccent; 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("Exiting successfully\n"); 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 0; 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 113