public void TestCompareStringString()
        {
            String            rule = "< c < b < a";
            RuleBasedCollator coll = new RuleBasedCollator(rule);

            NUnit.Framework.Assert.AreEqual(-1, coll.Compare("c", "a"));
        }
Exemplo n.º 2
0
        /// @tests java.text.CollationKey#toByteArray()
        // FIXME This test fails on Harmony ClassLibrary
        public void Failing_test_toByteArray()
        {
            // Test for method byte [] java.text.CollationKey.toByteArray()
            Collator collator = ILOG.J2CsMapping.Text.Collator.GetInstance();

            collator.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            CollationKey key1 = collator.GetCollationKey("abc");

            byte[] bytes = key1.ToByteArray();
            NUnit.Framework.Assert.IsTrue(bytes.Length >= 3, "Not enough bytes");

            try {
                collator = new RuleBasedCollator("= 1 , 2 ; 3 , 4 < 5 ; 6 , 7");
            } catch (ParseException e) {
                NUnit.Framework.Assert.Fail("ParseException");
                return;
            }
            bytes = collator.GetCollationKey("1234567").ToByteArray();

            /*
             * CollationElementIterator it =
             * ((RuleBasedCollator)collator).getCollationElementIterator("1234567");
             * int order; while ((order = it.next()) !=
             * CollationElementIterator.NULLORDER) {
             * System.out.println(Integer.toHexString(order)); } for (int i=0;
             * i<bytes.length; i+=2) {
             * System.out.print(Integer.toHexString(bytes[i]) +
             * Integer.toHexString(bytes[i+1]) + " "); } System.out.println();
             */
            byte[] result = new byte[] { 0, 2, 0, 2, 0, 2, 0, 0, 0, 3, 0, 3, 0, 1,
                                         0, 2, 0, 2, 0, 0, 0, 4, 0, 4, 0, 1, 0, 1, 0, 2 };
            // Failed in java too : NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(bytes,result),"Wrong bytes");
        }
        public void TestGetRules()
        {
            String            rule = "< a = b < c";
            RuleBasedCollator coll = new RuleBasedCollator(rule);

            NUnit.Framework.Assert.AreEqual(rule, coll.GetRules());
        }
        /*
         * For german, you might want oe to sort and match with o umlaut.
         * This is not the default, but you can make a customized ruleset to do this.
         *
         * The default is DIN 5007-1, this shows how to tailor a collator to get DIN 5007-2 behavior.
         *  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4423383
         */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testCustomRules() throws Exception
        public virtual void testCustomRules()
        {
            RuleBasedCollator baseCollator = (RuleBasedCollator)Collator.getInstance(new Locale("de", "DE"));

            string DIN5007_2_tailorings = "& ae , a\u0308 & AE , A\u0308" + "& oe , o\u0308 & OE , O\u0308" + "& ue , u\u0308 & UE , u\u0308";

            RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.Rules + DIN5007_2_tailorings);
            string            tailoredRules    = tailoredCollator.Rules;
            //
            // at this point, you would save these tailoredRules to a file,
            // and use the custom parameter.
            //
            string germanUmlaut = "Töne";
            string germanOE     = "Toene";
            IDictionary <string, string> args = new Dictionary <string, string>();

            args["custom"]   = "rules.txt";
            args["strength"] = "primary";
            CollationKeyFilterFactory factory = new CollationKeyFilterFactory(args);

            factory.inform(new StringMockResourceLoader(tailoredRules));
            TokenStream tsUmlaut = factory.create(new MockTokenizer(new StringReader(germanUmlaut), MockTokenizer.KEYWORD, false));
            TokenStream tsOE     = factory.create(new MockTokenizer(new StringReader(germanOE), MockTokenizer.KEYWORD, false));

            assertCollatesToSame(tsUmlaut, tsOE);
        }
Exemplo n.º 5
0
        public void TestNormalization()
        {
            String rules = "&a < \u0300\u0315 < A\u0300\u0315 < \u0316\u0315B < \u0316\u0300\u0315";

            String[]          testdata = { "\u1ED9",      "o\u0323\u0302",
                                           "\u0300\u0315",         "\u0315\u0300",
                                           "A\u0300\u0315B",       "A\u0315\u0300B",
                                           "A\u0316\u0315B",       "A\u0315\u0316B",
                                           "\u0316\u0300\u0315",   "\u0315\u0300\u0316",
                                           "A\u0316\u0300\u0315B", "A\u0315\u0300\u0316B",
                                           "\u0316\u0315\u0300",   "A\u0316\u0315\u0300B" };
            RuleBasedCollator coll = null;

            try
            {
                coll = new RuleBasedCollator(rules);
                coll.Decomposition = NormalizationMode.CanonicalDecomposition; //(Collator.CANONICAL_DECOMPOSITION);
            }
            catch (Exception e)
            {
                Warnln("ERROR: in creation of collator using rules " + rules);
                return;
            }

            CollationElementIterator iter = coll.GetCollationElementIterator("testing");

            for (int count = 0; count < testdata.Length; count++)
            {
                iter.SetText(testdata[count]);
                CollationTest.BackAndForth(this, iter);
            }
        }
Exemplo n.º 6
0
        public void TestReordering()
        {
            String[] tests =
            {
                "\u0E41c\u0301",            "=", "\u0E41\u0107",                   // composition
                "\u0E41\uD835\uDFCE",       "<", "\u0E41\uD835\uDFCF",             // supplementaries
                "\u0E41\uD834\uDD5F",       "=", "\u0E41\uD834\uDD58\uD834\uDD65", // supplementary composition decomps to supplementary
                "\u0E41\uD87E\uDC02",       "=", "\u0E41\u4E41",                   // supplementary composition decomps to BMP
                "\u0E41\u0301",             "=", "\u0E41\u0301",                   // unsafe (just checking backwards iteration)
                "\u0E41\u0301\u0316",       "=", "\u0E41\u0316\u0301",

                "abc\u0E41c\u0301",         "=", "abc\u0E41\u0107",                   // composition
                "abc\u0E41\uD834\uDC00",    "<", "abc\u0E41\uD834\uDC01",             // supplementaries
                "abc\u0E41\uD834\uDD5F",    "=", "abc\u0E41\uD834\uDD58\uD834\uDD65", // supplementary composition decomps to supplementary
                "abc\u0E41\uD87E\uDC02",    "=", "abc\u0E41\u4E41",                   // supplementary composition decomps to BMP
                "abc\u0E41\u0301",          "=", "abc\u0E41\u0301",                   // unsafe (just checking backwards iteration)
                "abc\u0E41\u0301\u0316",    "=", "abc\u0E41\u0316\u0301",

                "\u0E41c\u0301abc",         "=", "\u0E41\u0107abc",                   // composition
                "\u0E41\uD834\uDC00abc",    "<", "\u0E41\uD834\uDC01abc",             // supplementaries
                "\u0E41\uD834\uDD5Fabc",    "=", "\u0E41\uD834\uDD58\uD834\uDD65abc", // supplementary composition decomps to supplementary
                "\u0E41\uD87E\uDC02abc",    "=", "\u0E41\u4E41abc",                   // supplementary composition decomps to BMP
                "\u0E41\u0301abc",          "=", "\u0E41\u0301abc",                   // unsafe (just checking backwards iteration)
                "\u0E41\u0301\u0316abc",    "=", "\u0E41\u0316\u0301abc",

                "abc\u0E41c\u0301abc",      "=", "abc\u0E41\u0107abc",                   // composition
                "abc\u0E41\uD834\uDC00abc", "<", "abc\u0E41\uD834\uDC01abc",             // supplementaries
                "abc\u0E41\uD834\uDD5Fabc", "=", "abc\u0E41\uD834\uDD58\uD834\uDD65abc", // supplementary composition decomps to supplementary
                "abc\u0E41\uD87E\uDC02abc", "=", "abc\u0E41\u4E41abc",                   // supplementary composition decomps to BMP
                "abc\u0E41\u0301abc",       "=", "abc\u0E41\u0301abc",                   // unsafe (just checking backwards iteration)
                "abc\u0E41\u0301\u0316abc", "=", "abc\u0E41\u0316\u0301abc",
            };

            RuleBasedCollator collator;

            try
            {
                collator = GetThaiCollator();
            }
            catch (Exception e)
            {
                Warnln("could not construct Thai collator");
                return;
            }
            CompareArray(collator, tests);

            String rule = "& c < ab";

            String[] testcontraction = { "\u0E41ab", ">", "\u0E41c" };
            try
            {
                collator = new RuleBasedCollator(rule);
            }
            catch (Exception e)
            {
                Errln("Error: could not construct collator with rule " + rule);
                return;
            }
            CompareArray(collator, testcontraction);
        }
Exemplo n.º 7
0
        public void TestCustomRules()
        {
            String DIN5007_2_tailorings =
                "& ae , a\u0308 & AE , A\u0308" +
                "& oe , o\u0308 & OE , O\u0308" +
                "& ue , u\u0308 & UE , u\u0308";

            string baseRules = RuleBasedCollator.GetCollationRules(new Icu.Locale("de-DE"), UColRuleOption.UCOL_TAILORING_ONLY);
            //RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseRules + DIN5007_2_tailorings);

            string tailoredRules = baseRules + DIN5007_2_tailorings;
            //
            // at this point, you would save these tailoredRules to a file,
            // and use the custom parameter.
            //
            String germanUmlaut = "Töne";
            String germanOE     = "Toene";
            IDictionary <String, String> args = new Dictionary <String, String>();

            args.Put("custom", "rules.txt");
            args.Put("strength", "primary");
            ICUCollationKeyFilterFactory factory = new ICUCollationKeyFilterFactory(args);

            factory.Inform(new StringMockResourceLoader(tailoredRules));
            TokenStream tsUmlaut = factory.Create(
                new KeywordTokenizer(new StringReader(germanUmlaut)));
            TokenStream tsOE = factory.Create(
                new KeywordTokenizer(new StringReader(germanOE)));

            assertCollatesToSame(tsUmlaut, tsOE);
        }
Exemplo n.º 8
0
 public void GetSortKey_Null()
 {
     using (var ucaCollator = new RuleBasedCollator(string.Empty))
     {
         Assert.That(() => ucaCollator.GetSortKey(null), Throws.TypeOf <ArgumentNullException>());
     }
 }
Exemplo n.º 9
0
        public void TestDemo2()
        {
            Logln("Demo Test 2 : Create a new table collation with rules \"& C < ch , cH, Ch, CH\"");
            Collator col = Collator.GetInstance(new CultureInfo("en") /* Locale.ENGLISH */);


            String baseRules = ((RuleBasedCollator)col).GetRules();
            String newRules  = "& C < ch , cH, Ch, CH";

            newRules = baseRules + newRules;
            RuleBasedCollator myCollation = null;

            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Errln("Fail to create RuleBasedCollator with rules:" + newRules);
                return;
            }

            int j, n;

            for (j = 0; j < TOTALTESTSET; j++)
            {
                for (n = j + 1; n < TOTALTESTSET; n++)
                {
                    DoTest(myCollation, testCases[results[9][j]], testCases[results[9][n]], -1);
                }
            }
        }
Exemplo n.º 10
0
 public void Construct_EmptyRules_UCAcollator()
 {
     using (var collator = new RuleBasedCollator(string.Empty))
     {
         Assert.That(collator, Is.Not.Null);
     }
 }
Exemplo n.º 11
0
        public void Init()
        {
            String ruleset = "& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";

            // String ruleset = "& Four, 4";
            myCollation = new RuleBasedCollator(ruleset);
        }
Exemplo n.º 12
0
        public void TestCustomRules()
        {
            RuleBasedCollator baseCollator = (RuleBasedCollator)Collator.GetInstance(new UCultureInfo("de_DE"));

            String DIN5007_2_tailorings =
                "& ae , a\u0308 & AE , A\u0308" +
                "& oe , o\u0308 & OE , O\u0308" +
                "& ue , u\u0308 & UE , u\u0308";

            RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.GetRules() + DIN5007_2_tailorings);
            string            tailoredRules    = tailoredCollator.GetRules();
            //
            // at this point, you would save these tailoredRules to a file,
            // and use the custom parameter.
            //
            String germanUmlaut = "Töne";
            String germanOE     = "Toene";
            IDictionary <String, String> args = new Dictionary <String, String>();

            args.Put("custom", "rules.txt");
            args.Put("strength", "primary");
            ICUCollationKeyFilterFactory factory = new ICUCollationKeyFilterFactory(args);

            factory.Inform(new StringMockResourceLoader(tailoredRules));
            TokenStream tsUmlaut = factory.Create(
                new KeywordTokenizer(new StringReader(germanUmlaut)));
            TokenStream tsOE = factory.Create(
                new KeywordTokenizer(new StringReader(germanOE)));

            assertCollatesToSame(tsUmlaut, tsOE);
        }
Exemplo n.º 13
0
        public void TestDemo3()
        {
            // Logln("Demo Test 3 : Create a new table collation with rules \"& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'\"");
            Collator col = Collator.GetInstance(new CultureInfo("en") /* Locale.ENGLISH */);


            String baseRules = ((RuleBasedCollator)col).GetRules();
            String newRules  = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'";

            newRules = baseRules + newRules;
            RuleBasedCollator myCollation = null;

            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Errln("Fail to create RuleBasedCollator with rules:" + newRules);
                return;
            }

            int j, n;

            for (j = 0; j < TOTALTESTSET; j++)
            {
                for (n = j + 1; n < TOTALTESTSET; n++)
                {
                    DoTest(myCollation, testCases[results[10][j]], testCases[results[10][n]], -1);
                }
            }
        }
Exemplo n.º 14
0
 public int Compare(string rules, string string1, string string2)
 {
     using (var ucaCollator = new RuleBasedCollator(rules))
     {
         return(ucaCollator.Compare(string1, string2));
     }
 }
Exemplo n.º 15
0
 public void Construct_Rules_Okay()
 {
     using (var collator = new RuleBasedCollator(SerbianRules))
     {
         Assert.That(collator, Is.Not.Null);
     }
 }
Exemplo n.º 16
0
 internal void CompareArray(RuleBasedCollator c, String[] tests)
 {
     for (int i = 0; i < tests.Length; i += 3)
     {
         int expect = 0;
         if (tests[i + 1].Equals("<"))
         {
             expect = -1;
         }
         else if (tests[i + 1].Equals(">"))
         {
             expect = 1;
         }
         else if (tests[i + 1].Equals("="))
         {
             expect = 0;
         }
         else
         {
             // expect = Integer.decode(tests[i+1]).intValue();
             Errln("Error: unknown operator " + tests[i + 1]);
             return;
         }
         String s1 = tests[i];
         String s2 = tests[i + 2];
         CollationTest.DoTest(this, c, s1, s2, expect);
     }
 }
Exemplo n.º 17
0
 public int AlternateHandlingSetting(CollationStrength collationStrength,
                                     AlternateHandling alternateHandling, string string1, string string2)
 {
     /*  The Alternate attribute is used to control the handling of the so-called
      * variable characters in the UCA: whitespace, punctuation and symbols. If
      * Alternate is set to Non-Ignorable (N), then differences among these
      * characters are of the same importance as differences among letters.
      * If Alternate is set to Shifted (S), then these characters are of only
      * minor importance. The Shifted value is often used in combination with
      * Strength set to Quaternary. In such a case, white-space, punctuation,
      * and symbols are considered when comparing strings, but only if all other
      * aspects of the strings (base letters, accents, and case) are identical.
      * If Alternate is not set to Shifted, then there is no difference between
      * a Strength of 3 and a Strength of 4.
      * Example:
      *        S=3, A=N di Silva < Di Silva < diSilva < U.S.A. < USA
      *        S=3, A=S di Silva = diSilva < Di Silva  < U.S.A. = USA
      *        S=4, A=S di Silva < diSilva < Di Silva < U.S.A. < USA
      */
     using (var ucaCollator = new RuleBasedCollator(string.Empty, collationStrength))
     {
         ucaCollator.AlternateHandling = alternateHandling;
         return(ucaCollator.Compare(string1, string2));
     }
 }
Exemplo n.º 18
0
 private CollationElementIterator(RuleBasedCollator collator)
 {
     iter_      = null;
     rbc_       = collator;
     otherHalf_ = 0;
     dir_       = 0;
     offsets_   = null;
 }
Exemplo n.º 19
0
 public void Clone()
 {
     using (var danishCollator = new RuleBasedCollator(DanishRules))
         using (var danishCollator2 = (RuleBasedCollator)danishCollator.Clone())
         {
             Assert.That(danishCollator2.Compare("wa", "vb"), Is.EqualTo(-1));
         }
 }
Exemplo n.º 20
0
        public void TestNormalizedUnicodeChar()
        {
            // thai should have normalization on
            RuleBasedCollator th_th = null;

            try
            {
                th_th = (RuleBasedCollator)Collator.GetInstance(
                    new CultureInfo("th-TH"));
            }
            catch (Exception e)
            {
                Warnln("Error creating Thai collator");
                return;
            }
            StringBuffer source = new StringBuffer();

            source.Append('\uFDFA');
            CollationElementIterator iter
                = th_th.GetCollationElementIterator(source.ToString());

            CollationTest.BackAndForth(this, iter);
            for (char codepoint = (char)0x1; codepoint < 0xfffe;)
            {
                source.Delete(0, source.Length);
                while (codepoint % 0xFF != 0)
                {
                    if (UChar.IsDefined(codepoint))
                    {
                        source.Append(codepoint);
                    }
                    codepoint++;
                }

                if (UChar.IsDefined(codepoint))
                {
                    source.Append(codepoint);
                }

                if (codepoint != 0xFFFF)
                {
                    codepoint++;
                }

                /*if (((int)codepoint) >= 0xfe00) {
                 *  String str = source.substring(185, 190);
                 *  System.out.println(com.ibm.icu.impl.Utility.escape(str));
                 *  System.out.println("codepoint "
                 + Integer.toHexString(codepoint)
                 + "length " + str.Length);
                 +  iter = th_th.GetCollationElementIterator(str);
                 +  CollationTest.BackAndForth(this, iter);
                 */
                iter = th_th.GetCollationElementIterator(source.ToString());
                // A basic test to see if it's working at all
                CollationTest.BackAndForth(this, iter);
            }
        }
Exemplo n.º 21
0
 public void GetSortKey()
 {
     using (var serbianCollator = new RuleBasedCollator(SerbianRules))
     {
         var sortKeyČUKIĆ = serbianCollator.GetSortKey("ČUKIĆ SLOBODAN");
         var sortKeyCUKIĆ = serbianCollator.GetSortKey("CUKIĆ SVETOZAR");
         Assert.That(SortKey.Compare(sortKeyČUKIĆ, sortKeyCUKIĆ), Is.EqualTo(1));
     }
 }
Exemplo n.º 22
0
 public void GetSortKey_emptyString()
 {
     using (var ucaCollator = new RuleBasedCollator(string.Empty))
     {
         SortKey key = ucaCollator.GetSortKey(string.Empty);
         Assert.IsNotNull(key);
         Assert.IsNotNull(key.KeyData);
     }
 }
Exemplo n.º 23
0
        // private methods -----------------------------------------------------

        private static RuleBasedCollator GetThaiCollator()
        {
            if (m_collator_ == null)
            {
                m_collator_ = (RuleBasedCollator)Collator.GetInstance(
                    new CultureInfo("th-TH"));
            }
            return(m_collator_);
        }
Exemplo n.º 24
0
        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
            }
        }
Exemplo n.º 25
0
 public int NumericCollationSetting(NumericCollation numericCollation, string string1,
                                    string string2)
 {
     using (var ucaCollator = new RuleBasedCollator(string.Empty))
     {
         Assert.AreEqual(NumericCollation.Off, ucaCollator.NumericCollation);
         ucaCollator.NumericCollation = numericCollation;
         return(ucaCollator.Compare(string1, string2));
     }
 }
Exemplo n.º 26
0
        public void TestRules()
        {
            String[] testSourceCases =
            {
                "\u0061\u0062\u007a",
                "\u0061\u0062\u007a",
            };

            String[] testTargetCases =
            {
                "\u0061\u0062\u00e4",
                "\u0061\u0062\u0061\u0308",
            };

            int i = 0;

            Logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\"");
            Collator col       = Collator.GetInstance(new CultureInfo("en-US"));
            String   baseRules = ((RuleBasedCollator)col).GetRules();
            String   newRules  = " & z < ";

            newRules = baseRules + newRules + (0x00e4).ToString(CultureInfo.InvariantCulture);
            RuleBasedCollator myCollation = null;

            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Warnln("Demo Test 1 Table Collation object creation failed.");
                return;
            }

            for (i = 0; i < 2; i++)
            {
                doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
            }
            Logln("Demo Test 2 : Create a new table collation with rules \"& z < a 0x0308\"");
            newRules = "";
            newRules = baseRules + " & z < a" + (0x0308).ToString(CultureInfo.InvariantCulture);
            try
            {
                myCollation = new RuleBasedCollator(newRules);
            }
            catch (Exception e)
            {
                Errln("Demo Test 1 Table Collation object creation failed.");
                return;
            }
            for (i = 0; i < 2; i++)
            {
                doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
            }
        }
Exemplo n.º 27
0
 public IcuRulesCollator(string rules)
 {
     try
     {
         _collator = new RuleBasedCollator(LdmlCollationParser.ReplaceUnicodeEscapesForIcu(rules));
     }
     catch (DllNotFoundException e)
     {
         throw new DllNotFoundException("IcuRulesCollator requires the ICU dlls to be present", e);
     }
 }
Exemplo n.º 28
0
		public IcuRulesCollator(string rules)
		{
			try
			{
				_collator = new RuleBasedCollator(LdmlCollationParser.ReplaceUnicodeEscapesForIcu(rules));
			}
			catch (DllNotFoundException e)
			{
				throw new DllNotFoundException("IcuRulesCollator requires the ICU dlls to be present", e);
			}
		}
Exemplo n.º 29
0
 private void setCollShifted(RuleBasedCollator coll)
 {
     if (coll != null)
     {
         coll.Decomposition              = (Collator.CANONICAL_DECOMPOSITION);
         coll.IsLowerCaseFirst           = (false);
         coll.IsCaseLevel                = (false);
         coll.Strength                   = (isAtLeastUCA62 ? Collator.IDENTICAL : Collator.QUATERNARY);
         coll.IsAlternateHandlingShifted = (true);
     }
 }
Exemplo n.º 30
0
        public void TestCornerCases()
        {
            String[] TESTS =
            {
                // Shorter words precede longer
                "\u0e01",                         "<", "\u0e01\u0e01",

                // Tone marks are considered after letters (i.e. are primary ignorable)
                "\u0e01\u0e32",                   "<", "\u0e01\u0e49\u0e32",

                // ditto for other over-marks
                "\u0e01\u0e32",                   "<", "\u0e01\u0e32\u0e4c",

                // commonly used mark-in-context order.
                // In effect, marks are sorted after each syllable.
                "\u0e01\u0e32\u0e01\u0e49\u0e32", "<", "\u0e01\u0e48\u0e32\u0e01\u0e49\u0e32",

                // Hyphens and other punctuation follow whitespace but come before letters
                "\u0e01\u0e32",                   "=", "\u0e01\u0e32-",
                "\u0e01\u0e32-",                  "<", "\u0e01\u0e32\u0e01\u0e32",

                // Doubler follows an indentical word without the doubler
                "\u0e01\u0e32",                   "=", "\u0e01\u0e32\u0e46",
                "\u0e01\u0e32\u0e46",             "<", "\u0e01\u0e32\u0e01\u0e32",

                // \u0e45 after either \u0e24 or \u0e26 is treated as a single
                // combining character, similar to "c < ch" in traditional spanish.
                // TODO: beef up this case
                "\u0e24\u0e29\u0e35",             "<", "\u0e24\u0e45\u0e29\u0e35",
                "\u0e26\u0e29\u0e35",             "<", "\u0e26\u0e45\u0e29\u0e35",

                // Vowels reorder, should compare \u0e2d and \u0e34
                "\u0e40\u0e01\u0e2d",             "<", "\u0e40\u0e01\u0e34",

                // Tones are compared after the rest of the word (e.g. primary ignorable)
                "\u0e01\u0e32\u0e01\u0e48\u0e32", "<", "\u0e01\u0e49\u0e32\u0e01\u0e32",

                // Periods are ignored entirely
                "\u0e01.\u0e01.",                 "<", "\u0e01\u0e32",
            };

            RuleBasedCollator coll = null;

            try
            {
                coll = GetThaiCollator();
            }
            catch (Exception e)
            {
                Warnln("could not construct Thai collator");
                return;
            }
            CompareArray(coll, TESTS);
        }
Exemplo n.º 31
0
 private void setCollShifted(RuleBasedCollator coll)
 {
     if (coll != null)
     {
         coll.Decomposition              = (Collator.CanonicalDecomposition);
         coll.IsLowerCaseFirst           = (false);
         coll.IsCaseLevel                = (false);
         coll.Strength                   = (isAtLeastUCA62 ? Collator.Identical : Collator.Quaternary);
         coll.IsAlternateHandlingShifted = (true);
     }
 }
Exemplo n.º 32
0
		public SimpleRulesCollator(string rules)
		{
			string icuRules = ConvertToIcuRules(rules);
			try
			{
				_collator = new RuleBasedCollator(icuRules);
			}
			catch (DllNotFoundException e)
			{
				throw new DllNotFoundException("SimpleRulesCollator uses Icu and thus requires the ICU dlls to be present", e);
			}
		}
        /*
           * For german, you might want oe to sort and match with o umlaut.
           * This is not the default, but you can make a customized ruleset to do this.
           *
           * The default is DIN 5007-1, this shows how to tailor a collator to get DIN 5007-2 behavior.
           *  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4423383
           */
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testCustomRules() throws Exception
        public virtual void testCustomRules()
        {
            RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new Locale("de", "DE"));

            string DIN5007_2_tailorings = "& ae , a\u0308 & AE , A\u0308" + "& oe , o\u0308 & OE , O\u0308" + "& ue , u\u0308 & UE , u\u0308";

            RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.Rules + DIN5007_2_tailorings);
            string tailoredRules = tailoredCollator.Rules;
            //
            // at this point, you would save these tailoredRules to a file,
            // and use the custom parameter.
            //
            string germanUmlaut = "Töne";
            string germanOE = "Toene";
            IDictionary<string, string> args = new Dictionary<string, string>();
            args["custom"] = "rules.txt";
            args["strength"] = "primary";
            CollationKeyFilterFactory factory = new CollationKeyFilterFactory(args);
            factory.inform(new StringMockResourceLoader(tailoredRules));
            TokenStream tsUmlaut = factory.create(new MockTokenizer(new StringReader(germanUmlaut), MockTokenizer.KEYWORD, false));
            TokenStream tsOE = factory.create(new MockTokenizer(new StringReader(germanOE), MockTokenizer.KEYWORD, false));

            assertCollatesToSame(tsUmlaut, tsOE);
        }