Exemplo n.º 1
0
            public Spec(string theSpec)
            {
                top        = theSpec;
                spec       = null;
                scriptName = null;
                try
                {
                    // Canonicalize script name.  If top is a script name then
                    // script != UScript.INVALID_CODE.
                    int script = UScript.GetCodeFromName(top);

                    // Canonicalize script name -or- do locale->script mapping
                    int[] s = UScript.GetCode(top);
                    if (s != null)
                    {
                        scriptName = UScript.GetName(s[0]);
                        // If the script name is the same as top then it's redundant
                        if (scriptName.Equals(top, StringComparison.OrdinalIgnoreCase))
                        {
                            scriptName = null;
                        }
                    }

                    isSpecLocale = false;
                    res          = null;
                    // If 'top' is not a script name, try a locale lookup
                    if (script == UScript.InvalidCode)
                    {
                        // ICU4N specific - CultureInfo doesn't support IANA culture names, so we use ULocale instead.
                        ULocale toploc = new ULocale(top);

                        //CultureInfo toploc = LocaleUtility.GetLocaleFromName(top);
                        res = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuTransliteratorBaseName, toploc, Transliterator.ICU_DATA_CLASS_LOADER);
                        // Make sure we got the bundle we wanted; otherwise, don't use it
                        if (res != null && LocaleUtility.IsFallbackOf(res.GetULocale().ToString(), top))
                        {
                            isSpecLocale = true;
                        }
                    }
                }
                catch (MissingManifestResourceException)
                {
                    ////CLOVER:OFF
                    // The constructor is called from multiple private methods
                    //  that protects an invalid scriptName
                    scriptName = null;
                    ////CLOVER:ON
                }
                // assert(spec != top);
                Reset();
            }
Exemplo n.º 2
0
        public void TestScriptNamesUsingTry()
        {
            int v, rev;

            for (int i = 0; i < UScript.CodeLimit; i++)
            {
                if (!UScript.TryGetName(i, out string name) || name.Equals(""))
                {
                    Errln("FAILED: getName for code : " + i);
                }
                if (name != null)
                {
                    /* test reverse mapping */
                    rev = UScript.GetCodeFromName(name);
                    if (rev != (int)i)
                    {
                        Errln("Property round-trip failure: " + i + " -> " +
                              name + " -> " + rev);
                    }
                }
                if (!UScript.TryGetShortName(i, out string shortName) || shortName.Equals(""))
                {
                    Errln("FAILED: getName for code : " + i);
                }
                if (shortName != null)
                {
                    /* test reverse mapping */
                    rev = UScript.GetCodeFromName(shortName);
                    if (rev != (int)i)
                    {
                        Errln("Property round-trip failure: " + i + " -> " +
                              shortName + " -> " + rev);
                    }
                }
            }
        }