/// <summary>Creates a new <see cref="ICUTokenizerFactory"/>.</summary>
        public ICUTokenizerFactory(IDictionary <string, string> args)
            : base(args)
        {
            tailored = new Dictionary <int, string>();
            string rulefilesArg = Get(args, RULEFILES);

            if (rulefilesArg != null)
            {
                IList <string> scriptAndResourcePaths = SplitFileNames(rulefilesArg);
                foreach (string scriptAndResourcePath in scriptAndResourcePaths)
                {
                    int    colonPos     = scriptAndResourcePath.IndexOf(":");
                    string scriptCode   = scriptAndResourcePath.Substring(0, colonPos - 0).Trim();
                    string resourcePath = scriptAndResourcePath.Substring(colonPos + 1).Trim();
                    tailored[UChar.GetPropertyValueEnum(UProperty.Script, scriptCode)] = resourcePath;
                }
            }
            cjkAsWords     = GetBoolean(args, "cjkAsWords", true);
            myanmarAsWords = GetBoolean(args, "myanmarAsWords", true);
            if (args.Count != 0)
            {
                throw new ArgumentException("Unknown parameters: " + args);
            }
        }
示例#2
0
        public void TestPropertyNames()
        {
            int        v, rev;
            UProperty  p;
            NameChoice choice;

            for (p = 0; ; ++p)
            {
                bool sawProp = false;
                for (choice = 0; ; ++choice)
                {
                    string name = null;
                    try
                    {
                        name = UChar.GetPropertyName(p, choice);
                        if (!sawProp)
                        {
                            Log("prop " + p + ":");
                        }
                        string n = (name != null) ? ("\"" + name + '"') : "null";
                        Log(" " + choice + "=" + n);
                        sawProp = true;
                    }
                    catch (ArgumentException e)
                    {
                        if (choice > 0)
                        {
                            break;
                        }
                    }
                    if (name != null)
                    {
                        /* test reverse mapping */
                        rev = UChar.GetPropertyEnum(name);
                        if (rev != (int)p)
                        {
                            Errln("Property round-trip failure: " + p + " -> " +
                                  name + " -> " + rev);
                        }
                    }
                }
                if (sawProp)
                {
                    /* looks like a valid property; check the values */
                    string pname = UChar.GetPropertyName(p, NameChoice.Long);
                    int    max   = 0;
                    if (p == UProperty.Canonical_Combining_Class)
                    {
                        max = 255;
                    }
                    else if (p == UProperty.General_Category_Mask)
                    {
                        /* it's far too slow to iterate all the way up to
                         * the real max, U_GC_P_MASK */
                        max = 0x1000; // U_GC_NL_MASK;
                    }
                    else if (p == UProperty.Block)
                    {
                        /* UBlockCodes, unlike other values, start at 1 */
                        max = 1;
                    }
                    Logln("");
                    for (v = -1; ; ++v)
                    {
                        bool sawValue = false;
                        for (choice = 0; ; ++choice)
                        {
                            string vname = null;
                            try
                            {
                                vname = UChar.GetPropertyValueName(p, v, choice);
                                string n = (vname != null) ? ("\"" + vname + '"') : "null";
                                if (!sawValue)
                                {
                                    Log(" " + pname + ", value " + v + ":");
                                }
                                Log(" " + choice + "=" + n);
                                sawValue = true;
                            }
                            catch (ArgumentException e)
                            {
                                if (choice > 0)
                                {
                                    break;
                                }
                            }
                            if (vname != null)
                            {
                                /* test reverse mapping */
                                rev = UChar.GetPropertyValueEnum(p, vname);
                                if (rev != v)
                                {
                                    Errln("Value round-trip failure (" + pname +
                                          "): " + v + " -> " +
                                          vname + " -> " + rev);
                                }
                            }
                        }
                        if (sawValue)
                        {
                            Logln("");
                        }
                        if (!sawValue && v >= max)
                        {
                            break;
                        }
                    }
                }
                if (!sawProp)
                {
                    if (p >= UPropertyConstants.String_Limit)
                    {
                        break;
                    }
                    else if (p >= UPropertyConstants.Double_Limit)
                    {
                        p = UPropertyConstants.String_Start - 1;
                    }
                    else if (p >= UPropertyConstants.Mask_Limit)
                    {
                        p = UPropertyConstants.Double_Start - 1;
                    }
                    else if (p >= UPropertyConstants.Int_Limit)
                    {
                        p = UPropertyConstants.Mask_Start - 1;
                    }
                    else if (p >= UPropertyConstants.Binary_Limit)
                    {
                        p = UPropertyConstants.Int_Start - 1;
                    }
                }
            }

            int i = UChar.GetIntPropertyMinValue(
                UProperty.Canonical_Combining_Class);

            try
            {
                for (; i <= UChar.GetIntPropertyMaxValue(
                         UProperty.Canonical_Combining_Class);
                     i++)
                {
                    UChar.GetPropertyValueName(
                        UProperty.Canonical_Combining_Class,
                        i, NameChoice.Long);
                }
            }
            catch (ArgumentException e)
            {
                Errln("0x" + i.ToHexString()
                      + " should have a null property value name");
            }
        }