/// <summary> /// Temporary test, just to see how the stuff works. /// </summary> /// static public void Main(String[] args) { String[] testCases = { "fiss", "h\u03a3" }; CaseIterator ci = new CaseIterator(); for (int i = 0; i < testCases.Length; ++i) { String item = testCases[i]; System.Console.Out.WriteLine(); System.Console.Out.WriteLine("Testing: " + toName.Transliterate(item)); System.Console.Out.WriteLine(); ci.Reset(item); int count_0 = 0; for (String temp = ci.Next(); temp != null; temp = ci.Next()) { System.Console.Out.WriteLine(toName.Transliterate(temp)); count_0++; } System.Console.Out.WriteLine("Total: " + count_0); } // generate a list of all caseless characters -- characters whose // case closure is themselves. UnicodeSet caseless = new UnicodeSet(); for (int i_1 = 0; i_1 <= 0x10FFFF; ++i_1) { String cp = IBM.ICU.Text.UTF16.ValueOf(i_1); ci.Reset(cp); int count_2 = 0; String fold = null; for (String temp_3 = ci.Next(); temp_3 != null; temp_3 = ci.Next()) { fold = temp_3; if (++count_2 > 1) { break; } } if (count_2 == 1 && fold.Equals(cp)) { caseless.Add(i_1); } } System.Console.Out.WriteLine("caseless = " + caseless.ToPattern(true)); UnicodeSet not_lc = new UnicodeSet("[:^lc:]"); UnicodeSet a = new UnicodeSet(); a.Set(not_lc); a.RemoveAll(caseless); System.Console.Out.WriteLine("[:^lc:] - caseless = " + a.ToPattern(true)); a.Set(caseless); a.RemoveAll(not_lc); System.Console.Out.WriteLine("caseless - [:^lc:] = " + a.ToPattern(true)); }
static CaseIterator() { if (!GENERATE) { for (int i = 0; i < exceptionList.Length; ++i) { String[] exception = exceptionList[i]; ILOG.J2CsMapping.Collections.ISet s = new HashedSet(); for (int j = 0; j < exception.Length; ++j) { ILOG.J2CsMapping.Collections.Generics.Collections.Add(s, exception[j]); } ILOG.J2CsMapping.Collections.Collections.Put(fromCaseFold, exception[0], s); } } bool defaultmapping = true; for (int i = 0; i <= 0x10FFFF; ++i) { int cat = IBM.ICU.Lang.UCharacter.GetType(i); if (cat == ILOG.J2CsMapping.Util.Character.UNASSIGNED || cat == ILOG.J2CsMapping.Util.Character.PRIVATE_USE) { continue; } String cp = IBM.ICU.Text.UTF16.ValueOf(i); String mapped = IBM.ICU.Lang.UCharacter.FoldCase(cp, defaultmapping); if (mapped.Equals(cp)) { continue; } if (maxLength < mapped.Length) { maxLength = mapped.Length; } ILOG.J2CsMapping.Collections.ISet s = (ISet)ILOG.J2CsMapping.Collections.Collections.Get(fromCaseFold, mapped); if (s == null) { s = new HashedSet(); ILOG.J2CsMapping.Collections.Generics.Collections.Add(s, mapped); ILOG.J2CsMapping.Collections.Collections.Put(fromCaseFold, mapped, s); } ILOG.J2CsMapping.Collections.Generics.Collections.Add(s, cp); ILOG.J2CsMapping.Collections.Collections.Put(toCaseFold, cp, mapped); ILOG.J2CsMapping.Collections.Collections.Put(toCaseFold, mapped, mapped); } if (DUMP) { System.Console.Out.WriteLine("maxLength = " + maxLength); System.Console.Out.WriteLine("\nfromCaseFold:"); IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(new ILOG.J2CsMapping.Collections.ListSet(fromCaseFold.Keys).GetEnumerator()); while (it.HasNext()) { Object key = it.Next(); System.Console.Out.Write(" " + toHex2.Transliterate((String)key) + ": "); ILOG.J2CsMapping.Collections.ISet s = (ISet)ILOG.J2CsMapping.Collections.Collections.Get(fromCaseFold, key); IIterator it2 = new ILOG.J2CsMapping.Collections.IteratorAdapter(s.GetEnumerator()); bool first = true; while (it2.HasNext()) { if (first) { first = false; } else { System.Console.Out.Write(", "); } System.Console.Out.Write(toHex2 .Transliterate((String)it2.Next())); } System.Console.Out.WriteLine(""); } System.Console.Out.WriteLine("\ntoCaseFold:"); it = new ILOG.J2CsMapping.Collections.IteratorAdapter(new ILOG.J2CsMapping.Collections.ListSet(toCaseFold.Keys).GetEnumerator()); while (it.HasNext()) { String key = (String)it.Next(); String value_ren = (String)ILOG.J2CsMapping.Collections.Collections.Get(toCaseFold, key); System.Console.Out.WriteLine(" " + toHex2.Transliterate(key) + ": " + toHex2.Transliterate(value_ren)); } } IDictionary fromCaseFold2 = new Hashtable(); IIterator it3 = new ILOG.J2CsMapping.Collections.IteratorAdapter(new ILOG.J2CsMapping.Collections.ListSet(fromCaseFold.Keys).GetEnumerator()); while (it3.HasNext()) { Object key = it3.Next(); ILOG.J2CsMapping.Collections.ISet s = (ISet)ILOG.J2CsMapping.Collections.Collections.Get(fromCaseFold, key); String[] temp = new String[s.Count]; ILOG.J2CsMapping.Collections.Generics.Collections.ToArray(s, temp); ILOG.J2CsMapping.Collections.Collections.Put(fromCaseFold2, key, temp); } fromCaseFold = fromCaseFold2; if (GENERATE) { ILOG.J2CsMapping.Collections.ISet multichars = new SortedSet(); it3 = new ILOG.J2CsMapping.Collections.IteratorAdapter(new ILOG.J2CsMapping.Collections.ListSet(fromCaseFold.Keys).GetEnumerator()); while (it3.HasNext()) { String key = (String)it3.Next(); if (IBM.ICU.Text.UTF16.CountCodePoint(key) < 2) { continue; } ILOG.J2CsMapping.Collections.Generics.Collections.Add(multichars, key); } CaseIterator ci = new CaseIterator(); it3 = new ILOG.J2CsMapping.Collections.IteratorAdapter(multichars.GetEnumerator()); while (it3.HasNext()) { String key = (String)it3.Next(); ILOG.J2CsMapping.Collections.ISet partialClosure = new SortedSet(); ILOG.J2CsMapping.Collections.Generics.Collections.Add(partialClosure, key); if (IBM.ICU.Text.UTF16.CountCodePoint(key) > 2) { IIterator multiIt2 = new ILOG.J2CsMapping.Collections.IteratorAdapter(multichars.GetEnumerator()); while (multiIt2.HasNext()) { String otherKey = (String)multiIt2.Next(); if (otherKey.Length >= key.Length) { continue; } int pos = -1; while (true) { pos = ILOG.J2CsMapping.Util.StringUtil.IndexOf(key, otherKey, pos + 1); if (pos < 0) { break; } int endPos = pos + otherKey.Length; String[] choices = (String[])ILOG.J2CsMapping.Collections.Collections.Get(fromCaseFold, otherKey); for (int ii = 0; ii < choices.Length; ++ii) { String patchwork = key.Substring(0, (pos) - (0)) + choices[ii] + key.Substring(endPos); ILOG.J2CsMapping.Collections.Generics.Collections.Add(partialClosure, patchwork); } } } } ILOG.J2CsMapping.Collections.ISet closure = new SortedSet(); IIterator partialIt = new ILOG.J2CsMapping.Collections.IteratorAdapter(partialClosure.GetEnumerator()); while (partialIt.HasNext()) { String key2 = (String)partialIt.Next(); ci.Reset(key2); for (String temp = ci.Next(); temp != null; temp = ci .Next()) { ILOG.J2CsMapping.Collections.Generics.Collections.Add(closure, temp); } } IIterator it2 = new ILOG.J2CsMapping.Collections.IteratorAdapter(closure.GetEnumerator()); System.Console.Out.WriteLine("\t// " + toName.Transliterate(key)); System.Console.Out.Write("\t{\"" + toHex.Transliterate(key) + "\","); while (it2.HasNext()) { String item = (String)it2.Next(); System.Console.Out.Write("\"" + toHex.Transliterate(item) + "\","); } System.Console.Out.WriteLine("},"); } } }