コード例 #1
0
ファイル: TrieTest.cs プロジェクト: SilentCC/ICU4N
        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));
                }
            }
        }
コード例 #2
0
        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");
                }
            }
        }
コード例 #3
0
        // /CLOVER:ON

        // /CLOVER:OFF
        private void DumpCharCategories()
        {
            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] = "";
            }
            System.Console.Out.WriteLine("\nCharacter Categories");
            System.Console.Out.WriteLine("--------------------");
            for (char32 = 0; char32 <= 0x10ffff; char32++)
            {
                category  = fTrie.GetCodePointValue(char32);
                category &= ~0x4000;     // Mask off dictionary bit.
                if (category < 0 || category > fHeader.fCatCount)
                {
                    System.Console.Out.WriteLine("Error, bad category "
                                                 + ILOG.J2CsMapping.Util.IlNumber.ToString(category, 16) + " for char "
                                                 + ILOG.J2CsMapping.Util.IlNumber.ToString(char32, 16));
                    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] += " "
                                               + ILOG.J2CsMapping.Util.IlNumber.ToString(rangeStart, 16);
                        if (rangeEnd != rangeStart)
                        {
                            catStrings[lastCat] += "-"
                                                   + ILOG.J2CsMapping.Util.IlNumber.ToString(rangeEnd, 16);
                        }
                    }
                    lastCat    = category;
                    rangeStart = rangeEnd = char32;
                }
            }
            catStrings[lastCat] += " " + ILOG.J2CsMapping.Util.IlNumber.ToString(rangeStart, 16);
            if (rangeEnd != rangeStart)
            {
                catStrings[lastCat] += "-" + ILOG.J2CsMapping.Util.IlNumber.ToString(rangeEnd, 16);
            }

            for (category = 0; category <= fHeader.fCatCount; category++)
            {
                System.Console.Out.WriteLine(IntToString(category, 5) + "  "
                                             + catStrings[category]);
            }
            System.Console.Out.WriteLine();
        }
コード例 #4
0
ファイル: StringPrep.cs プロジェクト: SilentCC/ICU4N
 private char GetCodePointValue(int ch)
 {
     return(sprepTrie.GetCodePointValue(ch));
 }