Esempio n. 1
0
        public void TestNext()
        {
            String text = "abc";
            CollationElementIterator iterator = coll
                                                .GetCollationElementIterator(text);

            int[] orders = new int[text.Length];
            int   order  = iterator.Next();
            int   i      = 0;

            while (order != CollationElementIterator.NULLORDER)
            {
                orders[i++] = order;
                order       = iterator.Next();
            }

            int offset = iterator.GetOffset();

            NUnit.Framework.Assert.AreEqual(text.Length, offset);
            order = iterator.Previous();

            while (order != CollationElementIterator.NULLORDER)
            {
                NUnit.Framework.Assert.AreEqual(orders[--i], order);
                order = iterator.Previous();
            }

            NUnit.Framework.Assert.AreEqual(0, iterator.GetOffset());
        }
        public void TestGetCollationElementIteratorCharacterIterator()
        {
            {
                Locale            locale = new Locale("es", "", "TRADITIONAL");
                RuleBasedCollator coll   = (RuleBasedCollator)ILOG.J2CsMapping.Text.Collator
                                           .GetInstance(locale);
                String text = "cha";
                StringCharacterIterator source = new StringCharacterIterator(
                    text);
                CollationElementIterator iterator = coll
                                                    .GetCollationElementIterator(source);
                int[] e_offset = { 0, 1, 2, 3 };
                int   offset   = iterator.GetOffset();
                int   i        = 0;
                NUnit.Framework.Assert.AreEqual(e_offset[i++], offset);
                while (offset != text.Length)
                {
                    iterator.Next();
                    offset = iterator.GetOffset();
                    // System.out.println(offset);
                    NUnit.Framework.Assert.AreEqual(e_offset[i++], offset);
                }
            }

            {
                Locale            locale_0 = new Locale("de", "DE");
                RuleBasedCollator coll_1   = (RuleBasedCollator)ILOG.J2CsMapping.Text.Collator
                                             .GetInstance(locale_0);
                String text_2 = "\u00E6b";
                StringCharacterIterator source_3 = new StringCharacterIterator(
                    text_2);
                CollationElementIterator iterator_4 = coll_1
                                                      .GetCollationElementIterator(source_3);
                int[] e_offset_5 = { 0, 1, 1, 2 };
                int   offset_6   = iterator_4.GetOffset();
                int   i_7        = 0;
                NUnit.Framework.Assert.AreEqual(e_offset_5[i_7++], offset_6);
                while (offset_6 != text_2.Length)
                {
                    iterator_4.Next();
                    offset_6 = iterator_4.GetOffset();
                    NUnit.Framework.Assert.AreEqual(e_offset_5[i_7++], offset_6);
                }
            }
            // Regression for HARMONY-1352
            try
            {
                new RuleBasedCollator("< a< b< c< d")
                .GetCollationElementIterator((CharacterIterator)null);
                NUnit.Framework.Assert.Fail("NullPointerException expected");
            }
            catch (NullReferenceException e)
            {
                // expected
            }
        }
        public void TestGetCollationElementIteratorString()
        {
            {
                Locale            locale = new Locale("es", "", "TRADITIONAL");
                RuleBasedCollator coll   = (RuleBasedCollator)ILOG.J2CsMapping.Text.Collator
                                           .GetInstance(locale);
                String source = "cha";
                CollationElementIterator iterator = coll
                                                    .GetCollationElementIterator(source);
                int[] e_offset = { 0, 1, 2, 3 };
                int   offset   = iterator.GetOffset();
                int   i        = 0;
                NUnit.Framework.Assert.AreEqual(e_offset[i++], offset);
                while (offset != source.Length)
                {
                    iterator.Next();
                    offset = iterator.GetOffset();
                    NUnit.Framework.Assert.AreEqual(e_offset[i++], offset);
                }
            }

            {
                Locale            locale_0 = new Locale("de", "DE");
                RuleBasedCollator coll_1   = (RuleBasedCollator)ILOG.J2CsMapping.Text.Collator
                                             .GetInstance(locale_0);
                String source_2 = "\u00E6b";
                CollationElementIterator iterator_3 = coll_1
                                                      .GetCollationElementIterator(source_2);
                int[] e_offset_4 = { 0, 1, 1, 2 };
                int   offset_5   = iterator_3.GetOffset();
                int   i_6        = 0;
                NUnit.Framework.Assert.AreEqual(e_offset_4[i_6++], offset_5);
                while (offset_5 != source_2.Length)
                {
                    iterator_3.Next();
                    offset_5 = iterator_3.GetOffset();
                    NUnit.Framework.Assert.AreEqual(e_offset_4[i_6++], offset_5);
                }
            }
            // Regression for HARMONY-1352
            try
            {
                new RuleBasedCollator("< a< b< c< d")
                .GetCollationElementIterator((String)null);
                NUnit.Framework.Assert.Fail("NullPointerException expected");
            }
            catch (NullReferenceException e)
            {
                // expected
            }
        }
Esempio n. 4
0
        public void TestSetTextCharacterIterator()
        {
            // Failed in java too
            RuleBasedCollator rbColl = (RuleBasedCollator)ILOG.J2CsMapping.Text.Collator
                                       .GetInstance(new Locale("es", "", "TRADITIONAL"));
            String text = "caa";
            CollationElementIterator iterator = rbColl
                                                .GetCollationElementIterator(text);

            iterator.SetOffset(1);
            NUnit.Framework.Assert.AreEqual(1, iterator.GetOffset());
            iterator.SetText(new StringCharacterIterator("cha"));
            iterator.SetOffset(1);
            NUnit.Framework.Assert.AreEqual(1, iterator.GetOffset());
        }
Esempio n. 5
0
        public void TestGetOffset()
        {
            String text = "abc";
            CollationElementIterator iterator = coll
                                                .GetCollationElementIterator(text);

            int[] offsets = { 0, 1, 2, 3 };
            int   offset  = iterator.GetOffset();
            int   i       = 0;

            NUnit.Framework.Assert.AreEqual(offsets[i++], offset);
            while (offset != text.Length)
            {
                iterator.Next();
                offset = iterator.GetOffset();
                NUnit.Framework.Assert.AreEqual(offsets[i++], offset);
            }
        }
Esempio n. 6
0
        public void TestSearchCollatorElements()
        {
            String tsceText =
                " \uAC00" +              // simple LV Hangul
                " \uAC01" +              // simple LVT Hangul
                " \uAC0F" +              // LVTT, last jamo expands for search
                " \uAFFF" +              // LLVVVTT, every jamo expands for search
                " \u1100\u1161\u11A8" +  // 0xAC01 as conjoining jamo
                " \u3131\u314F\u3131" +  // 0xAC01 as compatibility jamo
                " \u1100\u1161\u11B6" +  // 0xAC0F as conjoining jamo; last expands for search
                " \u1101\u1170\u11B6" +  // 0xAFFF as conjoining jamo; all expand for search
                " \u00E6" +              // small letter ae, expands
                " \u1E4D" +              // small letter o with tilde and acute, decomposes
                " ";

            int[] rootStandardOffsets =
            {
                0,   1,  2,
                2,   3,  4,  4,
                4,   5,  6,  6,
                6,   7,  8,  8,
                8,   9, 10, 11,
                12, 13, 14, 15,
                16, 17, 18, 19,
                20, 21, 22, 23,
                24, 25, 26,/* plus another 1-2 offset=26 if ae-ligature maps to three CEs */
                26, 27, 28, 28,
                28,
                29
            };

            int[] rootSearchOffsets =
            {
                0,   1,  2,
                2,   3,  4,  4,
                4,   5,  6,  6,  6,
                6,   7,  8,  8,  8,  8,  8,  8,
                8,   9, 10, 11,
                12, 13, 14, 15,
                16, 17, 18, 19, 20,
                20, 21, 22, 22, 23, 23, 23, 24,
                24, 25, 26,/* plus another 1-2 offset=26 if ae-ligature maps to three CEs */
                26, 27, 28, 28,
                28,
                29
            };


            TSCEItem[] tsceItems =
            {
                new TSCEItem("root",                  rootStandardOffsets),
                new TSCEItem("root@collation=search", rootSearchOffsets),
            };

            foreach (TSCEItem tsceItem in tsceItems)
            {
                String            localeString = tsceItem.LocaleString;
                ULocale           uloc         = new ULocale(localeString);
                RuleBasedCollator col          = null;
                try
                {
                    col = (RuleBasedCollator)Collator.GetInstance(uloc);
                }
                catch (Exception e)
                {
                    Errln("Error: in locale " + localeString + ", err in Collator.getInstance");
                    continue;
                }
                CollationElementIterator uce = col.GetCollationElementIterator(tsceText);
                int[] offsets = tsceItem.GetOffsets();
                int   ioff, noff = offsets.Length;
                int   offset, element;

                ioff = 0;
                do
                {
                    offset  = uce.GetOffset();
                    element = uce.Next();
                    Logln(String.Format("({0}) offset={1:d2}  ce={2:x8}\n", tsceItem.LocaleString, offset, element));
                    if (element == 0)
                    {
                        Errln("Error: in locale " + localeString + ", CEIterator next() returned element 0");
                    }
                    if (ioff < noff)
                    {
                        if (offset != offsets[ioff])
                        {
                            Errln("Error: in locale " + localeString + ", expected CEIterator next()->getOffset " + offsets[ioff] + ", got " + offset);
                            //ioff = noff;
                            //break;
                        }
                        ioff++;
                    }
                    else
                    {
                        Errln("Error: in locale " + localeString + ", CEIterator next() returned more elements than expected");
                    }
                } while (element != CollationElementIterator.NULLORDER);
                if (ioff < noff)
                {
                    Errln("Error: in locale " + localeString + ", CEIterator next() returned fewer elements than expected");
                }

                // backwards test
                uce.SetOffset(tsceText.Length);
                ioff = noff;
                do
                {
                    offset  = uce.GetOffset();
                    element = uce.Previous();
                    if (element == 0)
                    {
                        Errln("Error: in locale " + localeString + ", CEIterator previous() returned element 0");
                    }
                    if (ioff > 0)
                    {
                        ioff--;
                        if (offset != offsets[ioff])
                        {
                            Errln("Error: in locale " + localeString + ", expected CEIterator previous()->getOffset " + offsets[ioff] + ", got " + offset);
                            //ioff = 0;
                            //break;
                        }
                    }
                    else
                    {
                        Errln("Error: in locale " + localeString + ", CEIterator previous() returned more elements than expected");
                    }
                } while (element != CollationElementIterator.NULLORDER);
                if (ioff > 0)
                {
                    Errln("Error: in locale " + localeString + ", CEIterator previous() returned fewer elements than expected");
                }
            }
        }
Esempio n. 7
0
        public void TestOffset(/* char* par */)
        {
            RuleBasedCollator en_us;

            try
            {
                en_us = (RuleBasedCollator)Collator.GetInstance(new CultureInfo("en-US"));
            }
            catch (Exception e)
            {
                Warnln("ERROR: in creation of collator of ENGLISH locale");
                return;
            }

            CollationElementIterator iter = en_us.GetCollationElementIterator(test1);

            // testing boundaries
            iter.SetOffset(0);
            if (iter.Previous() != CollationElementIterator.NULLORDER)
            {
                Errln("Error: After setting offset to 0, we should be at the end "
                      + "of the backwards iteration");
            }
            iter.SetOffset(test1.Length);
            if (iter.Next() != CollationElementIterator.NULLORDER)
            {
                Errln("Error: After setting offset to the end of the string, we "
                      + "should be at the end of the forwards iteration");
            }

            // Run all the way through the iterator, then get the offset
            int[] orders = CollationTest.GetOrders(iter);
            Logln("orders.Length = " + orders.Length);

            int offset = iter.GetOffset();

            if (offset != test1.Length)
            {
                String msg1 = "offset at end != length: ";
                String msg2 = " vs ";
                Errln(msg1 + offset + msg2 + test1.Length);
            }

            // Now set the offset back to the beginning and see if it works
            CollationElementIterator pristine = en_us.GetCollationElementIterator(test1);

            try
            {
                iter.SetOffset(0);
            }
            catch (Exception e)
            {
                Errln("setOffset failed.");
            }
            assertEqual(iter, pristine);

            // setting offset in the middle of a contraction
            String            contraction = "change";
            RuleBasedCollator tailored    = null;

            try
            {
                tailored = new RuleBasedCollator("& a < ch");
            }
            catch (Exception e)
            {
                Errln("Error: in creation of Spanish collator");
                return;
            }
            iter = tailored.GetCollationElementIterator(contraction);
            int[] order = CollationTest.GetOrders(iter);
            iter.SetOffset(1); // sets offset in the middle of ch
            int[] order2 = CollationTest.GetOrders(iter);
            if (!Arrays.Equals(order, order2))
            {
                Errln("Error: setting offset in the middle of a contraction should be the same as setting it to the start of the contraction");
            }
            contraction = "peache";
            iter        = tailored.GetCollationElementIterator(contraction);
            iter.SetOffset(3);
            order = CollationTest.GetOrders(iter);
            iter.SetOffset(4); // sets offset in the middle of ch
            order2 = CollationTest.GetOrders(iter);
            if (!Arrays.Equals(order, order2))
            {
                Errln("Error: setting offset in the middle of a contraction should be the same as setting it to the start of the contraction");
            }
            // setting offset in the middle of a surrogate pair
            String surrogate = "\ud800\udc00str";

            iter  = tailored.GetCollationElementIterator(surrogate);
            order = CollationTest.GetOrders(iter);
            iter.SetOffset(1); // sets offset in the middle of surrogate
            order2 = CollationTest.GetOrders(iter);
            if (!Arrays.Equals(order, order2))
            {
                Errln("Error: setting offset in the middle of a surrogate pair should be the same as setting it to the start of the surrogate pair");
            }
            surrogate = "simple\ud800\udc00str";
            iter      = tailored.GetCollationElementIterator(surrogate);
            iter.SetOffset(6);
            order = CollationTest.GetOrders(iter);
            iter.SetOffset(7); // sets offset in the middle of surrogate
            order2 = CollationTest.GetOrders(iter);
            if (!Arrays.Equals(order, order2))
            {
                Errln("Error: setting offset in the middle of a surrogate pair should be the same as setting it to the start of the surrogate pair");
            }
            // TODO: try iterating halfway through a messy string.
        }