Exemple #1
0
        private void getFunctionalEquivalentTestCases(String path, Assembly cl, String resName, String keyword,
                                                      bool truncate, String[] testCases)
        {
            //String F_STR = "f";
            String T_STR = "t";

            bool[] isAvail = new bool[1];

            Logln("Testing functional equivalents...");
            for (int i = 0; i < testCases.Length; i += 3)
            {
                bool    expectAvail  = T_STR.Equals(testCases[i + 0]);
                ULocale inLocale     = new ULocale(testCases[i + 1]);
                ULocale expectLocale = new ULocale(testCases[i + 2]);

                Logln(((int)(i / 3)).ToString(CultureInfo.InvariantCulture) + ": " + expectAvail.ToString() + "\t\t" +
                      inLocale.ToString() + "\t\t" + expectLocale.ToString());

                ULocale equivLocale = ICUResourceBundle.GetFunctionalEquivalent(path, cl, resName, keyword, inLocale, isAvail, truncate);
                bool    gotAvail    = isAvail[0];

                if ((gotAvail != expectAvail) || !equivLocale.Equals(expectLocale))
                {
                    Errln(((int)(i / 3)).ToString(CultureInfo.InvariantCulture) + ":  Error, expected  Equiv=" + expectAvail.ToString() + "\t\t" +
                          inLocale.ToString() + "\t\t--> " + expectLocale.ToString() + ",  but got " + gotAvail.ToString() + " " +
                          equivLocale.ToString());
                }
            }
        }
        internal override Calendar CreateInstance(ULocale desiredLocale)
        {
            ULocale[] actualLoc = new ULocale[1];
            if (desiredLocale.Equals(IBM.ICU.Util.ULocale.ROOT))
            {
                desiredLocale = IBM.ICU.Util.ULocale.ROOT;
            }
            Calendar cal = (Calendar)service.Get(desiredLocale, actualLoc);

            if (cal == null)
            {
                throw new MissingManifestResourceException("Unable to construct Calendar");
            }
            cal = (Calendar)cal.Clone();

            /*
             * !!! TODO !!! actualLoc returned by service is not properly set. When
             * this Calendar object is being created, cal.setLocale is called and
             * proper actual locale is set at that time. Revisit this later.
             * -yoshito
             */
            /*
             * ULocale uloc = actualLoc[0]; cal.setLocale(uloc, uloc); // service
             * make no distinction between actual and valid
             */
            return(cal);
        }
Exemple #3
0
        public void TestGetFunctionalEquivalent()
        {
            var kw = Collator.Keywords;

            String[] DATA =
            {
                "sv",                          "sv",                    "t",
                "sv@collation=direct",         "sv",                    "t",
                "sv@collation=traditional",    "sv",                    "t",
                "sv@collation=gb2312han",      "sv",                    "t",
                "sv@collation=stroke",         "sv",                    "t",
                "sv@collation=pinyin",         "sv",                    "t",
                "sv@collation=standard",       "sv@collation=standard", "t",
                "sv@collation=reformed",       "sv",                    "t",
                "sv@collation=big5han",        "sv",                    "t",
                "sv_FI",                       "sv",                    "f",
                "sv_FI@collation=direct",      "sv",                    "f",
                "sv_FI@collation=traditional", "sv",                    "f",
                "sv_FI@collation=gb2312han",   "sv",                    "f",
                "sv_FI@collation=stroke",      "sv",                    "f",
                "sv_FI@collation=pinyin",      "sv",                    "f",
                "sv_FI@collation=standard",    "sv@collation=standard", "f",
                "sv_FI@collation=reformed",    "sv",                    "f",
                "sv_FI@collation=big5han",     "sv",                    "f",
                "nl",                          "root",                  "t",
                "nl@collation=direct",         "root",                  "t",
                "nl_BE",                       "root",                  "f",
                "nl_BE@collation=direct",      "root",                  "f",
                "nl_BE@collation=traditional", "root",                  "f",
                "nl_BE@collation=gb2312han",   "root",                  "f",
                "nl_BE@collation=stroke",      "root",                  "f",
                "nl_BE@collation=pinyin",      "root",                  "f",
                "nl_BE@collation=big5han",     "root",                  "f",
                "nl_BE@collation=phonebook",   "root",                  "f",
                "en_US_VALLEYGIRL",            "root",                  "f"
            };
            int DATA_COUNT = (DATA.Length / 3);

            for (int i = 0; i < DATA_COUNT; i++)
            {
                bool[]  isAvailable     = new bool[1];
                ULocale input           = new ULocale(DATA[(i * 3) + 0]);
                ULocale expect          = new ULocale(DATA[(i * 3) + 1]);
                bool    expectAvailable = DATA[(i * 3) + 2].Equals("t");
                ULocale actual          = Collator.GetFunctionalEquivalent(kw[0], input, isAvailable);
                if (!actual.Equals(expect) || (expectAvailable != isAvailable[0]))
                {
                    Errln("#" + i + ": Collator.getFunctionalEquivalent(" + input + ")=" + actual + ", avail " + isAvailable[0] + ", " +
                          "expected " + expect + " avail " + expectAvailable);
                }
                else
                {
                    Logln("#" + i + ": Collator.getFunctionalEquivalent(" + input + ")=" + actual + ", avail " + isAvailable[0]);
                }
            }
        }
        public void TestDateFormat()
        {
            ULocale defLoc = IBM.ICU.Util.ULocale.GetDefault();

            IBM.ICU.Util.ULocale.SetDefault(_DEFAULT_LOCALE);
            for (int i = 0; i < _LOCALE_NUMBER; i++)
            {
                ULocale oldLoc = _LOCALES[i][0];
                ULocale newLoc = _LOCALES[i][1];
                if (ILOG.J2CsMapping.Collections.Collections.Get(availableMap, _LOCALES[i][1]) == null)
                {
                    Logln(_LOCALES[i][1] + " is not available. Skipping!");
                    continue;
                }
                DateFormat df1 = IBM.ICU.Text.DateFormat
                                 .GetDateInstance(IBM.ICU.Text.DateFormat.FULL, oldLoc);
                DateFormat df2 = IBM.ICU.Text.DateFormat
                                 .GetDateInstance(IBM.ICU.Text.DateFormat.FULL, newLoc);

                // Test function "getLocale"
                ULocale l1 = df1.GetLocale(IBM.ICU.Util.ULocale.VALID_LOCALE);
                ULocale l2 = df2.GetLocale(IBM.ICU.Util.ULocale.VALID_LOCALE);
                if (!newLoc.Equals(l1))
                {
                    Errln("DateFormatTest: newLoc!=l1: newLoc= " + newLoc + " l1= "
                          + l1);
                }
                if (!l1.Equals(l2))
                {
                    Errln("DateFormatTest: l1!=l2: l1= " + l1 + " l2= " + l2);
                }
                if (!df1.Equals(df2))
                {
                    Errln("DateFormatTest: df1!=df2: newLoc= " + newLoc
                          + " oldLoc= " + oldLoc);
                }
                this.Logln("DateFormat(getLocale) old:" + l1 + "   new:" + l2);

                // Test function "format"
                // Date d = new Date();
                // String d1 = df1.format(d);
                // String d2 = df2.format(d);
                // if (!d1.equals(d2)) {
                // pass = false;
                // }
                // this.logln("DateFormat(format) old:"+d1+"   new:"+d2);
            }
            IBM.ICU.Util.ULocale.SetDefault(defLoc);
        }
 // /CLOVER:OFF
 public override bool Equals(Object other)
 {
     if ((Object)this == other)
     {
         return(true);
     }
     try {
         UResourceBundle.ResourceCacheKey otherEntry = (UResourceBundle.ResourceCacheKey)other;
         // quick check to see if they are not equal
         if (hashCodeCache != otherEntry.hashCodeCache)
         {
             return(false);
         }
         // are the names the same?
         if (!searchName.Equals(otherEntry.searchName))
         {
             return(false);
         }
         // are the default locales the same?
         if (defaultLocale == null)
         {
             if (otherEntry.defaultLocale != null)
             {
                 return(false);
             }
         }
         else
         {
             if (!defaultLocale.Equals(otherEntry.defaultLocale))
             {
                 return(false);
             }
         }
         // are refs (both non-null) or (both null)?
         if (loaderRef == null)
         {
             return(otherEntry.loaderRef == null);
         }
         else
         {
             return((otherEntry.loaderRef != null) &&
                    (loaderRef.Target == otherEntry.loaderRef.Target));
         }
     } catch (NullReferenceException e) {
         return(false);
     } catch (InvalidCastException e_0) {
         return(false);
     }
 }
Exemple #6
0
 public LocaleDisplayNames Get(ULocale locale, DialectHandling dialectHandling)
 {
     if (!(dialectHandling == this.dialectHandling && DisplayContext.CapitalizationNone == this.capitalization &&
           DisplayContext.LengthFull == this.nameLength && DisplayContext.Substitute == this.substituteHandling &&
           locale.Equals(this.locale)))
     {
         this.locale             = locale;
         this.dialectHandling    = dialectHandling;
         this.capitalization     = DisplayContext.CapitalizationNone;
         this.nameLength         = DisplayContext.LengthFull;
         this.substituteHandling = DisplayContext.Substitute;
         this.cache = new LocaleDisplayNamesImpl(locale, dialectHandling);
     }
     return(cache);
 }
 public LocaleDisplayNames Get(ULocale locale, DialectHandling dialectHandling)
 {
     syncLock.EnterUpgradeableReadLock();
     try
     {
         if (!(dialectHandling == this.dialectHandling && DisplayContext.CapitalizationNone == this.capitalization &&
               DisplayContext.LengthFull == this.nameLength && DisplayContext.Substitute == this.substituteHandling &&
               locale.Equals(this.locale)))
         {
             syncLock.EnterWriteLock();
             try
             {
                 if (!(dialectHandling == this.dialectHandling && DisplayContext.CapitalizationNone == this.capitalization &&
                       DisplayContext.LengthFull == this.nameLength && DisplayContext.Substitute == this.substituteHandling &&
                       locale.Equals(this.locale)))
                 {
                     this.locale             = locale;
                     this.dialectHandling    = dialectHandling;
                     this.capitalization     = DisplayContext.CapitalizationNone;
                     this.nameLength         = DisplayContext.LengthFull;
                     this.substituteHandling = DisplayContext.Substitute;
                     this.cache = new LocaleDisplayNamesImpl(locale, dialectHandling);
                 }
             }
             finally
             {
                 syncLock.ExitWriteLock();
             }
         }
         return(cache);
     }
     finally
     {
         syncLock.ExitUpgradeableReadLock();
     }
 }
        public void TestCalendar()
        {
            ULocale defLoc = IBM.ICU.Util.ULocale.GetDefault();

            IBM.ICU.Util.ULocale.SetDefault(_DEFAULT_LOCALE);
            for (int i = 0; i < _LOCALE_NUMBER; i++)
            {
                ULocale oldLoc = _LOCALES[i][0];
                ULocale newLoc = _LOCALES[i][1];
                if (ILOG.J2CsMapping.Collections.Collections.Get(availableMap, _LOCALES[i][1]) == null)
                {
                    Logln(_LOCALES[i][1] + " is not available. Skipping!");
                    continue;
                }
                Calendar c1 = IBM.ICU.Util.Calendar.GetInstance(oldLoc);
                Calendar c2 = IBM.ICU.Util.Calendar.GetInstance(newLoc);
                c1.SetTime(c2.GetTime());
                // Test function "getFirstDayOfWeek"
                // int firstDayOfWeek1 = c1.getFirstDayOfWeek();
                // int firstDayOfWeek2 = c2.getFirstDayOfWeek();
                // if (firstDayOfWeek1 != firstDayOfWeek2) {
                // this.logln("Calendar(getFirstDayOfWeek) old:"
                // +firstDayOfWeek1+"   new:"+firstDayOfWeek2);
                // pass = false;
                // }

                // Test function "getLocale(ULocale.VALID_LOCALE)"
                ULocale l1 = c1.GetLocale(IBM.ICU.Util.ULocale.VALID_LOCALE);
                ULocale l2 = c2.GetLocale(IBM.ICU.Util.ULocale.VALID_LOCALE);
                if (!newLoc.Equals(l1))
                {
                    Errln("CalendarTest: newLoc!=l1: newLoc= " + newLoc + " l1= "
                          + l1);
                }
                if (!l1.Equals(l2))
                {
                    Errln("CalendarTest: l1!=l2: l1= " + l1 + " l2= " + l2);
                }
                if (!c1.Equals(c2))
                {
                    Errln("CalendarTest: c1!=c2.  newLoc= " + newLoc + " oldLoc= "
                          + oldLoc);
                }
                Logln("Calendar(getLocale) old:" + l1 + "   new:" + l2);
            }
            IBM.ICU.Util.ULocale.SetDefault(defLoc);
        }
Exemple #9
0
            public LocaleDisplayNames Get(ULocale locale, params DisplayContext[] contexts)
            {
                DialectHandling dialectHandlingIn  = DialectHandling.STANDARD_NAMES;
                DisplayContext  capitalizationIn   = DisplayContext.CapitalizationNone;
                DisplayContext  nameLengthIn       = DisplayContext.LengthFull;
                DisplayContext  substituteHandling = DisplayContext.Substitute;

                foreach (DisplayContext contextItem in contexts)
                {
                    switch (contextItem.Type())
                    {
                    case DisplayContextType.DialectHandling:
                        dialectHandlingIn = (contextItem.Value() == DisplayContext.StandardNames.Value()) ?
                                            DialectHandling.STANDARD_NAMES : DialectHandling.DIALECT_NAMES;
                        break;

                    case DisplayContextType.Capitalization:
                        capitalizationIn = contextItem;
                        break;

                    case DisplayContextType.DisplayLength:
                        nameLengthIn = contextItem;
                        break;

                    case DisplayContextType.SubstituteHandling:
                        substituteHandling = contextItem;
                        break;

                    default:
                        break;
                    }
                }
                if (!(dialectHandlingIn == this.dialectHandling && capitalizationIn == this.capitalization &&
                      nameLengthIn == this.nameLength && substituteHandling == this.substituteHandling &&
                      locale.Equals(this.locale)))
                {
                    this.locale             = locale;
                    this.dialectHandling    = dialectHandlingIn;
                    this.capitalization     = capitalizationIn;
                    this.nameLength         = nameLengthIn;
                    this.substituteHandling = substituteHandling;
                    this.cache = new LocaleDisplayNamesImpl(locale, contexts);
                }
                return(cache);
            }
Exemple #10
0
        // private static final String INVALID_NAME = "Invalid";
        /// <summary>
        /// Helper function to find the code from locale.
        /// </summary>
        ///
        /// <param name="locale">The locale.</param>
        private static int[] FindCodeFromLocale(ULocale locale)
        {
            ICUResourceBundle rb;

            try {
                rb = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle.GetBundleInstance(
                    IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale);
            } catch (MissingManifestResourceException e) {
                return(null);
            }

            // if rb is not a strict fallback of the requested locale, return null
            // if(!LocaleUtility.isFallbackOf(rb.getULocale().toString(),
            // locale.toString())){
            // return null;
            // }
            // non existent locale check
            if (rb.GetLoadingStatus() == IBM.ICU.Impl.ICUResourceBundle.FROM_DEFAULT &&
                !locale.Equals(IBM.ICU.Util.ULocale.GetDefault()))
            {
                return(null);
            }
            UResourceBundle sub = rb.Get(kLocaleScript);

            int[] result = new int[sub.GetSize()];
            int   w      = 0;

            for (int i = 0; i < result.Length; ++i)
            {
                int code = IBM.ICU.Lang.UCharacter.GetPropertyValueEnum(IBM.ICU.Lang.UProperty_Constants.SCRIPT,
                                                                        sub.GetString(i));
                result[w++] = code;
            }

            if (w < result.Length)
            {
                throw new InvalidOperationException("bad locale data, listed "
                                                    + result.Length + " scripts but found only " + w);
            }

            return(result);
        }
        public void TestUResourceBundle()
        {
            ULocale defLoc = IBM.ICU.Util.ULocale.GetDefault();

            IBM.ICU.Util.ULocale.SetDefault(_DEFAULT_LOCALE);
            for (int i = 0; i < _LOCALE_NUMBER; i++)
            {
                if (ILOG.J2CsMapping.Collections.Collections.Get(availableMap, _LOCALES[i][1]) == null)
                {
                    Logln(_LOCALES[i][1] + " is not available. Skipping!");
                    continue;
                }
                ULocale         oldLoc = _LOCALES[i][0];
                ULocale         newLoc = _LOCALES[i][1];
                UResourceBundle urb1   = null;
                UResourceBundle urb2   = null;

                urb1 = IBM.ICU.Util.UResourceBundle.GetBundleInstance(
                    IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, oldLoc);
                urb2 = IBM.ICU.Util.UResourceBundle.GetBundleInstance(
                    IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, newLoc);
                ULocale l1 = urb1.GetULocale();
                ULocale l2 = urb2.GetULocale();
                if (!newLoc.Equals(l1))
                {
                    Errln("ResourceBundleTest: newLoc!=l1: newLoc= " + newLoc
                          + " l1= " + l1);
                }
                if (!l1.Equals(l2))
                {
                    Errln("ResourceBundleTest: l1!=l2: l1= " + l1 + " l2= " + l2);
                }
                this.Logln("UResourceBundle old:" + l1 + "   new:" + l2);
            }
            IBM.ICU.Util.ULocale.SetDefault(defLoc);
        }
Exemple #12
0
        public static CollationTailoring LoadTailoring(ULocale locale, out ULocale outValidLocale)
        {
            // Java porting note: ICU4J getWithFallback/getStringWithFallback currently does not
            // work well when alias table is involved in a resource path, unless full path is specified.
            // For now, collation resources does not contain such data, so the code below should work fine.

            CollationTailoring root       = CollationRoot.Root;
            string             localeName = locale.GetName();

            if (localeName.Length == 0 || localeName.Equals("root"))
            {
                outValidLocale = ULocale.ROOT;
                return(root);
            }

            UResourceBundle bundle = null;

            try
            {
                bundle = ICUResourceBundle.GetBundleInstance(
                    ICUData.ICU_COLLATION_BASE_NAME, locale,
                    // ICU4N specific - need to pass in this assembly
                    // name for the resources to be resolved here.
                    CollationData.ICU_DATA_CLASS_LOADER,
                    ICUResourceBundle.OpenType.LOCALE_ROOT);
            }
            catch (MissingManifestResourceException e)
            {
                outValidLocale = ULocale.ROOT;
                return(root);
            }

            ULocale validLocale = bundle.GetULocale();
            // Normalize the root locale. See
            // http://bugs.icu-project.org/trac/ticket/10715
            string validLocaleName = validLocale.GetName();

            if (validLocaleName.Length == 0 || validLocaleName.Equals("root"))
            {
                validLocale = ULocale.ROOT;
            }
            outValidLocale = validLocale;

            // There are zero or more tailorings in the collations table.
            UResourceBundle collations;

            try
            {
                collations = bundle.Get("collations");
                if (collations == null)
                {
                    return(root);
                }
            }
            catch (MissingManifestResourceException ignored)
            {
                return(root);
            }

            // Fetch the collation type from the locale ID and the default type from the data.
            string type        = locale.GetKeywordValue("collation");
            string defaultType = "standard";

            string defT = ((ICUResourceBundle)collations).FindStringWithFallback("default");

            if (defT != null)
            {
                defaultType = defT;
            }

            if (type == null || type.Equals("default"))
            {
                type = defaultType;
            }
            else
            {
                type = ASCII.ToLower(type);
            }

            // Load the collations/type tailoring, with type fallback.

            // Java porting note: typeFallback is used for setting U_USING_DEFAULT_WARNING in
            // ICU4C, but not used by ICU4J

            // boolean typeFallback = false;
            UResourceBundle data = FindWithFallback(collations, type);

            if (data == null &&
                type.Length > 6 && type.StartsWith("search", StringComparison.Ordinal))
            {
                // fall back from something like "searchjl" to "search"
                // typeFallback = true;
                type = "search";
                data = FindWithFallback(collations, type);
            }

            if (data == null && !type.Equals(defaultType))
            {
                // fall back to the default type
                // typeFallback = true;
                type = defaultType;
                data = FindWithFallback(collations, type);
            }

            if (data == null && !type.Equals("standard"))
            {
                // fall back to the "standard" type
                // typeFallback = true;
                type = "standard";
                data = FindWithFallback(collations, type);
            }

            if (data == null)
            {
                return(root);
            }

            // Is this the same as the root collator? If so, then use that instead.
            ULocale actualLocale = data.GetULocale();
            // http://bugs.icu-project.org/trac/ticket/10715 ICUResourceBundle(root).getULocale() != ULocale.ROOT
            // Therefore not just if (actualLocale.equals(ULocale.ROOT) && type.equals("standard")) {
            string actualLocaleName = actualLocale.GetName();

            if (actualLocaleName.Length == 0 || actualLocaleName.Equals("root"))
            {
                actualLocale = ULocale.ROOT;
                if (type.Equals("standard"))
                {
                    return(root);
                }
            }

            CollationTailoring t = new CollationTailoring(root.Settings);

            t.ActualLocale = actualLocale;

            // deserialize
            UResourceBundle binary  = data.Get("%%CollationBin");
            ByteBuffer      inBytes = binary.GetBinary();

            try
            {
                CollationDataReader.Read(root, inBytes, t);
            }
            catch (IOException e)
            {
                throw new ICUUncheckedIOException("Failed to load collation tailoring data for locale:"
                                                  + actualLocale + " type:" + type, e);
            }

            // Try to fetch the optional rules string.
            try
            {
                t.SetRulesResource(data.Get("Sequence"));
            }
            catch (MissingManifestResourceException ignored)
            {
            }

            // Set the collation types on the informational locales,
            // except when they match the default types (for brevity and backwards compatibility).
            // For the valid locale, suppress the default type.
            if (!type.Equals(defaultType))
            {
                outValidLocale = validLocale.SetKeywordValue("collation", type);
            }

            // For the actual locale, suppress the default type *according to the actual locale*.
            // For example, zh has default=pinyin and contains all of the Chinese tailorings.
            // zh_Hant has default=stroke but has no other data.
            // For the valid locale "zh_Hant" we need to suppress stroke.
            // For the actual locale "zh" we need to suppress pinyin instead.
            if (!actualLocale.Equals(validLocale))
            {
                // Opening a bundle for the actual locale should always succeed.
                UResourceBundle actualBundle = UResourceBundle.GetBundleInstance(
                    ICUData.ICU_COLLATION_BASE_NAME, actualLocale);
                defT = ((ICUResourceBundle)actualBundle).FindStringWithFallback("collations/default");
                if (defT != null)
                {
                    defaultType = defT;
                }
            }

            if (!type.Equals(defaultType))
            {
                t.ActualLocale = t.ActualLocale.SetKeywordValue("collation", type);
            }

            // if (typeFallback) {
            //     ICU4C implementation sets U_USING_DEFAULT_WARNING here
            // }

            return(t);
        }
Exemple #13
0
        private static BreakIterator CreateBreakInstance(ULocale locale, int kind)
        {
            BreakIterator     iter = null;
            ICUResourceBundle rb   = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                     .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BRKITR_BASE_NAME,
                                                        locale);

            //
            // Get the binary rules. These are needed for both normal
            // RulesBasedBreakIterators
            // and for Dictionary iterators.
            //
            Stream ruleStream = null;

            try {
                String typeKey       = KIND_NAMES[kind];
                String brkfname      = rb.GetStringWithFallback("boundaries/" + typeKey);
                String rulesFileName = IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME /*+
                                                                                     * IBM.ICU.Impl.ICUResourceBundle.ICU_BUNDLE*/
                                       + IBM.ICU.Impl.ICUResourceBundle.ICU_BRKITR_NAME + "/" + brkfname;
                ruleStream = IBM.ICU.Impl.ICUData.GetStream(rulesFileName);
            } catch (Exception e) {
                throw new MissingManifestResourceException(e.ToString());
            }

            //
            // Check whether a dictionary exists, and create a DBBI iterator is
            // one does.
            //
            if (DICTIONARY_POSSIBLE[kind])
            {
                // This type of break iterator could potentially use a dictionary.
                //
                try {
                    // ICUResourceBundle dictRes =
                    // (ICUResourceBundle)rb.getObject("BreakDictionaryData");
                    // byte[] dictBytes = null;
                    // dictBytes = dictRes.getBinary(dictBytes);
                    // TODO: Hard code this for now! fix it once
                    // CompactTrieDictionary is ported
                    if (locale.Equals("th"))
                    {
                        String fileName = "data/th.brk";
                        Stream mask0    = IBM.ICU.Impl.ICUData.GetStream(fileName);
                        iter = new DictionaryBasedBreakIterator(ruleStream, mask0);
                    }
                } catch (MissingManifestResourceException e_0) {
                    // Couldn't find a dictionary.
                    // This is normal, and will occur whenever creating a word or
                    // line
                    // break iterator for a locale that does not have a
                    // BreakDictionaryData
                    // resource - meaning for all but Thai.
                    // Fall through to creating a normal RulebasedBreakIterator.
                } catch (IOException e_1) {
                    IBM.ICU.Impl.Assert.Fail(e_1);
                }
            }

            if (iter == null)
            {
                //
                // Create a normal RuleBasedBreakIterator.
                // We have determined that this is not supposed to be a dictionary
                // iterator.
                //
                try {
                    iter = IBM.ICU.Text.RuleBasedBreakIterator
                           .GetInstanceFromCompiledRules(ruleStream);
                } catch (IOException e_2) {
                    // Shouldn't be possible to get here.
                    // If it happens, the compiled rules are probably corrupted in
                    // some way.
                    IBM.ICU.Impl.Assert.Fail(e_2);
                }
            }
            // TODO: Determine valid and actual locale correctly.
            ULocale uloc = IBM.ICU.Util.ULocale.ForLocale(rb.GetLocale());

            iter.SetLocale(uloc, uloc);

            return(iter);
        }
            public LocaleDisplayNames Get(ULocale locale, params DisplayContext[] contexts)
            {
                DialectHandling dialectHandlingIn  = DialectHandling.StandardNames;
                DisplayContext  capitalizationIn   = DisplayContext.CapitalizationNone;
                DisplayContext  nameLengthIn       = DisplayContext.LengthFull;
                DisplayContext  substituteHandling = DisplayContext.Substitute;

                foreach (DisplayContext contextItem in contexts)
                {
                    switch (contextItem.Type())
                    {
                    case DisplayContextType.DialectHandling:
                        dialectHandlingIn = (contextItem.Value() == DisplayContext.StandardNames.Value()) ?
                                            DialectHandling.StandardNames : DialectHandling.DialectNames;
                        break;

                    case DisplayContextType.Capitalization:
                        capitalizationIn = contextItem;
                        break;

                    case DisplayContextType.DisplayLength:
                        nameLengthIn = contextItem;
                        break;

                    case DisplayContextType.SubstituteHandling:
                        substituteHandling = contextItem;
                        break;

                    default:
                        break;
                    }
                }
                syncLock.EnterUpgradeableReadLock();
                try
                {
                    if (!(dialectHandlingIn == this.dialectHandling && capitalizationIn == this.capitalization &&
                          nameLengthIn == this.nameLength && substituteHandling == this.substituteHandling &&
                          locale.Equals(this.locale)))
                    {
                        syncLock.EnterWriteLock();
                        try
                        {
                            if (!(dialectHandlingIn == this.dialectHandling && capitalizationIn == this.capitalization &&
                                  nameLengthIn == this.nameLength && substituteHandling == this.substituteHandling &&
                                  locale.Equals(this.locale)))
                            {
                                this.locale             = locale;
                                this.dialectHandling    = dialectHandlingIn;
                                this.capitalization     = capitalizationIn;
                                this.nameLength         = nameLengthIn;
                                this.substituteHandling = substituteHandling;
                                this.cache = new LocaleDisplayNamesImpl(locale, contexts);
                            }
                        }
                        finally
                        {
                            syncLock.ExitWriteLock();
                        }
                    }
                    return(cache);
                }
                finally
                {
                    syncLock.ExitUpgradeableReadLock();
                }
            }