Exemple #1
0
            public void TestLocaleGetCode(UCultureInfo testLocaleName, int expected)
            {
                int[] code = UScript.GetCode(testLocaleName);
                if (code == null)
                {
                    if (expected != UScript.InvalidCode)
                    {
                        Errln("Error testing UScript.getCode(). Got: null" + " Expected: " + expected + " for locale "
                              + testLocaleName);
                    }
                }
                else if ((code[0] != expected))
                {
                    Errln("Error testing UScript.getCode(). Got: " + code[0] + " Expected: " + expected + " for locale "
                          + testLocaleName);
                }

                UCultureInfo esperanto = new UCultureInfo("eo_DE");

                using (new ThreadCultureChange(esperanto, esperanto))
                {
                    code = UScript.GetCode(esperanto);
                    if (code != null)
                    {
                        if (code[0] != UScript.Latin)
                        {
                            Errln("Did not get the expected script code for Esperanto");
                        }
                    }
                    else
                    {
                        Warnln("Could not load the locale data.");
                    }
                }

                // Should work regardless of whether we have locale data for the language.
                AssertEqualScripts("tg script: Cyrl",  // Tajik
                                   new int[] { UScript.Cyrillic }, UScript.GetCode(new UCultureInfo("tg")));
                AssertEqualScripts("xsr script: Deva", // Sherpa
                                   new int[] { UScript.Devanagari }, UScript.GetCode(new UCultureInfo("xsr")));

                // Multi-script languages.
                AssertEqualScripts("ja scripts: Kana Hira Hani",
                                   new int[] { UScript.Katakana, UScript.Hiragana, UScript.Han }, UScript.GetCode(new UCultureInfo("ja")));
                AssertEqualScripts("ko scripts: Hang Hani", new int[] { UScript.Hangul, UScript.Han },
                                   UScript.GetCode(new UCultureInfo("ko")));
                AssertEqualScripts("zh script: Hani", new int[] { UScript.Han }, UScript.GetCode(new UCultureInfo("zh")));
                AssertEqualScripts("zh-Hant scripts: Hani Bopo", new int[] { UScript.Han, UScript.Bopomofo },
                                   UScript.GetCode(new UCultureInfo("zh_Hant")));
                AssertEqualScripts("zh-TW scripts: Hani Bopo", new int[] { UScript.Han, UScript.Bopomofo },
                                   UScript.GetCode(new UCultureInfo("zh_Hant_TW")));

                // Ambiguous API, but this probably wants to return Latin rather than Rongorongo (Roro).
                AssertEqualScripts("ro-RO script: Latn", new int[] { UScript.Latin }, UScript.GetCode("ro-RO")); // String
                                                                                                                 // not
                                                                                                                 // UCultureInfo
            }
            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();
            }
Exemple #3
0
 /// <summary>
 /// Return the script code for a given name, or
 /// <see cref="UScript.InvalidCode"/> if not found.
 /// </summary>
 private static int ScriptNameToCode(string name)
 {
     try
     {
         int[] codes = UScript.GetCode(name);
         return(codes != null ? codes[0] : UScript.InvalidCode);
     }
     catch (MissingManifestResourceException)
     {
         ///CLOVER:OFF
         return(UScript.InvalidCode);
         ///CLOVER:ON
     }
 }
Exemple #4
0
 public void TestGetCode(string testName, int expected)
 {
     int[] code = UScript.GetCode(testName);
     if (code == null)
     {
         if (expected != UScript.InvalidCode)
         {
             // getCode returns null if the code could not be found
             Errln("Error testing UScript.getCode(). Got: null" + " Expected: " + expected + " for locale "
                   + testName);
         }
     }
     else if ((code[0] != expected))
     {
         Errln("Error testing UScript.getCode(). Got: " + code[0] + " Expected: " + expected + " for locale "
               + testName);
     }
 }
Exemple #5
0
            public void TestMultipleCodes(string testLocaleName, int[] expected, CultureInfo testLocale)
            {
                int[] code = UScript.GetCode(testLocaleName);
                if (code != null)
                {
                    for (int j = 0; j < code.Length; j++)
                    {
                        if (code[j] != expected[j])
                        {
                            Errln("Error testing UScript.getCode(). Got: " + code[j] + " Expected: " + expected[j]
                                  + " for locale " + testLocaleName);
                        }
                    }
                }
                else
                {
                    Errln("Error testing UScript.getCode() for locale " + testLocaleName);
                }

                Logln("  Testing UScript.getCode(Locale) with locale: " + testLocale.DisplayName);
                code = UScript.GetCode(testLocale);
                if (code != null)
                {
                    for (int j = 0; j < code.Length; j++)
                    {
                        if (code[j] != expected[j])
                        {
                            Errln("Error testing UScript.getCode(). Got: " + code[j] + " Expected: " + expected[j]
                                  + " for locale " + testLocaleName);
                        }
                    }
                }
                else
                {
                    Errln("Error testing UScript.getCode() for locale " + testLocaleName);
                }
            }
Exemple #6
0
        public void TestNewCode()
        {
            /*
             * These script codes were originally added to ICU pre-3.6, so that ICU would
             * have all ISO 15924 script codes. ICU was then based on Unicode 4.1.
             * These script codes were added with only short names because we don't
             * want to invent long names ourselves.
             * Unicode 5 and later encode some of these scripts and give them long names.
             * Whenever this happens, the long script names here need to be updated.
             */
            String[] expectedLong = new String[] {
                "Balinese", "Batak", "Blis", "Brahmi", "Cham", "Cirt", "Cyrs",
                "Egyd", "Egyh", "Egyptian_Hieroglyphs",
                "Geok", "Hans", "Hant", "Pahawh_Hmong", "Old_Hungarian", "Inds",
                "Javanese", "Kayah_Li", "Latf", "Latg",
                "Lepcha", "Linear_A", "Mandaic", "Maya", "Meroitic_Hieroglyphs",
                "Nko", "Old_Turkic", "Old_Permic", "Phags_Pa", "Phoenician",
                "Miao", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vai", "Visp", "Cuneiform",
                "Zxxx", "Unknown",
                "Carian", "Jpan", "Tai_Tham", "Lycian", "Lydian", "Ol_Chiki", "Rejang", "Saurashtra", "SignWriting", "Sundanese",
                "Moon", "Meetei_Mayek",
                /* new in ICU 4.0 */
                "Imperial_Aramaic", "Avestan", "Chakma", "Kore",
                "Kaithi", "Manichaean", "Inscriptional_Pahlavi", "Psalter_Pahlavi", "Phlv",
                "Inscriptional_Parthian", "Samaritan", "Tai_Viet",
                "Zmth", "Zsym",
                /* new in ICU 4.4 */
                "Bamum", "Lisu", "Nkgb", "Old_South_Arabian",
                /* new in ICU 4.6 */
                "Bassa_Vah", "Duployan", "Elbasan", "Grantha", "Kpel",
                "Loma", "Mende_Kikakui", "Meroitic_Cursive",
                "Old_North_Arabian", "Nabataean", "Palmyrene", "Khudawadi", "Warang_Citi",
                /* new in ICU 4.8 */
                "Afak", "Jurc", "Mro", "Nushu", "Sharada", "Sora_Sompeng", "Takri", "Tangut", "Wole",
                /* new in ICU 49 */
                "Anatolian_Hieroglyphs", "Khojki", "Tirhuta",
                /* new in ICU 52 */
                "Caucasian_Albanian", "Mahajani",
                /* new in ICU 54 */
                "Ahom", "Hatran", "Modi", "Multani", "Pau_Cin_Hau", "Siddham",
                // new in ICU 58
                "Adlam", "Bhaiksuki", "Marchen", "Newa", "Osage", "Hanb", "Jamo", "Zsye",
                // new in ICU 60
                "Masaram_Gondi", "Soyombo", "Zanabazar_Square"
            };
            String[] expectedShort = new String[] {
                "Bali", "Batk", "Blis", "Brah", "Cham", "Cirt", "Cyrs", "Egyd", "Egyh", "Egyp",
                "Geok", "Hans", "Hant", "Hmng", "Hung", "Inds", "Java", "Kali", "Latf", "Latg",
                "Lepc", "Lina", "Mand", "Maya", "Mero", "Nkoo", "Orkh", "Perm", "Phag", "Phnx",
                "Plrd", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vaii", "Visp", "Xsux",
                "Zxxx", "Zzzz",
                "Cari", "Jpan", "Lana", "Lyci", "Lydi", "Olck", "Rjng", "Saur", "Sgnw", "Sund",
                "Moon", "Mtei",
                /* new in ICU 4.0 */
                "Armi", "Avst", "Cakm", "Kore",
                "Kthi", "Mani", "Phli", "Phlp", "Phlv", "Prti", "Samr", "Tavt",
                "Zmth", "Zsym",
                /* new in ICU 4.4 */
                "Bamu", "Lisu", "Nkgb", "Sarb",
                /* new in ICU 4.6 */
                "Bass", "Dupl", "Elba", "Gran", "Kpel", "Loma", "Mend", "Merc",
                "Narb", "Nbat", "Palm", "Sind", "Wara",
                /* new in ICU 4.8 */
                "Afak", "Jurc", "Mroo", "Nshu", "Shrd", "Sora", "Takr", "Tang", "Wole",
                /* new in ICU 49 */
                "Hluw", "Khoj", "Tirh",
                /* new in ICU 52 */
                "Aghb", "Mahj",
                /* new in ICU 54 */
                "Ahom", "Hatr", "Modi", "Mult", "Pauc", "Sidd",
                // new in ICU 58
                "Adlm", "Bhks", "Marc", "Newa", "Osge", "Hanb", "Jamo", "Zsye",
                // new in ICU 60
                "Gonm", "Soyo", "Zanb"
            };
            if (expectedLong.Length != (UScript.CodeLimit - UScript.Balinese))
            {
                Errln("need to add new script codes in lang.TestUScript.java!");
                return;
            }
            int j = 0;
            int i = 0;

            for (i = UScript.Balinese; i < UScript.CodeLimit; i++, j++)
            {
                String name = UScript.GetName(i);
                if (name == null || !name.Equals(expectedLong[j]))
                {
                    Errln("UScript.getName failed for code" + i + name + "!=" + expectedLong[j]);
                }
                name = UScript.GetShortName(i);
                if (name == null || !name.Equals(expectedShort[j]))
                {
                    Errln("UScript.getShortName failed for code" + i + name + "!=" + expectedShort[j]);
                }
            }
            for (i = 0; i < expectedLong.Length; i++)
            {
                int[] ret = UScript.GetCode(expectedShort[i]);
                if (ret.Length > 1)
                {
                    Errln("UScript.getCode did not return expected number of codes for script" + expectedShort[i] + ". EXPECTED: 1 GOT: " + ret.Length);
                }
                if (ret[0] != (UScript.Balinese + i))
                {
                    Errln("UScript.getCode did not return expected code for script" + expectedShort[i] + ". EXPECTED: " + (UScript.Balinese + i) + " GOT: %i\n" + ret[0]);
                }
            }
        }