private void AddEntry(bool alt, ushort [] v) { if (keyCount == keyValues.Length) { SortKeyValue [] tmp = new SortKeyValue [keyCount * 2]; Array.Copy(keyValues, tmp, keyCount); keyValues = tmp; } keyValues [keyCount] = new SortKeyValue(alt, v [0], (byte)v [1], (byte)v [2], v [3]); keyCount++; }
private void Serialize() { Console.WriteLine("static readonly int [] collElem = new int [] {"); DumpArray(collElem, CollationElementTableUtil.Indexer.TotalCount, true); Console.WriteLine("};"); Console.WriteLine("static readonly SortKeyValue [] keyValues = new SortKeyValue [] {"); for (int i = 0; i < keyCount; i++) { SortKeyValue s = keyValues [i]; Console.WriteLine(" new SortKeyValue ({0}, 0x{1:X04}, 0x{2:X04}, 0x{3:X04}, 0x{4:X04}),", s.Alt ? "true" : "false", s.Primary, s.Secondary, s.Thirtiary, s.Quarternary); } Console.WriteLine("};"); }
private void AddEntry (bool alt, ushort [] v) { if (keyCount == keyValues.Length) { SortKeyValue [] tmp = new SortKeyValue [keyCount * 2]; Array.Copy (keyValues, tmp, keyCount); keyValues = tmp; } keyValues [keyCount] = new SortKeyValue (alt, v [0], (byte) v [1], (byte) v [2], v [3]); keyCount++; }
private void Parse() { ushort [] v = new ushort [4]; TextReader reader = Console.In; while (reader.Peek() != -1) { string line = reader.ReadLine(); lineCount++; if (line.StartsWith("@")) { continue; // @version, @variable etc. } int idx = line.IndexOf('#'); if (idx >= 0) { line = line.Substring(0, idx); } if (line.Length == 0) { continue; } int cp = int.Parse(line.Substring(0, 5), NumberStyles.HexNumber); int collElemIdx = CollationElementTableUtil.Indexer.ToIndex(cp); if (collElemIdx < 0) { Console.Error.WriteLine("WARNING: handle character {0:x} in collation element table.", cp); continue; } line = line.Substring(line.IndexOf(';') + 1).Trim(); // count entries in a line int entryPerLine = 0; for (int e = 0; (e = line.IndexOf('[', e) + 1) > 0;) { entryPerLine++; } int start = 0; for (int e = 0; e < entryPerLine; e++) { start = line.IndexOf('[', start) + 1; string s = line.Substring(start, line.IndexOf(']', start) - start); bool alt = false; if (s [0] == '*') { alt = true; } string [] vslist = s.Substring(1).Split('.'); bool skip = false; for (int i = 0; i < 4; i++) { if (vslist [i].Length > 4) { skip = true; } else { v [i] = ushort.Parse(vslist [i], NumberStyles.HexNumber); } } if (skip) { // Console.Error.WriteLine ("WARNING: skipped entry {0:X}", cp); continue; } idx = keyCount; if (entryPerLine == 1) { // idx = 0 means "no matching entry", so here we start from 1 for (idx = 1; idx < keyCount; idx++) { SortKeyValue k = keyValues [idx]; if (k.Alt == alt && k.Primary == v [0] && k.Secondary == v [1] && k.Thirtiary == v [2] && k.Quarternary == v [3]) { break; } } } if (idx == keyCount) { AddEntry(alt, v); } } if (entryPerLine == 1) { collElem [collElemIdx] = idx; } else { collElem [collElemIdx] = (short)(keyCount - entryPerLine) + (short)(entryPerLine << 16); } } reader.Close(); }