2002-12-06 01:40:42 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (c) 1999-2003, International Business Machines Corporation and
|
2002-12-06 01:40:42 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
|
2000-09-06 19:49:13 +00:00
|
|
|
#include "unicode/translit.h"
|
2003-05-29 22:10:20 +00:00
|
|
|
//#include "unicode/rbt.h"
|
2000-09-06 19:49:13 +00:00
|
|
|
#include "unicode/unistr.h"
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/datefmt.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "util.h"
|
2003-05-29 22:10:20 +00:00
|
|
|
#include "unaccent.h"
|
|
|
|
|
|
|
|
// RuleBasedTransliterator rules to remove accents from characters
|
|
|
|
// so they can be displayed as ASCIIx
|
|
|
|
UnicodeString UNACCENT_RULES(
|
|
|
|
"[\\u00C0-\\u00C5] > A;"
|
|
|
|
"[\\u00C8-\\u00CB] > E;"
|
|
|
|
"[\\u00CC-\\u00CF] > I;"
|
|
|
|
"[\\u00E0-\\u00E5] > a;"
|
|
|
|
"[\\u00E8-\\u00EB] > e;"
|
|
|
|
"[\\u00EC-\\u00EF] > i;"
|
|
|
|
);
|
2000-09-06 19:49:13 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
Calendar *cal;
|
|
|
|
DateFormat *fmt;
|
|
|
|
DateFormat *defFmt;
|
2003-05-29 22:10:20 +00:00
|
|
|
Transliterator *greek_latin;
|
|
|
|
Transliterator *rbtUnaccent;
|
|
|
|
Transliterator *unaccent;
|
|
|
|
UParseError pError;
|
2000-09-06 19:49:13 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
Locale greece("el", "GR");
|
|
|
|
UnicodeString str, str2;
|
|
|
|
|
|
|
|
// Create a calendar in the Greek locale
|
|
|
|
cal = Calendar::createInstance(greece, status);
|
|
|
|
check(status, "Calendar::createInstance");
|
|
|
|
|
|
|
|
// Create a formatter
|
|
|
|
fmt = DateFormat::createDateInstance(DateFormat::kFull, greece);
|
|
|
|
fmt->setCalendar(*cal);
|
|
|
|
|
|
|
|
// Create a default formatter
|
|
|
|
defFmt = DateFormat::createDateInstance(DateFormat::kFull);
|
|
|
|
defFmt->setCalendar(*cal);
|
|
|
|
|
2003-05-29 22:10:20 +00:00
|
|
|
// Create a Greek-Latin Transliterator
|
|
|
|
greek_latin = Transliterator::createInstance("Greek-Latin", UTRANS_FORWARD, status);
|
|
|
|
if (greek_latin == 0) {
|
|
|
|
printf("ERROR: Transliterator::createInstance() failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a custom Transliterator
|
|
|
|
rbtUnaccent = Transliterator::createFromRules("RBTUnaccent",
|
|
|
|
UNACCENT_RULES,
|
|
|
|
UTRANS_FORWARD,
|
|
|
|
pError,
|
|
|
|
status);
|
|
|
|
check(status, "Transliterator::createFromRules");
|
|
|
|
|
|
|
|
// Create a custom Transliterator
|
|
|
|
unaccent = new UnaccentTransliterator();
|
|
|
|
|
2000-09-06 19:49:13 +00:00
|
|
|
// Loop over various months
|
|
|
|
for (int32_t month = Calendar::JANUARY;
|
|
|
|
month <= Calendar::DECEMBER;
|
|
|
|
++month) {
|
|
|
|
|
|
|
|
// Set the calendar to a date
|
|
|
|
cal->clear();
|
|
|
|
cal->set(1999, month, 4);
|
|
|
|
|
|
|
|
// Format the date in default locale
|
|
|
|
str.remove();
|
2003-05-29 22:10:20 +00:00
|
|
|
defFmt->format(cal->getTime(status), str, status);
|
2000-09-06 19:49:13 +00:00
|
|
|
check(status, "DateFormat::format");
|
|
|
|
printf("Date: ");
|
|
|
|
uprintf(escape(str));
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
// Format the date for Greece
|
|
|
|
str.remove();
|
2003-05-29 22:10:20 +00:00
|
|
|
fmt->format(cal->getTime(status), str, status);
|
2000-09-06 19:49:13 +00:00
|
|
|
check(status, "DateFormat::format");
|
|
|
|
printf("Greek formatted date: ");
|
|
|
|
uprintf(escape(str));
|
2003-05-29 22:10:20 +00:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
// Transliterate result
|
|
|
|
greek_latin->transliterate(str);
|
|
|
|
printf("Transliterated via Greek-Latin: ");
|
|
|
|
uprintf(escape(str));
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
// Transliterate result
|
|
|
|
str2 = str;
|
|
|
|
rbtUnaccent->transliterate(str);
|
|
|
|
printf("Transliterated via RBT unaccent: ");
|
|
|
|
uprintf(escape(str));
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
unaccent->transliterate(str2);
|
|
|
|
printf("Transliterated via normalizer unaccent: ");
|
|
|
|
uprintf(escape(str2));
|
2000-09-06 19:49:13 +00:00
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
delete fmt;
|
|
|
|
delete cal;
|
2003-05-29 22:10:20 +00:00
|
|
|
delete greek_latin;
|
|
|
|
delete unaccent;
|
|
|
|
delete rbtUnaccent;
|
2000-09-06 19:49:13 +00:00
|
|
|
|
|
|
|
printf("Exiting successfully\n");
|
|
|
|
return 0;
|
|
|
|
}
|