2 *******************************************************************************
\r
3 * Copyright (C) 1996-2007, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 // copied from the Transliterator demo
\r
10 package com.ibm.icu.dev.test.util;
\r
12 import com.ibm.icu.lang.UCharacter;
\r
13 import com.ibm.icu.text.UTF16;
\r
14 import com.ibm.icu.text.Transliterator;
\r
15 import com.ibm.icu.text.UnicodeSet;
\r
18 * Incrementally returns the set of all strings that case-fold to the same value.
\r
20 public class CaseIterator {
\r
23 private static Transliterator toName = Transliterator.getInstance("[:^ascii:] Any-Name");
\r
24 private static Transliterator toHex = Transliterator.getInstance("[:^ascii:] Any-Hex");
\r
25 private static Transliterator toHex2 = Transliterator.getInstance("[[^\u0021-\u007F]-[,]] Any-Hex");
\r
27 // global tables (could be precompiled)
\r
28 private static Map fromCaseFold = new HashMap();
\r
29 private static Map toCaseFold = new HashMap();
\r
30 private static int maxLength = 0;
\r
32 // This exception list is generated on the console by turning on the GENERATED flag,
\r
33 // which MUST be false for normal operation.
\r
34 // Once the list is generated, it is pasted in here.
\r
35 // A bit of a cludge, but this bootstrapping is the easiest way
\r
36 // to get around certain complications in the data.
\r
38 private static final boolean GENERATE = false;
\r
40 private static final boolean DUMP = false;
\r
42 private static String[][] exceptionList = {
\r
43 // a\N{MODIFIER LETTER RIGHT HALF RING}
\r
44 {"a\u02BE","A\u02BE","a\u02BE",},
\r
46 {"ff","FF","Ff","fF","ff",},
\r
48 {"ffi","FFI","FFi","FfI","Ffi","F\uFB01","fFI","fFi","ffI","ffi","f\uFB01","\uFB00I","\uFB00i",},
\r
50 {"ffl","FFL","FFl","FfL","Ffl","F\uFB02","fFL","fFl","ffL","ffl","f\uFB02","\uFB00L","\uFB00l",},
\r
52 {"fi","FI","Fi","fI","fi",},
\r
54 {"fl","FL","Fl","fL","fl",},
\r
55 // h\N{COMBINING MACRON BELOW}
\r
56 {"h\u0331","H\u0331","h\u0331",},
\r
57 // i\N{COMBINING DOT ABOVE}
\r
58 {"i\u0307","I\u0307","i\u0307",},
\r
59 // j\N{COMBINING CARON}
\r
60 {"j\u030C","J\u030C","j\u030C",},
\r
62 {"ss","SS","Ss","S\u017F","sS","ss","s\u017F","\u017FS","\u017Fs","\u017F\u017F",},
\r
64 {"st","ST","St","sT","st","\u017FT","\u017Ft",},
\r
65 // t\N{COMBINING DIAERESIS}
\r
66 {"t\u0308","T\u0308","t\u0308",},
\r
67 // w\N{COMBINING RING ABOVE}
\r
68 {"w\u030A","W\u030A","w\u030A",},
\r
69 // y\N{COMBINING RING ABOVE}
\r
70 {"y\u030A","Y\u030A","y\u030A",},
\r
71 // \N{MODIFIER LETTER APOSTROPHE}n
\r
72 {"\u02BCn","\u02BCN","\u02BCn",},
\r
73 // \N{GREEK SMALL LETTER ALPHA WITH TONOS}\N{GREEK SMALL LETTER IOTA}
\r
74 {"\u03AC\u03B9","\u0386\u0345","\u0386\u0399","\u0386\u03B9","\u0386\u1FBE","\u03AC\u0345","\u03AC\u0399","\u03AC\u03B9","\u03AC\u1FBE",},
\r
75 // \N{GREEK SMALL LETTER ETA WITH TONOS}\N{GREEK SMALL LETTER IOTA}
\r
76 {"\u03AE\u03B9","\u0389\u0345","\u0389\u0399","\u0389\u03B9","\u0389\u1FBE","\u03AE\u0345","\u03AE\u0399","\u03AE\u03B9","\u03AE\u1FBE",},
\r
77 // \N{GREEK SMALL LETTER ALPHA}\N{COMBINING GREEK PERISPOMENI}
\r
78 {"\u03B1\u0342","\u0391\u0342","\u03B1\u0342",},
\r
79 // \N{GREEK SMALL LETTER ALPHA}\N{COMBINING GREEK PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
80 {"\u03B1\u0342\u03B9","\u0391\u0342\u0345","\u0391\u0342\u0399","\u0391\u0342\u03B9","\u0391\u0342\u1FBE",
\r
81 "\u03B1\u0342\u0345","\u03B1\u0342\u0399","\u03B1\u0342\u03B9","\u03B1\u0342\u1FBE","\u1FB6\u0345",
\r
82 "\u1FB6\u0399","\u1FB6\u03B9","\u1FB6\u1FBE",},
\r
83 // \N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTER IOTA}
\r
84 {"\u03B1\u03B9","\u0391\u0345","\u0391\u0399","\u0391\u03B9","\u0391\u1FBE","\u03B1\u0345","\u03B1\u0399","\u03B1\u03B9","\u03B1\u1FBE",},
\r
85 // \N{GREEK SMALL LETTER ETA}\N{COMBINING GREEK PERISPOMENI}
\r
86 {"\u03B7\u0342","\u0397\u0342","\u03B7\u0342",},
\r
87 // \N{GREEK SMALL LETTER ETA}\N{COMBINING GREEK PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
88 {"\u03B7\u0342\u03B9","\u0397\u0342\u0345","\u0397\u0342\u0399","\u0397\u0342\u03B9","\u0397\u0342\u1FBE",
\r
89 "\u03B7\u0342\u0345","\u03B7\u0342\u0399","\u03B7\u0342\u03B9","\u03B7\u0342\u1FBE","\u1FC6\u0345","\u1FC6\u0399",
\r
90 "\u1FC6\u03B9","\u1FC6\u1FBE",},
\r
91 // \N{GREEK SMALL LETTER ETA}\N{GREEK SMALL LETTER IOTA}
\r
92 {"\u03B7\u03B9","\u0397\u0345","\u0397\u0399","\u0397\u03B9","\u0397\u1FBE","\u03B7\u0345","\u03B7\u0399","\u03B7\u03B9","\u03B7\u1FBE",},
\r
93 // \N{GREEK SMALL LETTER IOTA}\N{COMBINING DIAERESIS}\N{COMBINING GRAVE ACCENT}
\r
94 {"\u03B9\u0308\u0300","\u0345\u0308\u0300","\u0399\u0308\u0300","\u03B9\u0308\u0300","\u1FBE\u0308\u0300",},
\r
95 // \N{GREEK SMALL LETTER IOTA}\N{COMBINING DIAERESIS}\N{COMBINING ACUTE ACCENT}
\r
96 {"\u03B9\u0308\u0301","\u0345\u0308\u0301","\u0399\u0308\u0301","\u03B9\u0308\u0301","\u1FBE\u0308\u0301",},
\r
97 // \N{GREEK SMALL LETTER IOTA}\N{COMBINING DIAERESIS}\N{COMBINING GREEK PERISPOMENI}
\r
98 {"\u03B9\u0308\u0342","\u0345\u0308\u0342","\u0399\u0308\u0342","\u03B9\u0308\u0342","\u1FBE\u0308\u0342",},
\r
99 // \N{GREEK SMALL LETTER IOTA}\N{COMBINING GREEK PERISPOMENI}
\r
100 {"\u03B9\u0342","\u0345\u0342","\u0399\u0342","\u03B9\u0342","\u1FBE\u0342",},
\r
101 // \N{GREEK SMALL LETTER RHO}\N{COMBINING COMMA ABOVE}
\r
102 {"\u03C1\u0313","\u03A1\u0313","\u03C1\u0313","\u03F1\u0313",},
\r
103 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING DIAERESIS}\N{COMBINING GRAVE ACCENT}
\r
104 {"\u03C5\u0308\u0300","\u03A5\u0308\u0300","\u03C5\u0308\u0300",},
\r
105 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING DIAERESIS}\N{COMBINING ACUTE ACCENT}
\r
106 {"\u03C5\u0308\u0301","\u03A5\u0308\u0301","\u03C5\u0308\u0301",},
\r
107 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING DIAERESIS}\N{COMBINING GREEK PERISPOMENI}
\r
108 {"\u03C5\u0308\u0342","\u03A5\u0308\u0342","\u03C5\u0308\u0342",},
\r
109 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING COMMA ABOVE}
\r
110 {"\u03C5\u0313","\u03A5\u0313","\u03C5\u0313",},
\r
111 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING COMMA ABOVE}\N{COMBINING GRAVE ACCENT}
\r
112 {"\u03C5\u0313\u0300","\u03A5\u0313\u0300","\u03C5\u0313\u0300","\u1F50\u0300",},
\r
113 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING COMMA ABOVE}\N{COMBINING ACUTE ACCENT}
\r
114 {"\u03C5\u0313\u0301","\u03A5\u0313\u0301","\u03C5\u0313\u0301","\u1F50\u0301",},
\r
115 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING COMMA ABOVE}\N{COMBINING GREEK PERISPOMENI}
\r
116 {"\u03C5\u0313\u0342","\u03A5\u0313\u0342","\u03C5\u0313\u0342","\u1F50\u0342",},
\r
117 // \N{GREEK SMALL LETTER UPSILON}\N{COMBINING GREEK PERISPOMENI}
\r
118 {"\u03C5\u0342","\u03A5\u0342","\u03C5\u0342",},
\r
119 // \N{GREEK SMALL LETTER OMEGA}\N{COMBINING GREEK PERISPOMENI}
\r
120 {"\u03C9\u0342","\u03A9\u0342","\u03C9\u0342","\u2126\u0342",},
\r
121 // \N{GREEK SMALL LETTER OMEGA}\N{COMBINING GREEK PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
122 {"\u03C9\u0342\u03B9","\u03A9\u0342\u0345","\u03A9\u0342\u0399","\u03A9\u0342\u03B9","\u03A9\u0342\u1FBE","\u03C9\u0342\u0345","\u03C9\u0342\u0399","\u03C9\u0342\u03B9","\u03C9\u0342\u1FBE","\u1FF6\u0345",
\r
123 "\u1FF6\u0399","\u1FF6\u03B9","\u1FF6\u1FBE","\u2126\u0342\u0345","\u2126\u0342\u0399","\u2126\u0342\u03B9","\u2126\u0342\u1FBE",},
\r
124 // \N{GREEK SMALL LETTER OMEGA}\N{GREEK SMALL LETTER IOTA}
\r
125 {"\u03C9\u03B9","\u03A9\u0345","\u03A9\u0399","\u03A9\u03B9","\u03A9\u1FBE","\u03C9\u0345","\u03C9\u0399","\u03C9\u03B9","\u03C9\u1FBE","\u2126\u0345","\u2126\u0399","\u2126\u03B9","\u2126\u1FBE",},
\r
126 // \N{GREEK SMALL LETTER OMEGA WITH TONOS}\N{GREEK SMALL LETTER IOTA}
\r
127 {"\u03CE\u03B9","\u038F\u0345","\u038F\u0399","\u038F\u03B9","\u038F\u1FBE","\u03CE\u0345","\u03CE\u0399","\u03CE\u03B9","\u03CE\u1FBE",},
\r
128 // \N{ARMENIAN SMALL LETTER ECH}\N{ARMENIAN SMALL LETTER YIWN}
\r
129 {"\u0565\u0582","\u0535\u0552","\u0535\u0582","\u0565\u0552","\u0565\u0582",},
\r
130 // \N{ARMENIAN SMALL LETTER MEN}\N{ARMENIAN SMALL LETTER ECH}
\r
131 {"\u0574\u0565","\u0544\u0535","\u0544\u0565","\u0574\u0535","\u0574\u0565",},
\r
132 // \N{ARMENIAN SMALL LETTER MEN}\N{ARMENIAN SMALL LETTER INI}
\r
133 {"\u0574\u056B","\u0544\u053B","\u0544\u056B","\u0574\u053B","\u0574\u056B",},
\r
134 // \N{ARMENIAN SMALL LETTER MEN}\N{ARMENIAN SMALL LETTER XEH}
\r
135 {"\u0574\u056D","\u0544\u053D","\u0544\u056D","\u0574\u053D","\u0574\u056D",},
\r
136 // \N{ARMENIAN SMALL LETTER MEN}\N{ARMENIAN SMALL LETTER NOW}
\r
137 {"\u0574\u0576","\u0544\u0546","\u0544\u0576","\u0574\u0546","\u0574\u0576",},
\r
138 // \N{ARMENIAN SMALL LETTER VEW}\N{ARMENIAN SMALL LETTER NOW}
\r
139 {"\u057E\u0576","\u054E\u0546","\u054E\u0576","\u057E\u0546","\u057E\u0576",},
\r
140 // \N{GREEK SMALL LETTER ALPHA WITH PSILI}\N{GREEK SMALL LETTER IOTA}
\r
141 {"\u1F00\u03B9","\u1F00\u0345","\u1F00\u0399","\u1F00\u03B9","\u1F00\u1FBE","\u1F08\u0345","\u1F08\u0399","\u1F08\u03B9","\u1F08\u1FBE",},
\r
142 // \N{GREEK SMALL LETTER ALPHA WITH DASIA}\N{GREEK SMALL LETTER IOTA}
\r
143 {"\u1F01\u03B9","\u1F01\u0345","\u1F01\u0399","\u1F01\u03B9","\u1F01\u1FBE","\u1F09\u0345","\u1F09\u0399","\u1F09\u03B9","\u1F09\u1FBE",},
\r
144 // \N{GREEK SMALL LETTER ALPHA WITH PSILI AND VARIA}\N{GREEK SMALL LETTER IOTA}
\r
145 {"\u1F02\u03B9","\u1F02\u0345","\u1F02\u0399","\u1F02\u03B9","\u1F02\u1FBE","\u1F0A\u0345","\u1F0A\u0399","\u1F0A\u03B9","\u1F0A\u1FBE",},
\r
146 // \N{GREEK SMALL LETTER ALPHA WITH DASIA AND VARIA}\N{GREEK SMALL LETTER IOTA}
\r
147 {"\u1F03\u03B9","\u1F03\u0345","\u1F03\u0399","\u1F03\u03B9","\u1F03\u1FBE","\u1F0B\u0345","\u1F0B\u0399","\u1F0B\u03B9","\u1F0B\u1FBE",},
\r
148 // \N{GREEK SMALL LETTER ALPHA WITH PSILI AND OXIA}\N{GREEK SMALL LETTER IOTA}
\r
149 {"\u1F04\u03B9","\u1F04\u0345","\u1F04\u0399","\u1F04\u03B9","\u1F04\u1FBE","\u1F0C\u0345","\u1F0C\u0399","\u1F0C\u03B9","\u1F0C\u1FBE",},
\r
150 // \N{GREEK SMALL LETTER ALPHA WITH DASIA AND OXIA}\N{GREEK SMALL LETTER IOTA}
\r
151 {"\u1F05\u03B9","\u1F05\u0345","\u1F05\u0399","\u1F05\u03B9","\u1F05\u1FBE","\u1F0D\u0345","\u1F0D\u0399","\u1F0D\u03B9","\u1F0D\u1FBE",},
\r
152 // \N{GREEK SMALL LETTER ALPHA WITH PSILI AND PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
153 {"\u1F06\u03B9","\u1F06\u0345","\u1F06\u0399","\u1F06\u03B9","\u1F06\u1FBE","\u1F0E\u0345","\u1F0E\u0399","\u1F0E\u03B9","\u1F0E\u1FBE",},
\r
154 // \N{GREEK SMALL LETTER ALPHA WITH DASIA AND PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
155 {"\u1F07\u03B9","\u1F07\u0345","\u1F07\u0399","\u1F07\u03B9","\u1F07\u1FBE","\u1F0F\u0345","\u1F0F\u0399","\u1F0F\u03B9","\u1F0F\u1FBE",},
\r
156 // \N{GREEK SMALL LETTER ETA WITH PSILI}\N{GREEK SMALL LETTER IOTA}
\r
157 {"\u1F20\u03B9","\u1F20\u0345","\u1F20\u0399","\u1F20\u03B9","\u1F20\u1FBE","\u1F28\u0345","\u1F28\u0399","\u1F28\u03B9","\u1F28\u1FBE",},
\r
158 // \N{GREEK SMALL LETTER ETA WITH DASIA}\N{GREEK SMALL LETTER IOTA}
\r
159 {"\u1F21\u03B9","\u1F21\u0345","\u1F21\u0399","\u1F21\u03B9","\u1F21\u1FBE","\u1F29\u0345","\u1F29\u0399","\u1F29\u03B9","\u1F29\u1FBE",},
\r
160 // \N{GREEK SMALL LETTER ETA WITH PSILI AND VARIA}\N{GREEK SMALL LETTER IOTA}
\r
161 {"\u1F22\u03B9","\u1F22\u0345","\u1F22\u0399","\u1F22\u03B9","\u1F22\u1FBE","\u1F2A\u0345","\u1F2A\u0399","\u1F2A\u03B9","\u1F2A\u1FBE",},
\r
162 // \N{GREEK SMALL LETTER ETA WITH DASIA AND VARIA}\N{GREEK SMALL LETTER IOTA}
\r
163 {"\u1F23\u03B9","\u1F23\u0345","\u1F23\u0399","\u1F23\u03B9","\u1F23\u1FBE","\u1F2B\u0345","\u1F2B\u0399","\u1F2B\u03B9","\u1F2B\u1FBE",},
\r
164 // \N{GREEK SMALL LETTER ETA WITH PSILI AND OXIA}\N{GREEK SMALL LETTER IOTA}
\r
165 {"\u1F24\u03B9","\u1F24\u0345","\u1F24\u0399","\u1F24\u03B9","\u1F24\u1FBE","\u1F2C\u0345","\u1F2C\u0399","\u1F2C\u03B9","\u1F2C\u1FBE",},
\r
166 // \N{GREEK SMALL LETTER ETA WITH DASIA AND OXIA}\N{GREEK SMALL LETTER IOTA}
\r
167 {"\u1F25\u03B9","\u1F25\u0345","\u1F25\u0399","\u1F25\u03B9","\u1F25\u1FBE","\u1F2D\u0345","\u1F2D\u0399","\u1F2D\u03B9","\u1F2D\u1FBE",},
\r
168 // \N{GREEK SMALL LETTER ETA WITH PSILI AND PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
169 {"\u1F26\u03B9","\u1F26\u0345","\u1F26\u0399","\u1F26\u03B9","\u1F26\u1FBE","\u1F2E\u0345","\u1F2E\u0399","\u1F2E\u03B9","\u1F2E\u1FBE",},
\r
170 // \N{GREEK SMALL LETTER ETA WITH DASIA AND PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
171 {"\u1F27\u03B9","\u1F27\u0345","\u1F27\u0399","\u1F27\u03B9","\u1F27\u1FBE","\u1F2F\u0345","\u1F2F\u0399","\u1F2F\u03B9","\u1F2F\u1FBE",},
\r
172 // \N{GREEK SMALL LETTER OMEGA WITH PSILI}\N{GREEK SMALL LETTER IOTA}
\r
173 {"\u1F60\u03B9","\u1F60\u0345","\u1F60\u0399","\u1F60\u03B9","\u1F60\u1FBE","\u1F68\u0345","\u1F68\u0399","\u1F68\u03B9","\u1F68\u1FBE",},
\r
174 // \N{GREEK SMALL LETTER OMEGA WITH DASIA}\N{GREEK SMALL LETTER IOTA}
\r
175 {"\u1F61\u03B9","\u1F61\u0345","\u1F61\u0399","\u1F61\u03B9","\u1F61\u1FBE","\u1F69\u0345","\u1F69\u0399","\u1F69\u03B9","\u1F69\u1FBE",},
\r
176 // \N{GREEK SMALL LETTER OMEGA WITH PSILI AND VARIA}\N{GREEK SMALL LETTER IOTA}
\r
177 {"\u1F62\u03B9","\u1F62\u0345","\u1F62\u0399","\u1F62\u03B9","\u1F62\u1FBE","\u1F6A\u0345","\u1F6A\u0399","\u1F6A\u03B9","\u1F6A\u1FBE",},
\r
178 // \N{GREEK SMALL LETTER OMEGA WITH DASIA AND VARIA}\N{GREEK SMALL LETTER IOTA}
\r
179 {"\u1F63\u03B9","\u1F63\u0345","\u1F63\u0399","\u1F63\u03B9","\u1F63\u1FBE","\u1F6B\u0345","\u1F6B\u0399","\u1F6B\u03B9","\u1F6B\u1FBE",},
\r
180 // \N{GREEK SMALL LETTER OMEGA WITH PSILI AND OXIA}\N{GREEK SMALL LETTER IOTA}
\r
181 {"\u1F64\u03B9","\u1F64\u0345","\u1F64\u0399","\u1F64\u03B9","\u1F64\u1FBE","\u1F6C\u0345","\u1F6C\u0399","\u1F6C\u03B9","\u1F6C\u1FBE",},
\r
182 // \N{GREEK SMALL LETTER OMEGA WITH DASIA AND OXIA}\N{GREEK SMALL LETTER IOTA}
\r
183 {"\u1F65\u03B9","\u1F65\u0345","\u1F65\u0399","\u1F65\u03B9","\u1F65\u1FBE","\u1F6D\u0345","\u1F6D\u0399","\u1F6D\u03B9","\u1F6D\u1FBE",},
\r
184 // \N{GREEK SMALL LETTER OMEGA WITH PSILI AND PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
185 {"\u1F66\u03B9","\u1F66\u0345","\u1F66\u0399","\u1F66\u03B9","\u1F66\u1FBE","\u1F6E\u0345","\u1F6E\u0399","\u1F6E\u03B9","\u1F6E\u1FBE",},
\r
186 // \N{GREEK SMALL LETTER OMEGA WITH DASIA AND PERISPOMENI}\N{GREEK SMALL LETTER IOTA}
\r
187 {"\u1F67\u03B9","\u1F67\u0345","\u1F67\u0399","\u1F67\u03B9","\u1F67\u1FBE","\u1F6F\u0345","\u1F6F\u0399","\u1F6F\u03B9","\u1F6F\u1FBE",},
\r
188 // \N{GREEK SMALL LETTER ALPHA WITH VARIA}\N{GREEK SMALL LETTER IOTA}
\r
189 {"\u1F70\u03B9","\u1F70\u0345","\u1F70\u0399","\u1F70\u03B9","\u1F70\u1FBE","\u1FBA\u0345","\u1FBA\u0399","\u1FBA\u03B9","\u1FBA\u1FBE",},
\r
190 // \N{GREEK SMALL LETTER ETA WITH VARIA}\N{GREEK SMALL LETTER IOTA}
\r
191 {"\u1F74\u03B9","\u1F74\u0345","\u1F74\u0399","\u1F74\u03B9","\u1F74\u1FBE","\u1FCA\u0345","\u1FCA\u0399","\u1FCA\u03B9","\u1FCA\u1FBE",},
\r
192 // \N{GREEK SMALL LETTER OMEGA WITH VARIA}\N{GREEK SMALL LETTER IOTA}
\r
193 {"\u1F7C\u03B9","\u1F7C\u0345","\u1F7C\u0399","\u1F7C\u03B9","\u1F7C\u1FBE","\u1FFA\u0345","\u1FFA\u0399","\u1FFA\u03B9","\u1FFA\u1FBE",},
\r
196 // this initializes the data used to generated the case-equivalents
\r
200 // Gather up the exceptions in a form we can use
\r
203 for (int i = 0; i < exceptionList.length; ++i) {
\r
204 String[] exception = exceptionList[i];
\r
205 Set s = new HashSet();
\r
206 // there has to be some method to do the following, but I can't find it in the collections
\r
207 for (int j = 0; j < exception.length; ++j) {
\r
208 s.add(exception[j]);
\r
210 fromCaseFold.put(exception[0], s);
\r
214 // walk through all the characters, and at every case fold result,
\r
215 // put a set of all the characters that map to that result
\r
217 boolean defaultmapping = true; // false for turkish
\r
218 for (int i = 0; i <= 0x10FFFF; ++i) {
\r
219 int cat = UCharacter.getType(i);
\r
220 if (cat == Character.UNASSIGNED || cat == Character.PRIVATE_USE) continue;
\r
222 String cp = UTF16.valueOf(i);
\r
223 String mapped = UCharacter.foldCase(cp, defaultmapping);
\r
224 if (mapped.equals(cp)) continue;
\r
226 if (maxLength < mapped.length()) maxLength = mapped.length();
\r
228 // at this point, have different case folding
\r
230 Set s = (Set) fromCaseFold.get(mapped);
\r
233 s.add(mapped); // add the case fold result itself
\r
234 fromCaseFold.put(mapped, s);
\r
237 toCaseFold.put(cp, mapped);
\r
238 toCaseFold.put(mapped, mapped); // add mapping to self
\r
241 // Emit the final data
\r
244 System.out.println("maxLength = " + maxLength);
\r
246 System.out.println("\nfromCaseFold:");
\r
247 Iterator it = fromCaseFold.keySet().iterator();
\r
248 while (it.hasNext()) {
\r
249 Object key = it.next();
\r
250 System.out.print(" " + toHex2.transliterate((String)key) + ": ");
\r
251 Set s = (Set) fromCaseFold.get(key);
\r
252 Iterator it2 = s.iterator();
\r
253 boolean first = true;
\r
254 while (it2.hasNext()) {
\r
258 System.out.print(", ");
\r
260 System.out.print(toHex2.transliterate((String)it2.next()));
\r
262 System.out.println("");
\r
265 System.out.println("\ntoCaseFold:");
\r
266 it = toCaseFold.keySet().iterator();
\r
267 while (it.hasNext()) {
\r
268 String key = (String) it.next();
\r
269 String value = (String) toCaseFold.get(key);
\r
270 System.out.println(" " + toHex2.transliterate(key) + ": " + toHex2.transliterate(value));
\r
274 // Now convert all those sets into linear arrays
\r
275 // We can't do this in place in Java, so make a temporary target array
\r
277 // Note: This could be transformed into a single array, with offsets into it.
\r
278 // Might be best choice in C.
\r
281 Map fromCaseFold2 = new HashMap();
\r
282 Iterator it = fromCaseFold.keySet().iterator();
\r
283 while (it.hasNext()) {
\r
284 Object key = it.next();
\r
285 Set s = (Set) fromCaseFold.get(key);
\r
286 String[] temp = new String[s.size()];
\r
288 fromCaseFold2.put(key, temp);
\r
290 fromCaseFold = fromCaseFold2;
\r
292 // We have processed everything, so the iterator will now work
\r
293 // The following is normally OFF.
\r
294 // It is here to generate (under the GENERATE flag) the static exception list.
\r
295 // It must be at the very end of initialization, so that the iterator is functional.
\r
296 // (easiest to do it that way)
\r
300 // first get small set of items that have multiple characters
\r
302 Set multichars = new TreeSet();
\r
303 it = fromCaseFold.keySet().iterator();
\r
304 while (it.hasNext()) {
\r
305 String key = (String) it.next();
\r
306 if (UTF16.countCodePoint(key) < 2) continue;
\r
307 multichars.add(key);
\r
310 // now we will go through each of them.
\r
312 CaseIterator ci = new CaseIterator();
\r
313 it = multichars.iterator();
\r
315 while (it.hasNext()) {
\r
316 String key = (String) it.next();
\r
318 // here is a nasty complication. Take 'ffi' ligature. We
\r
319 // can't just close it, since we would miss the combination
\r
320 // that includes the 'fi' => "fi" ligature
\r
321 // so first do a pass through, and add substring combinations
\r
322 // we call this a 'partial closure'
\r
324 Set partialClosure = new TreeSet();
\r
325 partialClosure.add(key);
\r
327 if (UTF16.countCodePoint(key) > 2) {
\r
328 Iterator multiIt2 = multichars.iterator();
\r
329 while (multiIt2.hasNext()) {
\r
330 String otherKey = (String) multiIt2.next();
\r
331 if (otherKey.length() >= key.length()) continue;
\r
334 // The following is not completely general
\r
335 // but works for the actual cased stuff,
\r
336 // and should work for future characters, since we won't have
\r
337 // more ligatures & other oddities.
\r
338 pos = key.indexOf(otherKey, pos+1);
\r
339 if (pos < 0) break;
\r
340 int endPos = pos + otherKey.length();
\r
341 // we know we have a proper substring,
\r
342 // so get the combinations
\r
343 String[] choices = (String[]) fromCaseFold.get(otherKey);
\r
344 for (int ii = 0; ii < choices.length; ++ii) {
\r
345 String patchwork = key.substring(0, pos)
\r
347 + key.substring(endPos);
\r
348 partialClosure.add(patchwork);
\r
354 // now, for each thing in the partial closure, get its
\r
355 // case closure and add it to the final result.
\r
357 Set closure = new TreeSet(); // this will be the real closure
\r
358 Iterator partialIt = partialClosure.iterator();
\r
359 while (partialIt.hasNext()) {
\r
360 String key2 = (String) partialIt.next();
\r
362 for (String temp = ci.next(); temp != null; temp = ci.next()) {
\r
366 /*String[] choices = (String[]) fromCaseFold.get(key2);
\r
367 for (int i = 0; i < choices.length; ++i) {
\r
368 ci.reset(choices[i]);
\r
370 while (null != (temp = ci.next())) {
\r
377 // print it out, so that it can be cut and pasted back into this document.
\r
379 Iterator it2 = closure.iterator();
\r
380 System.out.println("\t// " + toName.transliterate(key));
\r
381 System.out.print("\t{\"" + toHex.transliterate(key) + "\",");
\r
382 while (it2.hasNext()) {
\r
383 String item = (String)it2.next();
\r
384 System.out.print("\"" + toHex.transliterate(item) + "\",");
\r
386 System.out.println("},");
\r
391 // ============ PRIVATE CLASS DATA ============
\r
393 // pieces that we will put together
\r
394 // is not changed during iteration
\r
395 private int count = 0;
\r
396 private String[][] variants;
\r
398 // state information, changes during iteration
\r
399 private boolean done = false;
\r
400 private int[] counts;
\r
402 // internal buffer for efficiency
\r
403 private StringBuffer nextBuffer = new StringBuffer();
\r
405 // ========================
\r
408 * Reset to different source. Once reset, the iteration starts from the beginning.
\r
409 * @param source The string to get case variants for
\r
411 public void reset(String source) {
\r
413 // allocate arrays to store pieces
\r
414 // using length might be slightly too long, but we don't care much
\r
416 counts = new int[source.length()];
\r
417 variants = new String[source.length()][];
\r
419 // walk through the source, and break up into pieces
\r
420 // each piece becomes an array of equivalent values
\r
421 // TODO: could optimized this later to coalesce all single string pieces
\r
423 String piece = null;
\r
425 for (int i = 0; i < source.length(); i += piece.length()) {
\r
427 // find *longest* matching piece
\r
428 String caseFold = null;
\r
431 // do exactly one CP
\r
432 piece = UTF16.valueOf(source, i);
\r
433 caseFold = (String) toCaseFold.get(piece);
\r
435 int max = i + maxLength;
\r
436 if (max > source.length()) max = source.length();
\r
437 for (int j = max; j > i; --j) {
\r
438 piece = source.substring(i, j);
\r
439 caseFold = (String) toCaseFold.get(piece);
\r
440 if (caseFold != null) break;
\r
444 // if we fail, pick one code point
\r
445 if (caseFold == null) {
\r
446 piece = UTF16.valueOf(source, i);
\r
447 variants[count++] = new String[] {piece}; // single item string
\r
449 variants[count++] = (String[])fromCaseFold.get(caseFold);
\r
456 * Restart the iteration from the beginning, but with same source
\r
458 public void reset() {
\r
460 for (int i = 0; i < count; ++i) {
\r
466 * Iterates through the case variants.
\r
467 * @return next case variant. Each variant will case-fold to the same value as the source will.
\r
468 * When the iteration is done, null is returned.
\r
470 public String next() {
\r
472 if (done) return null;
\r
475 // TODO Optimize so we keep the piece before and after the current position
\r
476 // so we don't have so much concatenation
\r
478 // get the result, a concatenation
\r
480 nextBuffer.setLength(0);
\r
481 for (i = 0; i < count; ++i) {
\r
482 nextBuffer.append(variants[i][counts[i]]);
\r
485 // find the next right set of pieces to concatenate
\r
487 for (i = count-1; i >= 0; --i) {
\r
489 if (counts[i] < variants[i].length) break;
\r
493 // if we go too far, bail
\r
499 return nextBuffer.toString();
\r
504 * Temporary test, just to see how the stuff works.
\r
506 static public void main(String[] args) {
\r
507 String[] testCases = {"fiss", "h\u03a3"};
\r
508 CaseIterator ci = new CaseIterator();
\r
510 for (int i = 0; i < testCases.length; ++i) {
\r
511 String item = testCases[i];
\r
512 System.out.println();
\r
513 System.out.println("Testing: " + toName.transliterate(item));
\r
514 System.out.println();
\r
517 for (String temp = ci.next(); temp != null; temp = ci.next()) {
\r
518 System.out.println(toName.transliterate(temp));
\r
521 System.out.println("Total: " + count);
\r
524 // generate a list of all caseless characters -- characters whose
\r
525 // case closure is themselves.
\r
527 UnicodeSet caseless = new UnicodeSet();
\r
529 for (int i = 0; i <= 0x10FFFF; ++i) {
\r
530 String cp = UTF16.valueOf(i);
\r
533 String fold = null;
\r
534 for (String temp = ci.next(); temp != null; temp = ci.next()) {
\r
536 if (++count > 1) break;
\r
538 if (count==1 && fold.equals(cp)) {
\r
543 System.out.println("caseless = " + caseless.toPattern(true));
\r
545 UnicodeSet not_lc = new UnicodeSet("[:^lc:]");
\r
547 UnicodeSet a = new UnicodeSet();
\r
549 a.removeAll(caseless);
\r
550 System.out.println("[:^lc:] - caseless = " + a.toPattern(true));
\r
553 a.removeAll(not_lc);
\r
554 System.out.println("caseless - [:^lc:] = " + a.toPattern(true));
\r