]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/util/TransliteratorUtilities.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / util / TransliteratorUtilities.java
old mode 100755 (executable)
new mode 100644 (file)
index 0a5f84b..9080161
-//##header\r
-/*\r
- *******************************************************************************\r
- * Copyright (C) 2002-2009, International Business Machines Corporation and    *\r
- * others. All Rights Reserved.                                                *\r
- *******************************************************************************\r
- */\r
-package com.ibm.icu.dev.test.util;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.IOException;\r
-\r
-import com.ibm.icu.text.Transliterator;\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//##import com.ibm.icu.dev.test.TestUtil;\r
-//#endif\r
-\r
-public class TransliteratorUtilities {\r
-    public static boolean DEBUG = false;\r
-\r
-    public static void registerTransliteratorFromFile(String dir, String id) {\r
-        try {\r
-            String filename = id.replace('-', '_') +  ".txt";\r
-            String rules = getFileContents(dir, filename);\r
-            Transliterator t;\r
-            int pos = id.indexOf('-');\r
-            String rid;\r
-            if (pos < 0) {\r
-                rid = id + "-Any";\r
-                id = "Any-" + id;\r
-            } else {\r
-                rid = id.substring(pos+1) + "-" + id.substring(0, pos);\r
-            }\r
-            t = Transliterator.createFromRules(id, rules, Transliterator.FORWARD);\r
-            Transliterator.unregister(id);\r
-            Transliterator.registerInstance(t);\r
-\r
-            /*String test = "\u049A\u0430\u0437\u0430\u049B";\r
-            System.out.println(t.transliterate(test));\r
-            t = Transliterator.getInstance(id);\r
-            System.out.println(t.transliterate(test));\r
-            */\r
-\r
-            t = Transliterator.createFromRules(rid, rules, Transliterator.REVERSE);\r
-            Transliterator.unregister(rid);\r
-            Transliterator.registerInstance(t);\r
-            if (DEBUG) System.out.println("Registered new Transliterator: " + id + ", " + rid);\r
-        } catch (IOException e) {\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//##        throw (IllegalArgumentException) new IllegalArgumentException("Can't open " + dir + ", " + id+" "+ e.getMessage());\r
-//#else\r
-            throw (IllegalArgumentException) new IllegalArgumentException("Can't open " + dir + ", " + id).initCause(e);\r
-//#endif\r
-        }\r
-    }\r
-\r
-    /**\r
-     * \r
-     */\r
-    public static String getFileContents(String dir, String filename) throws IOException {\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//##        BufferedReader br = TestUtil.openUTF8Reader(dir, filename);\r
-//#else\r
-        BufferedReader br = BagFormatter.openUTF8Reader(dir, filename);\r
-//#endif \r
-        StringBuffer buffer = new StringBuffer();\r
-        while (true) {\r
-            String line = br.readLine();\r
-            if (line == null) break;\r
-            if (line.length() > 0 && line.charAt(0) == '\uFEFF') line = line.substring(1);\r
-            buffer.append(line).append("\r\n");\r
-        }\r
-        br.close();\r
-        return buffer.toString();\r
-         \r
-    }\r
-\r
-    private static final String BASE_RULES =\r
-        ":: (hex-any/xml);" +\r
-        ":: (hex-any/xml10);" + \r
-        "'<' > '&lt;' ;" +\r
-        "'<' < '&'[lL][Tt]';' ;" +\r
-        "'&' > '&amp;' ;" +\r
-        "'&' < '&'[aA][mM][pP]';' ;" +\r
-        "'>' < '&'[gG][tT]';' ;" +\r
-        "'\"' < '&'[qQ][uU][oO][tT]';' ; " +\r
-        "'' < '&'[aA][pP][oO][sS]';' ; ";\r
-\r
-    private static final String CONTENT_RULES =\r
-        "'>' > '&gt;' ;";\r
-\r
-    private static final String HTML_RULES = BASE_RULES + CONTENT_RULES + \r
-        "'\"' > '&quot;' ; ";\r
-\r
-    private static final String HTML_RULES_CONTROLS = HTML_RULES + \r
-        ":: [[:C:][:Z:][:whitespace:][:Default_Ignorable_Code_Point:]] hex/unicode ; ";\r
-\r
-    private static final String HTML_RULES_ASCII = HTML_RULES + \r
-        ":: [[:C:][:^ASCII:]] any-hex/xml ; ";\r
-\r
-    private static final String XML_RULES = HTML_RULES +\r
-        "'' > '&apos;' ; "\r
-;\r
-    \r
-    /*\r
-The ampersand character (&) and the left angle bracket (<) MUST NOT appear \r
-\r
-in their literal form, except when used as markup delimiters, or within a \r
-\r
-comment, a processing instruction, or a CDATA section. If they are needed \r
-\r
-elsewhere, they MUST be escaped using either numeric character references or \r
-\r
-the strings "&amp;" and "&lt;" respectively. The right angle bracket (>) MAY \r
-\r
-be represented using the string "&gt;", and MUST, for compatibility, be \r
-\r
-escaped using either "&gt;" or a character reference when it appears in the string \r
-\r
-"]]>" in content, when that string is not marking the end of a CDATA section.\r
-\r
-In the content of elements, character data is any string of characters which does \r
-\r
-not contain the start-delimiter of any markup and does not include the \r
-\r
-CDATA-section-close delimiter, "]]>". In a CDATA section, character data is \r
-\r
-any string of characters not including the CDATA-section-close delimiter, \r
-\r
-"]]>".\r
-\r
-To allow attribute values to contain both single and double quotes, the \r
-\r
-apostrophe or single-quote character (') MAY be represented as "&apos;", and \r
-\r
-the double-quote character (") as "&quot;".\r
-\r
-\r
-     */\r
-    \r
-    public static final Transliterator toXML = Transliterator.createFromRules(\r
-            "any-xml", XML_RULES, Transliterator.FORWARD);\r
-    public static final Transliterator fromXML = Transliterator.createFromRules(\r
-            "xml-any", XML_RULES, Transliterator.REVERSE);\r
-    public static final Transliterator toHTML = Transliterator.createFromRules(\r
-            "any-html", HTML_RULES, Transliterator.FORWARD);\r
-    public static final Transliterator toHTMLControl = Transliterator.createFromRules(\r
-            "any-html", HTML_RULES_CONTROLS, Transliterator.FORWARD);\r
-    public static final Transliterator toHTMLAscii = Transliterator.createFromRules(\r
-            "any-html", HTML_RULES_ASCII, Transliterator.FORWARD);\r
-    public static final Transliterator fromHTML = Transliterator.createFromRules(\r
-            "html-any", HTML_RULES, Transliterator.REVERSE);\r
-}\r
+//##header J2SE15
+/*
+ *******************************************************************************
+ * Copyright (C) 2002-2009, International Business Machines Corporation and    *
+ * others. All Rights Reserved.                                                *
+ *******************************************************************************
+ */
+package com.ibm.icu.dev.test.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+
+import com.ibm.icu.text.Transliterator;
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//##import com.ibm.icu.dev.test.TestUtil;
+//#endif
+
+public class TransliteratorUtilities {
+    public static boolean DEBUG = false;
+
+    public static void registerTransliteratorFromFile(String dir, String id) {
+        try {
+            String filename = id.replace('-', '_') +  ".txt";
+            String rules = getFileContents(dir, filename);
+            Transliterator t;
+            int pos = id.indexOf('-');
+            String rid;
+            if (pos < 0) {
+                rid = id + "-Any";
+                id = "Any-" + id;
+            } else {
+                rid = id.substring(pos+1) + "-" + id.substring(0, pos);
+            }
+            t = Transliterator.createFromRules(id, rules, Transliterator.FORWARD);
+            Transliterator.unregister(id);
+            Transliterator.registerInstance(t);
+
+            /*String test = "\u049A\u0430\u0437\u0430\u049B";
+            System.out.println(t.transliterate(test));
+            t = Transliterator.getInstance(id);
+            System.out.println(t.transliterate(test));
+            */
+
+            t = Transliterator.createFromRules(rid, rules, Transliterator.REVERSE);
+            Transliterator.unregister(rid);
+            Transliterator.registerInstance(t);
+            if (DEBUG) System.out.println("Registered new Transliterator: " + id + ", " + rid);
+        } catch (IOException e) {
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//##        throw (IllegalArgumentException) new IllegalArgumentException("Can't open " + dir + ", " + id+" "+ e.getMessage());
+//#else
+            throw (IllegalArgumentException) new IllegalArgumentException("Can't open " + dir + ", " + id).initCause(e);
+//#endif
+        }
+    }
+
+    /**
+     * 
+     */
+    public static String getFileContents(String dir, String filename) throws IOException {
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//##        BufferedReader br = TestUtil.openUTF8Reader(dir, filename);
+//#else
+        BufferedReader br = BagFormatter.openUTF8Reader(dir, filename);
+//#endif 
+        StringBuffer buffer = new StringBuffer();
+        while (true) {
+            String line = br.readLine();
+            if (line == null) break;
+            if (line.length() > 0 && line.charAt(0) == '\uFEFF') line = line.substring(1);
+            buffer.append(line).append("\r\n");
+        }
+        br.close();
+        return buffer.toString();
+         
+    }
+
+    private static final String BASE_RULES =
+        ":: (hex-any/xml);" +
+        ":: (hex-any/xml10);" + 
+        "'<' > '&lt;' ;" +
+        "'<' < '&'[lL][Tt]';' ;" +
+        "'&' > '&amp;' ;" +
+        "'&' < '&'[aA][mM][pP]';' ;" +
+        "'>' < '&'[gG][tT]';' ;" +
+        "'\"' < '&'[qQ][uU][oO][tT]';' ; " +
+        "'' < '&'[aA][pP][oO][sS]';' ; ";
+
+    private static final String CONTENT_RULES =
+        "'>' > '&gt;' ;";
+
+    private static final String HTML_RULES = BASE_RULES + CONTENT_RULES + 
+        "'\"' > '&quot;' ; ";
+
+    private static final String HTML_RULES_CONTROLS = HTML_RULES + 
+        ":: [[:C:][:Z:][:whitespace:][:Default_Ignorable_Code_Point:]] hex/unicode ; ";
+
+    private static final String HTML_RULES_ASCII = HTML_RULES + 
+        ":: [[:C:][:^ASCII:]] any-hex/xml ; ";
+
+    private static final String XML_RULES = HTML_RULES +
+        "'' > '&apos;' ; "
+;
+    
+    /*
+The ampersand character (&) and the left angle bracket (<) MUST NOT appear 
+
+in their literal form, except when used as markup delimiters, or within a 
+
+comment, a processing instruction, or a CDATA section. If they are needed 
+
+elsewhere, they MUST be escaped using either numeric character references or 
+
+the strings "&amp;" and "&lt;" respectively. The right angle bracket (>) MAY 
+
+be represented using the string "&gt;", and MUST, for compatibility, be 
+
+escaped using either "&gt;" or a character reference when it appears in the string 
+
+"]]>" in content, when that string is not marking the end of a CDATA section.
+
+In the content of elements, character data is any string of characters which does 
+
+not contain the start-delimiter of any markup and does not include the 
+
+CDATA-section-close delimiter, "]]>". In a CDATA section, character data is 
+
+any string of characters not including the CDATA-section-close delimiter, 
+
+"]]>".
+
+To allow attribute values to contain both single and double quotes, the 
+
+apostrophe or single-quote character (') MAY be represented as "&apos;", and 
+
+the double-quote character (") as "&quot;".
+
+
+     */
+    
+    public static final Transliterator toXML = Transliterator.createFromRules(
+            "any-xml", XML_RULES, Transliterator.FORWARD);
+    public static final Transliterator fromXML = Transliterator.createFromRules(
+            "xml-any", XML_RULES, Transliterator.REVERSE);
+    public static final Transliterator toHTML = Transliterator.createFromRules(
+            "any-html", HTML_RULES, Transliterator.FORWARD);
+    public static final Transliterator toHTMLControl = Transliterator.createFromRules(
+            "any-html", HTML_RULES_CONTROLS, Transliterator.FORWARD);
+    public static final Transliterator toHTMLAscii = Transliterator.createFromRules(
+            "any-html", HTML_RULES_ASCII, Transliterator.FORWARD);
+    public static final Transliterator fromHTML = Transliterator.createFromRules(
+            "html-any", HTML_RULES, Transliterator.REVERSE);
+}