////CLOVER:ON ////CLOVER:OFF private void DumpCharCategories(TextWriter output) { int n = fHeader.fCatCount; string[] catStrings = new string[n + 1]; int rangeStart = 0; int rangeEnd = 0; int lastCat = -1; int char32; int category; int[] lastNewline = new int[n + 1]; for (category = 0; category <= fHeader.fCatCount; category++) { catStrings[category] = ""; } output.WriteLine("\nCharacter Categories"); output.WriteLine("--------------------"); for (char32 = 0; char32 <= 0x10ffff; char32++) { category = fTrie.Get(char32); category &= ~0x4000; // Mask off dictionary bit. if (category < 0 || category > fHeader.fCatCount) { output.WriteLine("Error, bad category " + (category).ToHexString() + " for char " + (char32).ToHexString()); break; } if (category == lastCat) { rangeEnd = char32; } else { if (lastCat >= 0) { if (catStrings[lastCat].Length > lastNewline[lastCat] + 70) { lastNewline[lastCat] = catStrings[lastCat].Length + 10; catStrings[lastCat] += "\n "; } catStrings[lastCat] += " " + (rangeStart).ToHexString(); if (rangeEnd != rangeStart) { catStrings[lastCat] += "-" + (rangeEnd).ToHexString(); } } lastCat = category; rangeStart = rangeEnd = char32; } } catStrings[lastCat] += " " + (rangeStart).ToHexString(); if (rangeEnd != rangeStart) { catStrings[lastCat] += "-" + (rangeEnd).ToHexString(); } for (category = 0; category <= fHeader.fCatCount; category++) { output.WriteLine(Int32ToString(category, 5) + " " + catStrings[category]); } output.WriteLine(); }
// // Check the expected values from a single Trie2. // private void trieGettersTest(String testName, Trie2 trie, // The Trie2 to test. int[][] checkRanges) // Expected data. // Tuples of (value, high limit code point) // High limit is first code point following the range // with the indicated value. // (Structures copied from ICU4C tests.) { int countCheckRanges = checkRanges.Length; int initialValue, errorValue; int value, value2; int start, limit; int i, countSpecials; countSpecials = 0; /*getSpecialValues(checkRanges, countCheckRanges, &initialValue, &errorValue);*/ errorValue = 0x0bad; initialValue = 0; if (checkRanges[countSpecials][0] == 0) { initialValue = checkRanges[countSpecials][1]; countSpecials++; } start = 0; for (i = countSpecials; i < countCheckRanges; ++i) { limit = checkRanges[i][0]; value = checkRanges[i][1]; while (start < limit) { value2 = trie.Get(start); if (value != value2) { // The redundant if, outside of the assert, is for speed. // It makes a significant difference for this test. assertEquals("wrong value for " + testName + " of " + (start).ToHexString(), value, value2); } ++start; } } if (!testName.StartsWith("dummy", StringComparison.Ordinal) && !testName.StartsWith("trie1", StringComparison.Ordinal)) { /* Test values for lead surrogate code units. * For non-lead-surrogate code units, getFromU16SingleLead() and get() * should be the same. */ for (start = 0xd7ff; start < 0xdc01; ++start) { switch (start) { case 0xd7ff: case 0xdc00: value = trie.Get(start); break; case 0xd800: value = 90; break; case 0xd999: value = 94; break; case 0xdbff: value = 99; break; default: value = initialValue; break; } value2 = trie.GetFromU16SingleLead((char)start); if (value2 != value) { Errln(where () + " testName: " + testName + " getFromU16SingleLead() failed." + "char, exected, actual = " + (start).ToHexString() + ", " + (value).ToHexString() + ", " + (value2).ToHexString()); } } } /* test errorValue */ value = trie.Get(-1); value2 = trie.Get(0x110000); if (value != errorValue || value2 != errorValue) { Errln("trie2.Get() error value test. Expected, actual1, actual2 = " + errorValue + ", " + value + ", " + value2); } // Check that Trie enumeration produces the same contents as simple get() foreach (Trie2Range range in trie) { for (int cp = range.StartCodePoint; cp <= range.EndCodePoint; cp++) { if (range.IsLeadSurrogate) { assertTrue(testName, cp >= (char)0xd800 && cp < (char)0xdc00); assertEquals(testName, range.Value, trie.GetFromU16SingleLead((char)cp)); } else { assertEquals(testName, range.Value, trie.Get(cp)); } } } }