12e5b6d6dSopenharmony_ci/***********************************************************************
22e5b6d6dSopenharmony_ci * © 2016 and later: Unicode, Inc. and others.
32e5b6d6dSopenharmony_ci * License & terms of use: http://www.unicode.org/copyright.html
42e5b6d6dSopenharmony_ci ***********************************************************************
52e5b6d6dSopenharmony_ci ***********************************************************************
62e5b6d6dSopenharmony_ci * COPYRIGHT:
72e5b6d6dSopenharmony_ci * Copyright (c) 1999-2002, International Business Machines Corporation and
82e5b6d6dSopenharmony_ci * others. All Rights Reserved.
92e5b6d6dSopenharmony_ci ***********************************************************************/
102e5b6d6dSopenharmony_ci
112e5b6d6dSopenharmony_ci#include "unicode/translit.h"
122e5b6d6dSopenharmony_ci#include "unicode/rbt.h"
132e5b6d6dSopenharmony_ci#include "unicode/unistr.h"
142e5b6d6dSopenharmony_ci#include "unicode/calendar.h"
152e5b6d6dSopenharmony_ci#include "unicode/datefmt.h"
162e5b6d6dSopenharmony_ci#include <stdio.h>
172e5b6d6dSopenharmony_ci#include <stdlib.h>
182e5b6d6dSopenharmony_ci#include "util.h"
192e5b6d6dSopenharmony_ci#include "unaccent.h"
202e5b6d6dSopenharmony_ci
212e5b6d6dSopenharmony_ci// RuleBasedTransliterator rules to remove accents from characters
222e5b6d6dSopenharmony_ci// so they can be displayed as ASCIIx
232e5b6d6dSopenharmony_ciUnicodeString UNACCENT_RULES(
242e5b6d6dSopenharmony_ci    "[\\u00C0-\\u00C5] > A;"
252e5b6d6dSopenharmony_ci    "[\\u00C8-\\u00CB] > E;"
262e5b6d6dSopenharmony_ci    "[\\u00CC-\\u00CF] > I;"
272e5b6d6dSopenharmony_ci    "[\\u00E0-\\u00E5] > a;"
282e5b6d6dSopenharmony_ci    "[\\u00E8-\\u00EB] > e;"
292e5b6d6dSopenharmony_ci    "[\\u00EC-\\u00EF] > i;"
302e5b6d6dSopenharmony_ci    );
312e5b6d6dSopenharmony_ci
322e5b6d6dSopenharmony_ciint main(int argc, char **argv) {
332e5b6d6dSopenharmony_ci
342e5b6d6dSopenharmony_ci    Calendar *cal;
352e5b6d6dSopenharmony_ci    DateFormat *fmt;
362e5b6d6dSopenharmony_ci    DateFormat *defFmt;
372e5b6d6dSopenharmony_ci    Transliterator *greek_latin;
382e5b6d6dSopenharmony_ci    Transliterator *rbtUnaccent;
392e5b6d6dSopenharmony_ci    Transliterator *unaccent;
402e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
412e5b6d6dSopenharmony_ci    Locale greece("el", "GR");
422e5b6d6dSopenharmony_ci    UnicodeString str, str2;
432e5b6d6dSopenharmony_ci
442e5b6d6dSopenharmony_ci    // Create a calendar in the Greek locale
452e5b6d6dSopenharmony_ci    cal = Calendar::createInstance(greece, status);
462e5b6d6dSopenharmony_ci    check(status, "Calendar::createInstance");
472e5b6d6dSopenharmony_ci
482e5b6d6dSopenharmony_ci    // Create a formatter
492e5b6d6dSopenharmony_ci    fmt = DateFormat::createDateInstance(DateFormat::kFull, greece);
502e5b6d6dSopenharmony_ci    fmt->setCalendar(*cal);
512e5b6d6dSopenharmony_ci
522e5b6d6dSopenharmony_ci    // Create a default formatter
532e5b6d6dSopenharmony_ci    defFmt = DateFormat::createDateInstance(DateFormat::kFull);
542e5b6d6dSopenharmony_ci    defFmt->setCalendar(*cal);
552e5b6d6dSopenharmony_ci
562e5b6d6dSopenharmony_ci    // Create a Greek-Latin Transliterator
572e5b6d6dSopenharmony_ci    greek_latin = Transliterator::createInstance("Greek-Latin");
582e5b6d6dSopenharmony_ci    if (greek_latin == 0) {
592e5b6d6dSopenharmony_ci        printf("ERROR: Transliterator::createInstance() failed\n");
602e5b6d6dSopenharmony_ci        exit(1);
612e5b6d6dSopenharmony_ci    }
622e5b6d6dSopenharmony_ci
632e5b6d6dSopenharmony_ci    // Create a custom Transliterator
642e5b6d6dSopenharmony_ci    rbtUnaccent = new RuleBasedTransliterator("RBTUnaccent",
652e5b6d6dSopenharmony_ci                                              UNACCENT_RULES,
662e5b6d6dSopenharmony_ci                                              UTRANS_FORWARD,
672e5b6d6dSopenharmony_ci                                              status);
682e5b6d6dSopenharmony_ci    check(status, "RuleBasedTransliterator::ct");
692e5b6d6dSopenharmony_ci
702e5b6d6dSopenharmony_ci    // Create a custom Transliterator
712e5b6d6dSopenharmony_ci    unaccent = new UnaccentTransliterator();
722e5b6d6dSopenharmony_ci
732e5b6d6dSopenharmony_ci    // Loop over various months
742e5b6d6dSopenharmony_ci    for (int32_t month = Calendar::JANUARY;
752e5b6d6dSopenharmony_ci         month <= Calendar::DECEMBER;
762e5b6d6dSopenharmony_ci         ++month) {
772e5b6d6dSopenharmony_ci
782e5b6d6dSopenharmony_ci        // Set the calendar to a date
792e5b6d6dSopenharmony_ci        cal->clear();
802e5b6d6dSopenharmony_ci        cal->set(1999, month, 4);
812e5b6d6dSopenharmony_ci
822e5b6d6dSopenharmony_ci        // Format the date in default locale
832e5b6d6dSopenharmony_ci        str.remove();
842e5b6d6dSopenharmony_ci        defFmt->format(cal->getTime(status), str, status);
852e5b6d6dSopenharmony_ci        check(status, "DateFormat::format");
862e5b6d6dSopenharmony_ci        printf("Date: ");
872e5b6d6dSopenharmony_ci        uprintf(escape(str));
882e5b6d6dSopenharmony_ci        printf("\n");
892e5b6d6dSopenharmony_ci
902e5b6d6dSopenharmony_ci        // Format the date for Greece
912e5b6d6dSopenharmony_ci        str.remove();
922e5b6d6dSopenharmony_ci        fmt->format(cal->getTime(status), str, status);
932e5b6d6dSopenharmony_ci        check(status, "DateFormat::format");
942e5b6d6dSopenharmony_ci        printf("Greek formatted date: ");
952e5b6d6dSopenharmony_ci        uprintf(escape(str));
962e5b6d6dSopenharmony_ci        printf("\n");
972e5b6d6dSopenharmony_ci
982e5b6d6dSopenharmony_ci        // Transliterate result
992e5b6d6dSopenharmony_ci        greek_latin->transliterate(str);
1002e5b6d6dSopenharmony_ci        printf("Transliterated via Greek-Latin: ");
1012e5b6d6dSopenharmony_ci        uprintf(escape(str));
1022e5b6d6dSopenharmony_ci        printf("\n");
1032e5b6d6dSopenharmony_ci
1042e5b6d6dSopenharmony_ci        // Transliterate result
1052e5b6d6dSopenharmony_ci        str2 = str;
1062e5b6d6dSopenharmony_ci        rbtUnaccent->transliterate(str);
1072e5b6d6dSopenharmony_ci        printf("Transliterated via RBT unaccent: ");
1082e5b6d6dSopenharmony_ci        uprintf(escape(str));
1092e5b6d6dSopenharmony_ci        printf("\n");
1102e5b6d6dSopenharmony_ci
1112e5b6d6dSopenharmony_ci        unaccent->transliterate(str2);
1122e5b6d6dSopenharmony_ci        printf("Transliterated via normalizer unaccent: ");
1132e5b6d6dSopenharmony_ci        uprintf(escape(str2));
1142e5b6d6dSopenharmony_ci        printf("\n\n");
1152e5b6d6dSopenharmony_ci    }
1162e5b6d6dSopenharmony_ci
1172e5b6d6dSopenharmony_ci    // Clean up
1182e5b6d6dSopenharmony_ci    delete fmt;
1192e5b6d6dSopenharmony_ci    delete cal;
1202e5b6d6dSopenharmony_ci    delete greek_latin;
1212e5b6d6dSopenharmony_ci    delete unaccent;
1222e5b6d6dSopenharmony_ci    delete rbtUnaccent;
1232e5b6d6dSopenharmony_ci
1242e5b6d6dSopenharmony_ci    printf("Exiting successfully\n");
1252e5b6d6dSopenharmony_ci    return 0;
1262e5b6d6dSopenharmony_ci}
127