| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package uk.me.parabola.util; |
| 14 |
|
| 15 |
import java.io.File; |
| 16 |
import java.io.FileWriter; |
| 17 |
import java.io.IOException; |
| 18 |
import java.io.PrintWriter; |
| 19 |
import java.util.Enumeration; |
| 20 |
|
| 21 |
import uk.me.parabola.imgfmt.Utils; |
| 22 |
|
| 23 |
import com.ibm.icu.text.Transliterator; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class TableIcuCreator { |
| 32 |
private static Transliterator trans; |
| 33 |
|
| 34 |
public static void main(String[] args) { |
| 35 |
int count = 0; |
| 36 |
Enumeration<String> targets = Transliterator.getAvailableIDs(); |
| 37 |
while (targets.hasMoreElements()) { |
| 38 |
String s = targets.nextElement(); |
| 39 |
System.out.println(s); |
| 40 |
count++; |
| 41 |
} |
| 42 |
|
| 43 |
System.out.println("number " + count); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
trans = Transliterator.getInstance("Any-Latin"); |
| 48 |
|
| 49 |
for (int row = 0; row < 256; row++) { |
| 50 |
String name = String.format("row%02x.trans", row); |
| 51 |
PrintWriter out = null; |
| 52 |
try { |
| 53 |
out = new PrintWriter(new FileWriter(name)); |
| 54 |
printRow(out, row); |
| 55 |
} catch (IOException e) { |
| 56 |
System.out.println("Could not open " + name + " for write"); |
| 57 |
} catch (UselessException e) { |
| 58 |
|
| 59 |
File f = new File(name); |
| 60 |
f.delete(); |
| 61 |
} finally { |
| 62 |
Utils.closeFile(out); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
private static void printRow(PrintWriter out, int row) throws UselessException { |
| 68 |
out.println("#"); |
| 69 |
out.println("# This is a table for transliterating characters."); |
| 70 |
out.println("# It was created using icu4j"); |
| 71 |
out.println("#"); |
| 72 |
out.println("# All resulting strings that contained characters outside the"); |
| 73 |
out.println("# range of iso 8859-1 are commented out"); |
| 74 |
out.println("#"); |
| 75 |
out.println(); |
| 76 |
|
| 77 |
int count = 0; |
| 78 |
for (int i = 0; i < 256; i++) { |
| 79 |
char c = (char) ((row << 8) + i); |
| 80 |
String single = "" + c; |
| 81 |
String result = trans.transliterate(single); |
| 82 |
|
| 83 |
if (result.length() == 1 && result.charAt(0) == c) |
| 84 |
result = "?"; |
| 85 |
else |
| 86 |
count++; |
| 87 |
|
| 88 |
boolean inRange = true; |
| 89 |
for (char rc : result.toCharArray()) { |
| 90 |
if (rc > 0xff) { |
| 91 |
|
| 92 |
inRange = false; |
| 93 |
break; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
if (!inRange) { |
| 98 |
count--; |
| 99 |
out.print("#"); |
| 100 |
} |
| 101 |
|
| 102 |
out.format("U+%02x%02x %-12.12s # Character %s", row, i, result, single); |
| 103 |
|
| 104 |
out.println(); |
| 105 |
} |
| 106 |
|
| 107 |
if (count == 0) |
| 108 |
throw new UselessException("count of 0"); |
| 109 |
} |
| 110 |
|
| 111 |
private static class UselessException extends Exception { |
| 112 |
private UselessException(String msg) { |
| 113 |
super(msg); |
| 114 |
} |
| 115 |
} |
| 116 |
} |