summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu/icu-xetex/samples/translit/unaccent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/icu/icu-xetex/samples/translit/unaccent.cpp')
-rw-r--r--Build/source/libs/icu/icu-xetex/samples/translit/unaccent.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/Build/source/libs/icu/icu-xetex/samples/translit/unaccent.cpp b/Build/source/libs/icu/icu-xetex/samples/translit/unaccent.cpp
new file mode 100644
index 00000000000..d3af7f35df7
--- /dev/null
+++ b/Build/source/libs/icu/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++;
+ }
+}