summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/samples/translit
diff options
context:
space:
mode:
authorJonathan Kew <jfkthame@googlemail.com>2006-07-25 12:37:43 +0000
committerJonathan Kew <jfkthame@googlemail.com>2006-07-25 12:37:43 +0000
commit10c60368cd42904bd991453f02b684ebe02ef915 (patch)
treec6fb06ccf22a81c80af08f79df1b436120703de4 /Build/source/libs/icu-xetex/samples/translit
parent4d8b2aac6036acbb6878236c27e2fb110dad8643 (diff)
adding ICU library sources used by xetex
git-svn-id: svn://tug.org/texlive/trunk@1915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/icu-xetex/samples/translit')
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/Makefile22
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/README.TXT101
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/answers/main_1.cpp70
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/answers/main_2.cpp85
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/answers/main_3.cpp112
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/answers/main_4.cpp122
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/answers/unaccent.cpp54
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/answers/unaccent.h41
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/main.cpp124
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/translit.sln21
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/translit.vcproj165
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/unaccent.cpp56
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/unaccent.h89
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/util.cpp63
-rw-r--r--Build/source/libs/icu-xetex/samples/translit/util.h16
15 files changed, 1141 insertions, 0 deletions
diff --git a/Build/source/libs/icu-xetex/samples/translit/Makefile b/Build/source/libs/icu-xetex/samples/translit/Makefile
new file mode 100644
index 00000000000..d7d2baf97e1
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/Makefile
@@ -0,0 +1,22 @@
+# Copyright (c) 2000-2003 IBM, Inc. and others
+# sample code makefile
+
+# Usage:
+# - configure, build, install ICU (make install)
+# - make sure "icu-config" (in the ICU installed bin directory) is on
+# the path
+# - do 'make' in this directory
+
+#### definitions
+# Name of your target
+TARGET=translit
+
+# All object files (C or C++)
+OBJECTS=main.o unaccent.o util.o
+
+#### rules
+# Load in standard makefile definitions
+include ../defs.mk
+
+# the actual rules (this is a simple sample)
+include ../rules.mk
diff --git a/Build/source/libs/icu-xetex/samples/translit/README.TXT b/Build/source/libs/icu-xetex/samples/translit/README.TXT
new file mode 100644
index 00000000000..12931cd8138
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/README.TXT
@@ -0,0 +1,101 @@
+Copyright (c) 2002-2005, International Business Machines Corporation and others. All Rights Reserved.
+This is an exercise for the ICU Workshop (September 2000).
+ http://icu.sourceforge.net/docs/workshop_2000/agenda.html
+
+ Day 2: September 12th 2000
+ Pre-requisite:
+ 1. All the hardware and software requirements from Day 1.
+ 2. Attended or fully understand Day 1 material.
+ 3. Read through the ICU user's guide at
+ http://icu.sourceforge.net/userguide/.
+
+ #Transformation Support
+ 10:45am - 12:00pm
+ Alan Liu
+
+ Topics:
+ 1. What is the Unicode normalization?
+ 2. What kind of case mapping support is available in ICU?
+ 3. What is Transliteration and how do I use a Transliterator on a document?
+ 4. How do I add my own Transliterator?
+
+
+INSTRUCTIONS
+------------
+
+This exercise was developed and tested on ICU release 1.6.0, Win32,
+Microsoft Visual C++ 6.0. It should work on other ICU releases and
+other platforms as well.
+
+ MSVC:
+ Open the file "translit.sln" in Microsoft Visual C++.
+
+ Unix:
+ - Build and install ICU with a prefix, for example '--prefix=/home/srl/ICU'
+ - Set the variable ICU_PREFIX=/home/srl/ICU and use GNU make in
+ this directory.
+ - You may use 'make check' to invoke this sample.
+
+
+PROBLEMS
+--------
+
+Problem 0:
+
+ To start with, the program prints out a series of dates formatted in
+ Greek. Set up the program, build it, and run it.
+
+Problem 1: Basic Transliterator (Easy)
+
+ The Greek text shows up almost entirely as Unicode escapes. These
+ are unreadable on a US machine. Use an existing system
+ transliterator to transliterate the Greek text to Latin so it can be
+ phonetically read on a US machine. If you don't know the names of
+ the system transliterators, use Transliterator::getAvailableID() and
+ Transliterator::countAvailableIDs(), or look directly in the index
+ table icu/data/translit_index.txt.
+
+Problem 2: RuleBasedTransliterator (Medium)
+
+ Some of the text is still unreadable and shows up as Unicode escape
+ sequences. Create a RuleBasedTransliterator to change the
+ unreadable characters to close ASCII equivalents. For example, the
+ rule "\u00C0 > A;" will change an 'A' with a grave accent to a plain
+ 'A'.
+
+ To save typing, use UnicodeSets to handle ranges of characters.
+
+ See the included file "U0080.pdf" for a table of the U+00C0 to U+00FF
+ Unicode block.
+
+Problem 3: Transliterator subclassing; Normalizer (Difficult)
+
+ The rule-based approach is flexible and, in most cases, the best
+ choice for creating a new transliterator. Sometimes, however, a
+ more elegant algorithmic solution is available. Instead of typing
+ in a list of rules, you can write C++ code to accomplish the desired
+ transliteration.
+
+ Use a Normalizer to remove accents from characters. You will need
+ to convert each character to a sequence of base and combining
+ characters by applying a canonical denormalization transformation.
+ Then discard the combining characters (the accents etc.) leaving the
+ base character. Wrap this all up in a subclass of the
+ Transliterator class that overrides the pure virtual
+ handleTransliterate() method.
+
+
+ANSWERS
+-------
+
+The exercise includes answers. These are in the "answers" directory,
+and are numbered 1, 2, etc. In some cases new files that the user
+needs to create are included in the answers directory.
+
+If you get stuck and you want to move to the next step, copy the
+answers file into the main directory in order to proceed. E.g.,
+"main_1.cpp" contains the original "main.cpp" file. "main_2.cpp"
+contains the "main.cpp" file after problem 1. Etc.
+
+
+Have fun!
diff --git a/Build/source/libs/icu-xetex/samples/translit/answers/main_1.cpp b/Build/source/libs/icu-xetex/samples/translit/answers/main_1.cpp
new file mode 100644
index 00000000000..ba526eb675b
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/answers/main_1.cpp
@@ -0,0 +1,70 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/translit.h"
+#include "unicode/rbt.h"
+#include "unicode/unistr.h"
+#include "unicode/calendar.h"
+#include "unicode/datefmt.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "util.h"
+#include "unaccent.h"
+
+int main(int argc, char **argv) {
+
+ Calendar *cal;
+ DateFormat *fmt;
+ DateFormat *defFmt;
+ 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);
+
+ // 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();
+ defFmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Date: ");
+ uprintf(escape(str));
+ printf("\n");
+
+ // Format the date for Greece
+ str.remove();
+ fmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Greek formatted date: ");
+ uprintf(escape(str));
+ printf("\n\n");
+ }
+
+ // Clean up
+ delete fmt;
+ delete cal;
+
+ printf("Exiting successfully\n");
+ return 0;
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/answers/main_2.cpp b/Build/source/libs/icu-xetex/samples/translit/answers/main_2.cpp
new file mode 100644
index 00000000000..bf392d105a6
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/answers/main_2.cpp
@@ -0,0 +1,85 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/translit.h"
+#include "unicode/rbt.h"
+#include "unicode/unistr.h"
+#include "unicode/calendar.h"
+#include "unicode/datefmt.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "util.h"
+#include "unaccent.h"
+
+int main(int argc, char **argv) {
+
+ Calendar *cal;
+ DateFormat *fmt;
+ DateFormat *defFmt;
+ Transliterator *greek_latin;
+ 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);
+
+ // Create a Greek-Latin Transliterator
+ greek_latin = Transliterator::createInstance("Greek-Latin");
+ if (greek_latin == 0) {
+ printf("ERROR: Transliterator::createInstance() failed\n");
+ exit(1);
+ }
+
+ // 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();
+ defFmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Date: ");
+ uprintf(escape(str));
+ printf("\n");
+
+ // Format the date for Greece
+ str.remove();
+ fmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Greek formatted date: ");
+ uprintf(escape(str));
+ printf("\n");
+
+ // Transliterate result
+ greek_latin->transliterate(str);
+ printf("Transliterated via Greek-Latin: ");
+ uprintf(escape(str));
+ printf("\n\n");
+ }
+
+ // Clean up
+ delete fmt;
+ delete cal;
+ delete greek_latin;
+
+ printf("Exiting successfully\n");
+ return 0;
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/answers/main_3.cpp b/Build/source/libs/icu-xetex/samples/translit/answers/main_3.cpp
new file mode 100644
index 00000000000..93065a252a0
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/answers/main_3.cpp
@@ -0,0 +1,112 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/translit.h"
+#include "unicode/rbt.h"
+#include "unicode/unistr.h"
+#include "unicode/calendar.h"
+#include "unicode/datefmt.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "util.h"
+#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;"
+ );
+
+int main(int argc, char **argv) {
+
+ Calendar *cal;
+ DateFormat *fmt;
+ DateFormat *defFmt;
+ Transliterator *greek_latin;
+ Transliterator *rbtUnaccent;
+ 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);
+
+ // Create a Greek-Latin Transliterator
+ greek_latin = Transliterator::createInstance("Greek-Latin");
+ if (greek_latin == 0) {
+ printf("ERROR: Transliterator::createInstance() failed\n");
+ exit(1);
+ }
+
+ // Create a custom Transliterator
+ rbtUnaccent = new RuleBasedTransliterator("RBTUnaccent",
+ UNACCENT_RULES,
+ UTRANS_FORWARD,
+ status);
+ check(status, "RuleBasedTransliterator::ct");
+
+ // 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();
+ defFmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Date: ");
+ uprintf(escape(str));
+ printf("\n");
+
+ // Format the date for Greece
+ str.remove();
+ fmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Greek formatted date: ");
+ uprintf(escape(str));
+ 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\n");
+ }
+
+ // Clean up
+ delete fmt;
+ delete cal;
+ delete greek_latin;
+ delete rbtUnaccent;
+
+ printf("Exiting successfully\n");
+ return 0;
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/answers/main_4.cpp b/Build/source/libs/icu-xetex/samples/translit/answers/main_4.cpp
new file mode 100644
index 00000000000..5b51cb5672c
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/answers/main_4.cpp
@@ -0,0 +1,122 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/translit.h"
+#include "unicode/rbt.h"
+#include "unicode/unistr.h"
+#include "unicode/calendar.h"
+#include "unicode/datefmt.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "util.h"
+#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;"
+ );
+
+int main(int argc, char **argv) {
+
+ Calendar *cal;
+ DateFormat *fmt;
+ DateFormat *defFmt;
+ Transliterator *greek_latin;
+ Transliterator *rbtUnaccent;
+ Transliterator *unaccent;
+ 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);
+
+ // Create a Greek-Latin Transliterator
+ greek_latin = Transliterator::createInstance("Greek-Latin");
+ if (greek_latin == 0) {
+ printf("ERROR: Transliterator::createInstance() failed\n");
+ exit(1);
+ }
+
+ // Create a custom Transliterator
+ rbtUnaccent = new RuleBasedTransliterator("RBTUnaccent",
+ UNACCENT_RULES,
+ UTRANS_FORWARD,
+ status);
+ check(status, "RuleBasedTransliterator::ct");
+
+ // Create a custom Transliterator
+ unaccent = new UnaccentTransliterator();
+
+ // 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();
+ defFmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Date: ");
+ uprintf(escape(str));
+ printf("\n");
+
+ // Format the date for Greece
+ str.remove();
+ fmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Greek formatted date: ");
+ uprintf(escape(str));
+ 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));
+ printf("\n\n");
+ }
+
+ // Clean up
+ delete fmt;
+ delete cal;
+ delete greek_latin;
+ delete unaccent;
+ delete rbtUnaccent;
+
+ printf("Exiting successfully\n");
+ return 0;
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/answers/unaccent.cpp b/Build/source/libs/icu-xetex/samples/translit/answers/unaccent.cpp
new file mode 100644
index 00000000000..8b9832d79b6
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/answers/unaccent.cpp
@@ -0,0 +1,54 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unaccent.h"
+
+/**
+ * Constructor
+ */
+UnaccentTransliterator::UnaccentTransliterator() :
+ normalizer("", Normalizer::DECOMP),
+ Transliterator("Unaccent", 0) {
+}
+
+/**
+ * Destructor
+ */
+UnaccentTransliterator::~UnaccentTransliterator() {
+}
+
+/**
+ * Remove accents from a character using Normalizer.
+ */
+UChar UnaccentTransliterator::unaccent(UChar c) const {
+ UnicodeString str(c);
+ UErrorCode status = U_ZERO_ERROR;
+ UnaccentTransliterator* t = (UnaccentTransliterator*)this;
+
+ t->normalizer.setText(str, status);
+ if (U_FAILURE(status)) {
+ return c;
+ }
+ return (UChar) t->normalizer.next();
+}
+
+/**
+ * Implement Transliterator API
+ */
+void UnaccentTransliterator::handleTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental) const {
+ UnicodeString str("a");
+ while (index.start < index.limit) {
+ UChar c = text.charAt(index.start);
+ UChar d = unaccent(c);
+ if (c != d) {
+ str.setCharAt(0, d);
+ text.handleReplaceBetween(index.start, index.start+1, str);
+ }
+ index.start++;
+ }
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/answers/unaccent.h b/Build/source/libs/icu-xetex/samples/translit/answers/unaccent.h
new file mode 100644
index 00000000000..4cda092d58f
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/answers/unaccent.h
@@ -0,0 +1,41 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/translit.h"
+#include "unicode/normlzr.h"
+
+class UnaccentTransliterator : public Transliterator {
+
+ public:
+
+ /**
+ * Constructor
+ */
+ UnaccentTransliterator();
+
+ /**
+ * Destructor
+ */
+ virtual ~UnaccentTransliterator();
+
+ protected:
+
+ /**
+ * Implement Transliterator API
+ */
+ virtual void handleTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental) const;
+
+ private:
+
+ /**
+ * Unaccent a single character using normalizer.
+ */
+ UChar unaccent(UChar c) const;
+
+ Normalizer normalizer;
+};
diff --git a/Build/source/libs/icu-xetex/samples/translit/main.cpp b/Build/source/libs/icu-xetex/samples/translit/main.cpp
new file mode 100644
index 00000000000..5bf46717ff1
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/main.cpp
@@ -0,0 +1,124 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2003, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/translit.h"
+//#include "unicode/rbt.h"
+#include "unicode/unistr.h"
+#include "unicode/calendar.h"
+#include "unicode/datefmt.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "util.h"
+#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;"
+ );
+
+int main(int argc, char **argv) {
+
+ Calendar *cal;
+ DateFormat *fmt;
+ DateFormat *defFmt;
+ Transliterator *greek_latin;
+ Transliterator *rbtUnaccent;
+ Transliterator *unaccent;
+ UParseError pError;
+ 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);
+
+ // 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();
+
+ // 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();
+ defFmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Date: ");
+ uprintf(escape(str));
+ printf("\n");
+
+ // Format the date for Greece
+ str.remove();
+ fmt->format(cal->getTime(status), str, status);
+ check(status, "DateFormat::format");
+ printf("Greek formatted date: ");
+ uprintf(escape(str));
+ 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));
+ printf("\n\n");
+ }
+
+ // Clean up
+ delete fmt;
+ delete cal;
+ delete greek_latin;
+ delete unaccent;
+ delete rbtUnaccent;
+
+ printf("Exiting successfully\n");
+ return 0;
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/translit.sln b/Build/source/libs/icu-xetex/samples/translit/translit.sln
new file mode 100644
index 00000000000..b509f1d0e56
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/translit.sln
@@ -0,0 +1,21 @@
+Microsoft Visual Studio Solution File, Format Version 7.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translit", "translit.vcproj", "{D1BEC124-303A-4F44-BA70-55769B8FE96A}"
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ ConfigName.0 = Debug
+ ConfigName.1 = Release
+ EndGlobalSection
+ GlobalSection(ProjectDependencies) = postSolution
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Debug.ActiveCfg = Debug|Win32
+ {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Debug.Build.0 = Debug|Win32
+ {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Release.ActiveCfg = Release|Win32
+ {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Release.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/Build/source/libs/icu-xetex/samples/translit/translit.vcproj b/Build/source/libs/icu-xetex/samples/translit/translit.vcproj
new file mode 100644
index 00000000000..2d14ca8c85e
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/translit.vcproj
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="translit"
+ SccProjectName=""
+ SccLocalPath="">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="1"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ OptimizeForProcessor="2"
+ AdditionalIncludeDirectories="..\..\..\include"
+ PreprocessorDefinitions="WIN32,_DEBUG,_CONSOLE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug/translit.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"
+ CompileAs="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="icuucd.lib icuind.lib"
+ OutputFile=".\Debug/translit.exe"
+ LinkIncremental="2"
+ SuppressStartupBanner="TRUE"
+ AdditionalLibraryDirectories="..\..\..\lib"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile=".\Debug/translit.pdb"
+ SubSystem="1"/>
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Debug/translit.tlb"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="1"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ InlineFunctionExpansion="1"
+ OptimizeForProcessor="2"
+ AdditionalIncludeDirectories="..\..\..\include"
+ PreprocessorDefinitions="WIN32,NDEBUG,_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/translit.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ CompileAs="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="icuuc.lib icuin.lib"
+ OutputFile=".\Release/translit.exe"
+ LinkIncremental="1"
+ SuppressStartupBanner="TRUE"
+ AdditionalLibraryDirectories="..\..\..\lib"
+ ProgramDatabaseFile=".\Release/translit.pdb"
+ SubSystem="1"/>
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Release/translit.tlb"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+ <File
+ RelativePath=".\main.cpp">
+ </File>
+ <File
+ RelativePath=".\unaccent.cpp">
+ </File>
+ <File
+ RelativePath=".\util.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl">
+ <File
+ RelativePath=".\unaccent.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/Build/source/libs/icu-xetex/samples/translit/unaccent.cpp b/Build/source/libs/icu-xetex/samples/translit/unaccent.cpp
new file mode 100644
index 00000000000..d3af7f35df7
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/unaccent.cpp
@@ -0,0 +1,56 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2003, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unaccent.h"
+
+const char UnaccentTransliterator::fgClassID = 0;
+
+/**
+ * Constructor
+ */
+UnaccentTransliterator::UnaccentTransliterator() :
+ normalizer("", UNORM_NFD),
+ Transliterator("Unaccent", 0) {
+}
+
+/**
+ * Destructor
+ */
+UnaccentTransliterator::~UnaccentTransliterator() {
+}
+
+/**
+ * Remove accents from a character using Normalizer.
+ */
+UChar UnaccentTransliterator::unaccent(UChar c) const {
+ UnicodeString str(c);
+ UErrorCode status = U_ZERO_ERROR;
+ UnaccentTransliterator* t = (UnaccentTransliterator*)this;
+
+ t->normalizer.setText(str, status);
+ if (U_FAILURE(status)) {
+ return c;
+ }
+ return (UChar) t->normalizer.next();
+}
+
+/**
+ * Implement Transliterator API
+ */
+void UnaccentTransliterator::handleTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental) const {
+ UnicodeString str("a");
+ while (index.start < index.limit) {
+ UChar c = text.charAt(index.start);
+ UChar d = unaccent(c);
+ if (c != d) {
+ str.setCharAt(0, d);
+ text.handleReplaceBetween(index.start, index.start+1, str);
+ }
+ index.start++;
+ }
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/unaccent.h b/Build/source/libs/icu-xetex/samples/translit/unaccent.h
new file mode 100644
index 00000000000..10ee9d9096b
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/unaccent.h
@@ -0,0 +1,89 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2003, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/translit.h"
+#include "unicode/normlzr.h"
+
+class UnaccentTransliterator : public Transliterator {
+
+ public:
+
+ /**
+ * Constructor
+ */
+ UnaccentTransliterator();
+
+ /**
+ * Destructor
+ */
+ virtual ~UnaccentTransliterator();
+
+ protected:
+
+ /**
+ * Implement Transliterator API
+ */
+ virtual void handleTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental) const;
+
+ private:
+
+ /**
+ * Unaccent a single character using normalizer.
+ */
+ UChar unaccent(UChar c) const;
+
+ Normalizer normalizer;
+
+public:
+
+ /**
+ * Return the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static inline UClassID getStaticClassID(void) { return (UClassID)&fgClassID; };
+
+ /**
+ * Returns a unique class ID <b>polymorphically</b>. This method
+ * is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and
+ * clone() methods call this method.
+ *
+ * <p>Concrete subclasses of Transliterator that wish clients to
+ * be able to identify them should implement getDynamicClassID()
+ * and also a static method and data member:
+ *
+ * <pre>
+ * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
+ * static char fgClassID;
+ * </pre>
+ *
+ * Subclasses that do not implement this method will have a
+ * dynamic class ID of Transliterator::getStatisClassID().
+ *
+ * @return The class ID for this object. All objects of a given
+ * class have the same class ID. Objects of other classes have
+ * different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); };
+
+private:
+
+ /**
+ * Class identifier for subclasses of Transliterator that do not
+ * define their class (anonymous subclasses).
+ */
+ static const char fgClassID;
+};
diff --git a/Build/source/libs/icu-xetex/samples/translit/util.cpp b/Build/source/libs/icu-xetex/samples/translit/util.cpp
new file mode 100644
index 00000000000..25a8f0224d4
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/util.cpp
@@ -0,0 +1,63 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/unistr.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+// Verify that a UErrorCode is successful; exit(1) if not
+void check(UErrorCode& status, const char* msg) {
+ if (U_FAILURE(status)) {
+ printf("ERROR: %s (%s)\n", u_errorName(status), msg);
+ exit(1);
+ }
+ // printf("Ok: %s\n", msg);
+}
+
+// Append a hex string to the target
+static UnicodeString& appendHex(uint32_t number,
+ int8_t digits,
+ UnicodeString& target) {
+ static const UnicodeString DIGIT_STRING("0123456789ABCDEF");
+ while (digits > 0) {
+ target += DIGIT_STRING[(number >> ((--digits) * 4)) & 0xF];
+ }
+ return target;
+}
+
+// Replace nonprintable characters with unicode escapes
+UnicodeString escape(const UnicodeString &source) {
+ int32_t i;
+ UnicodeString target;
+ target += "\"";
+ for (i=0; i<source.length(); ++i) {
+ UChar ch = source[i];
+ if (ch < 0x09 || (ch > 0x0A && ch < 0x20) || ch > 0x7E) {
+ target += "\\u";
+ appendHex(ch, 4, target);
+ } else {
+ target += ch;
+ }
+ }
+ target += "\"";
+ return target;
+}
+
+// Print the given string to stdout
+void uprintf(const UnicodeString &str) {
+ char *buf = 0;
+ int32_t len = str.length();
+ // int32_t bufLen = str.extract(0, len, buf); // Preflight
+ /* Preflighting seems to be broken now, so assume 1-1 conversion,
+ plus some slop. */
+ int32_t bufLen = len + 16;
+ int32_t actualLen;
+ buf = new char[bufLen + 1];
+ actualLen = str.extract(0, len, buf/*, bufLen*/); // Default codepage conversion
+ buf[actualLen] = 0;
+ printf("%s", buf);
+ delete buf;
+}
diff --git a/Build/source/libs/icu-xetex/samples/translit/util.h b/Build/source/libs/icu-xetex/samples/translit/util.h
new file mode 100644
index 00000000000..2d9c4c724e2
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/translit/util.h
@@ -0,0 +1,16 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/unistr.h"
+
+// Verify that a UErrorCode is successful; exit(1) if not
+void check(UErrorCode& status, const char* msg);
+
+// Replace nonprintable characters with unicode escapes
+UnicodeString escape(const UnicodeString &source);
+
+// Print the given string to stdout
+void uprintf(const UnicodeString &str);