public void TestDummyCharTrie() { CharTrie trie; int initialValue = 0x313, leadUnitValue = 0xaffe; int value; int c; trie = new CharTrie(initialValue, leadUnitValue, new DummyGetFoldingOffset()); /* test that all code points have initialValue */ for (c = 0; c <= 0x10ffff; ++c) { value = trie.GetCodePointValue(c); if (value != initialValue) { Errln("CharTrie/dummy.getCodePointValue(c)(U+" + Hex(c) + ")=0x" + Hex(value) + " instead of 0x" + Hex(initialValue)); } } /* test that the lead surrogate code units have leadUnitValue */ for (c = 0xd800; c <= 0xdbff; ++c) { value = trie.GetLeadValue((char)c); if (value != leadUnitValue) { Errln("CharTrie/dummy.getLeadValue(c)(U+" + Hex(c) + ")=0x" + Hex(value) + " instead of 0x" + Hex(leadUnitValue)); } } }
private StringPrep(ByteBuffer bytes) { StringPrepDataReader reader = new StringPrepDataReader(bytes); // read the indexes indexes = reader.ReadIndexes(INDEX_TOP); sprepTrie = new CharTrie(bytes, null); //indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in bytes // load the rest of the data data and initialize the data members mappingData = reader.Read(indexes[INDEX_MAPPING_DATA_SIZE] / 2); // get the options doNFKC = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0); checkBiDi = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0); sprepUniVer = GetVersionInfo(reader.GetUnicodeVersion()); normCorrVer = GetVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]); VersionInfo normUniVer = UCharacter.UnicodeVersion; if (normUniVer.CompareTo(sprepUniVer) < 0 && /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */ normUniVer.CompareTo(normCorrVer) < 0 && /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */ ((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on*/ ) { throw new IOException("Normalization Correction version not supported"); } if (checkBiDi) { bdp = UBiDiProps.Instance; } }
public void TestCharValues() { CharTrie trie = null; try { trie = IBM.ICU.Impl.UCharacterProperty.GetInstance().m_trie_; } catch (Exception e) { Warnln("Error creating ucharacter trie"); return; } for (int i = 0; i < 0xFFFF; i++) { if (i < 0xFF && trie.GetBMPValue((char)i) != trie .GetLatin1LinearValue((char)i)) { Errln("For latin 1 codepoint, getBMPValue should be the same " + "as getLatin1LinearValue"); } if (trie.GetBMPValue((char)i) != trie.GetCodePointValue(i)) { Errln("For BMP codepoint, getBMPValue should be the same " + "as getCodepointValue"); } } for (int i_0 = 0x10000; i_0 < 0x10ffff; i_0++) { char lead = IBM.ICU.Text.UTF16.GetLeadSurrogate(i_0); char trail = IBM.ICU.Text.UTF16.GetTrailSurrogate(i_0); char value_ren = trie.GetCodePointValue(i_0); if (value_ren != trie.GetSurrogateValue(lead, trail) || value_ren != trie.GetTrailValue(trie.GetLeadValue(lead), trail)) { Errln("For Non-BMP codepoints, getSurrogateValue should be " + "the same s getCodepointValue and getTrailValue"); } } }
public void TestCharTrie() { CharTrie ct = new CharTrie(null); // use default char comparer ct.Add("this"); ct.Add("these"); ct.Add("those"); ct.Add("the"); ct.Add("they"); ct.Add("their"); ct.Add("there"); ct.Add("thus"); // test strings if (ct.GetMatchingLength("this") != "this".Length || ct.GetMatchingLength("these") != "these".Length || ct.GetMatchingLength("those") != "those".Length || ct.GetMatchingLength("the") != "the".Length || ct.GetMatchingLength("they") != "they".Length || ct.GetMatchingLength("their") != "their".Length || ct.GetMatchingLength("there") != "there".Length || ct.GetMatchingLength("thus") != "thus".Length) { throw new Exception(" earlier added strings are not contained in char trie "); } // test substrings if (ct.GetMatchingLength("thisaaa") != "this".Length || ct.GetMatchingLength("thesebbb") != "these".Length || ct.GetMatchingLength("thoseccc") != "those".Length || ct.GetMatchingLength("theddd") != "the".Length || ct.GetMatchingLength("theyeee") != "they".Length || ct.GetMatchingLength("theirfff") != "their".Length || ct.GetMatchingLength("thereggg") != "there".Length || ct.GetMatchingLength("thushhh") != "thus".Length) { throw new Exception(" earlier added strings are not contained in char trie "); } // test enumeration int i = 0; foreach (CharTrie.Node node in ct) { node.GetType(); ++i; } if (i != 17) { throw new Exception(" char trie enumeration returns invalid number of nodes "); } // test serialization MemoryStream stream = new MemoryStream(); ct.Save(new BinaryWriter(stream)); stream.Flush(); CharTrie ct1 = new CharTrie(null); stream.Seek(0, SeekOrigin.Begin); ct1.Load(new BinaryReader(stream)); if (ct1.GetMatchingLength("this") != "this".Length || ct1.GetMatchingLength("these") != "these".Length || ct1.GetMatchingLength("those") != "those".Length || ct1.GetMatchingLength("the") != "the".Length || ct1.GetMatchingLength("they") != "they".Length || ct1.GetMatchingLength("their") != "their".Length || ct1.GetMatchingLength("there") != "there".Length || ct1.GetMatchingLength("thus") != "thus".Length) { throw new Exception(" earlier added strings are not contained in char trie "); } if (ct1.GetMatchingLength("thisaaa") != "this".Length || ct1.GetMatchingLength("thesebbb") != "these".Length || ct1.GetMatchingLength("thoseccc") != "those".Length || ct1.GetMatchingLength("theddd") != "the".Length || ct1.GetMatchingLength("theyeee") != "they".Length || ct1.GetMatchingLength("theirfff") != "their".Length || ct1.GetMatchingLength("thereggg") != "there".Length || ct1.GetMatchingLength("thushhh") != "thus".Length) { throw new Exception(" earlier added strings are not contained in char trie "); } }