コード例 #1
0
ファイル: UnicodeMap.cs プロジェクト: bdqnghi/j2cstranslator
 /// <summary>
 /// Add all the (main) values from a Unicode property
 /// </summary>
 ///
 /// <param name="prop">the property to add to the map</param>
 /// <returns>this (for chaining)</returns>
 public UnicodeMap PutAll(UnicodeMap prop)
 {
     // TODO optimize
     for (int i = 0; i <= 0x10FFFF; ++i)
     {
         _put(i, prop.GetValue(i));
     }
     return(this);
 }
コード例 #2
0
ファイル: UnicodeMap.cs プロジェクト: bdqnghi/j2cstranslator
 public UnicodeMap ComposeWith(UnicodeMap other, UnicodeMap.Composer composer)
 {
     for (int i = 0; i <= 0x10FFFF; ++i)
     {
         Object v1 = GetValue(i);
         Object v2 = other.GetValue(i);
         Object v3 = composer.Compose(i, v1, v2);
         if (v1 != v3 && (v1 == null || !v1.Equals(v3)))
         {
             Put(i, v3);
         }
     }
     return(this);
 }
コード例 #3
0
        public void TestUnicodeMap()
        {
            random.SetSeed(12345);
            // do random change to both, then compare
            Logln("Comparing against HashMap");
            for (int counter = 0; counter < ITERATIONS; ++counter)
            {
                int    start     = random.Next(LIMIT);
                String value_ren = TEST_VALUES[random.Next(TEST_VALUES.Length)];
                String logline   = IBM.ICU.Impl.Utility.Hex(start) + "\t" + value_ren;
                if (SHOW_PROGRESS)
                {
                    Logln(counter + "\t" + logline);
                }
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(log, logline);
                if (DEBUG && counter == 144)
                {
                    System.Console.Out.WriteLine(" debug");
                }
                map1.Put(start, value_ren);
                ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(start)), value_ren);
                Check(counter);
            }
            CheckNext(LIMIT);

            Logln("Setting General Category");
            map1 = new UnicodeMap();
            map2 = new SortedList();
            for (int cp = 0; cp <= SET_LIMIT; ++cp)
            {
                int enumValue = IBM.ICU.Lang.UCharacter.GetIntPropertyValue(cp, propEnum);
                // if (enumValue <= 0) continue; // for smaller set
                String value_0 = IBM.ICU.Lang.UCharacter.GetPropertyValueName(propEnum, enumValue,
                                                                              IBM.ICU.Lang.UProperty_Constants.NameChoice.LONG);
                map1.Put(cp, value_0);
                ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(cp)), value_0);
            }
            CheckNext(Int32.MaxValue);

            Logln("Comparing General Category");
            Check(-1);
            Logln("Comparing Values");
            ILOG.J2CsMapping.Collections.ISet values1 = (ISet)map1.GetAvailableValues(new SortedSet());
            ILOG.J2CsMapping.Collections.ISet values2 = new SortedSet(map2.Values);
            if (!IBM.ICU.Charset.TestBoilerplate.VerifySetsIdentical(this, values1, values2))
            {
                throw new ArgumentException("Halting");
            }
            Logln("Comparing Sets");
            for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(values1.GetEnumerator()); it.HasNext();)
            {
                Object value_1 = it.Next();
                Logln((value_1 == null) ? "null" : value_1.ToString());
                UnicodeSet set1 = map1.GetSet(value_1);
                UnicodeSet set2 = IBM.ICU.Charset.TestBoilerplate.GetSet(map2, value_1);
                if (!IBM.ICU.Charset.TestBoilerplate.VerifySetsIdentical(this, set1, set2))
                {
                    throw new ArgumentException("Halting");
                }
            }

            Logln("Getting Scripts");
            UnicodeMap scripts = IBM.ICU.Charset.ICUPropertyFactory.Make().GetProperty("script")
                                 .GetUnicodeMap_internal();

            UnicodeMap.Composer composer = new TestUtilities.Anonymous_C1();

            Logln("Trying Compose");
            UnicodeMap composed = ((UnicodeMap)scripts.CloneAsThawed())
                                  .ComposeWith(map1, composer);
            Object last = "";

            for (int i = 0; i < 0x10FFFF; ++i)
            {
                Object comp = composed.GetValue(i);
                Object gc   = map1.GetValue(i);
                Object sc   = scripts.GetValue(i);
                if (!comp.Equals(composer.Compose(i, gc, sc)))
                {
                    Errln("Failed compose at: " + i);
                }
                if (!last.Equals(comp))
                {
                    Logln(IBM.ICU.Impl.Utility.Hex(i) + "\t" + comp);
                    last = comp;
                }
            }

            // check boilerplate
            IList argList = new ArrayList();

            ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "TestMain");
            if (paras.nothrow)
            {
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "-nothrow");
            }
            if (paras.verbose)
            {
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "-verbose");
            }
            String[] args = new String[argList.Count];
            ILOG.J2CsMapping.Collections.Collections.ToArray(argList, args);
            new TestUtilities.UnicodeMapBoilerplate().Run(args);
            // TODO: the following is not being reached
            new TestUtilities.UnicodeSetBoilerplate().Run(args);
        }