diff options
author | Jonathan Kew <jfkthame@googlemail.com> | 2008-03-04 13:26:36 +0000 |
---|---|---|
committer | Jonathan Kew <jfkthame@googlemail.com> | 2008-03-04 13:26:36 +0000 |
commit | 53790d2a0c50915d8cec71df3e89cd24d887b2fe (patch) | |
tree | 16f6b4df067eb3c2024e0a7735cb7ccea86b3aba /Build/source/libs/icu-xetex/samples/translit | |
parent | f483a5de9331a257f597282e611ecfb63f5ab118 (diff) |
update icu-xetex to 3.8.1-based code from xetex repository
git-svn-id: svn://tug.org/texlive/trunk@6842 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/icu-xetex/samples/translit')
15 files changed, 1209 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..a7c44e6008c --- /dev/null +++ b/Build/source/libs/icu-xetex/samples/translit/README.TXT @@ -0,0 +1,101 @@ +Copyright (c) 2002-2007, International Business Machines Corporation and others. All Rights Reserved. +This is an exercise for the ICU Workshop (September 2000). + http://www.icu-project.org/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://www.icu-project.org/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..1addab69a9b --- /dev/null +++ b/Build/source/libs/icu-xetex/samples/translit/translit.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translit", "translit.vcproj", "{D1BEC124-303A-4F44-BA70-55769B8FE96A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Debug|Win32.ActiveCfg = Debug|Win32 + {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Debug|Win32.Build.0 = Debug|Win32 + {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Release|Win32.ActiveCfg = Release|Win32 + {D1BEC124-303A-4F44-BA70-55769B8FE96A}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + 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..fb3904ee67a --- /dev/null +++ b/Build/source/libs/icu-xetex/samples/translit/translit.vcproj @@ -0,0 +1,235 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="translit" + ProjectGUID="{D1BEC124-303A-4F44-BA70-55769B8FE96A}" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory=".\Debug" + IntermediateDirectory=".\Debug" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + UseOfMFC="0" + ATLMinimizesCRunTimeLibraryUsage="false" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TypeLibraryName=".\Debug/translit.tlb" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="..\..\..\include" + PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_DEPRECATE" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + TreatWChar_tAsBuiltInType="true" + UsePrecompiledHeader="0" + PrecompiledHeaderFile=".\Debug/translit.pch" + AssemblerListingLocation=".\Debug/" + ObjectFile=".\Debug/" + ProgramDataBaseFileName=".\Debug/" + WarningLevel="3" + SuppressStartupBanner="true" + DebugInformationFormat="4" + CompileAs="0" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + PreprocessorDefinitions="_DEBUG" + Culture="1033" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <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="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory=".\Release" + IntermediateDirectory=".\Release" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + UseOfMFC="0" + ATLMinimizesCRunTimeLibraryUsage="false" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TypeLibraryName=".\Release/translit.tlb" + /> + <Tool + Name="VCCLCompilerTool" + InlineFunctionExpansion="1" + AdditionalIncludeDirectories="..\..\..\include" + PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_DEPRECATE" + StringPooling="true" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + TreatWChar_tAsBuiltInType="true" + UsePrecompiledHeader="0" + PrecompiledHeaderFile=".\Release/translit.pch" + AssemblerListingLocation=".\Release/" + ObjectFile=".\Release/" + ProgramDataBaseFileName=".\Release/" + WarningLevel="3" + SuppressStartupBanner="true" + CompileAs="0" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + PreprocessorDefinitions="NDEBUG" + Culture="1033" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <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="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </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); |