Beispiel #1
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);
        }
Beispiel #2
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);
        }