Пример #1
0
        internal String GetZoneString(ULocale locale, String olsonID, int item)
        {
            IDictionary data = (IDictionary)ILOG.J2CsMapping.Collections.Collections.Get(zoneData, locale);

            if (data == null)
            {
                data = new Hashtable();
                if (SHOW_ALL)
                {
                    System.Console.Out.WriteLine();
                }
                if (SHOW_ALL)
                {
                    System.Console.Out.WriteLine("zones for " + locale);
                }
                ICUResourceBundle bundle = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                           .GetBundleInstance(locale);
                ICUResourceBundle table = bundle.GetWithFallback("zoneStrings");
                for (int i = 0; i < table.GetSize(); ++i)
                {
                    UResourceBundle stringSet = table.Get(i);
                    // ICUResourceBundle stringSet =
                    // table.getWithFallback(String.valueOf(i));
                    String key = stringSet.GetString(0);
                    if (SHOW_ALL)
                    {
                        System.Console.Out.WriteLine("key: " + key);
                    }
                    ArrayList list = new ArrayList();
                    for (int j = 1; j < stringSet.GetSize(); ++j)
                    {
                        String entry = stringSet.GetString(j);
                        if (SHOW_ALL)
                        {
                            System.Console.Out.WriteLine("  entry: " + entry);
                        }
                        ILOG.J2CsMapping.Collections.Generics.Collections.Add(list, entry);
                    }
                    ILOG.J2CsMapping.Collections.Collections.Put(data, key, ILOG.J2CsMapping.Collections.Generics.Collections.ToArray(list, new String[list.Count]));
                }
                ILOG.J2CsMapping.Collections.Collections.Put(zoneData, locale, data);
            }
            String[] strings = (String[])ILOG.J2CsMapping.Collections.Collections.Get(data, olsonID);
            if (strings == null || item >= strings.Length)
            {
                return(olsonID);
            }
            return(strings[item]);
        }
Пример #2
0
        private static NumberingSystem LookupInstanceByName(string name)
        {
            int    radix;
            bool   isAlgorithmic;
            string description;

            try
            {
                UResourceBundle numberingSystemsInfo = UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, "numberingSystems");
                UResourceBundle nsCurrent            = numberingSystemsInfo.Get("numberingSystems");
                UResourceBundle nsTop = nsCurrent.Get(name);

                description = nsTop.GetString("desc");
                UResourceBundle nsRadixBundle = nsTop.Get("radix");
                UResourceBundle nsAlgBundle   = nsTop.Get("algorithmic");
                radix = nsRadixBundle.GetInt32();
                int algorithmic = nsAlgBundle.GetInt32();

                isAlgorithmic = (algorithmic == 1);
            }
            catch (MissingManifestResourceException)
            {
                return(null);
            }

            return(GetInstance(name, radix, isAlgorithmic, description));
        }
Пример #3
0
        /// <summary>
        /// Gets the rule from the rulesId. If there is no rule for this rulesId,
        /// return null.
        /// </summary>
        public virtual PluralRules GetRulesForRulesId(string rulesId)
        {
            // synchronize on the map.  release the lock temporarily while we build the rules.
            PluralRules rules = null;
            bool        hasRules; // Separate boolean because stored rules can be null.

            lock (rulesIdToRulesLock)
            {
                hasRules = rulesIdToRules.ContainsKey(rulesId);
                if (hasRules)
                {
                    rulesIdToRules.TryGetValue(rulesId, out rules);  // can be null
                }
            }
            if (!hasRules)
            {
                try
                {
                    UResourceBundle pluralb = GetPluralBundle();
                    UResourceBundle rulesb  = pluralb.Get("rules");
                    UResourceBundle setb    = rulesb.Get(rulesId);

                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < setb.Length; ++i)
                    {
                        UResourceBundle b = setb.Get(i);
                        if (i > 0)
                        {
                            sb.Append("; ");
                        }
                        sb.Append(b.Key);
                        sb.Append(": ");
                        sb.Append(b.GetString());
                    }
                    rules = PluralRules.ParseDescription(sb.ToString());
                }
                catch (FormatException)
                {
                }
                catch (MissingManifestResourceException)
                {
                }
                lock (rulesIdToRulesLock)
                {
                    if (rulesIdToRules.ContainsKey(rulesId))
                    {
                        rulesIdToRules.TryGetValue(rulesId, out rules);
                    }
                    else
                    {
                        rulesIdToRules[rulesId] = rules;  // can be null
                    }
                }
            }
            return(rules);
        }
Пример #4
0
        internal static string LoadRules(ULocale locale, string collationType)
        {
            UResourceBundle bundle = UResourceBundle.GetBundleInstance(
                ICUData.ICU_COLLATION_BASE_NAME, locale);
            UResourceBundle data = ((ICUResourceBundle)bundle).GetWithFallback(
                "collations/" + ASCII.ToLower(collationType));
            string rules = data.GetString("Sequence");

            return(rules);
        }
Пример #5
0
        internal static string LoadRules(UCultureInfo locale, string collationType)
        {
            UResourceBundle bundle = UResourceBundle.GetBundleInstance(
                // ICU4N specific - passing in the current assembly to load resources from.
                ICUData.IcuCollationBaseName, locale, ICUResourceBundle.IcuDataAssembly);
            UResourceBundle data = ((ICUResourceBundle)bundle).GetWithFallback(
                "collations/" + ASCII.ToLower(collationType));
            string rules = data.GetString("Sequence");

            return(rules);
        }
Пример #6
0
            public virtual String GetString(String key)
            {
                String t;

                try {
                    t = res.GetString(key);
                } catch (MissingManifestResourceException e) {
                    t = null;
                }
                return(t);
            }
Пример #7
0
        private static string rootRules = null; // ICU4N specific - made non-volatile and used LazyInitializer

        private static void LoadRootRules()
        {
            if (rootRules != null)
            {
                return;
            }
            LazyInitializer.EnsureInitialized(ref rootRules, () =>
            {
                UResourceBundle rootBundle = UResourceBundle.GetBundleInstance(
                    // ICU4N specific - passing in the current assembly to load resources from.
                    ICUData.IcuCollationBaseName, UCultureInfo.InvariantCulture, ICUResourceBundle.IcuDataAssembly);
                return(rootBundle.GetString("UCARules"));
            });
        }
Пример #8
0
 private static void LoadRootRules()
 {
     if (rootRules != null)
     {
         return;
     }
     lock (typeof(CollationLoader))
     {
         if (rootRules == null)
         {
             UResourceBundle rootBundle = UResourceBundle.GetBundleInstance(
                 // ICU4N specific - passing in the current assembly to load resources from.
                 ICUData.ICU_COLLATION_BASE_NAME, ULocale.ROOT, CollationData.ICU_DATA_CLASS_LOADER);
             rootRules = rootBundle.GetString("UCARules");
         }
     }
 }
Пример #9
0
 private static void LoadRootRules()
 {
     if (rootRules != null)
     {
         return;
     }
     lock (typeof(CollationLoader))
     {
         if (rootRules == null)
         {
             UResourceBundle rootBundle = UResourceBundle.GetBundleInstance(
                 // ICU4N specific - passing in the current assembly to load resources from.
                 ICUData.IcuCollationBaseName, ULocale.ROOT, CollationData.IcuDataAssembly);
             rootRules = rootBundle.GetString("UCARules");
         }
     }
 }
Пример #10
0
        private void LoadDates()
        {
            CalendarData    calData = new CalendarData(fLocale, calendar.GetType());
            UResourceBundle rb      = calData.Get("fields", "day", "relative");

            ILOG.J2CsMapping.Collections.ISet datesSet = new SortedSet(new RelativeDateFormat.Anonymous_C0());

            for (UResourceBundleIterator i = rb.GetIterator(); i.HasNext();)
            {
                UResourceBundle line = i.Next();

                String k = line.GetKey();
                String v = line.GetString();
                RelativeDateFormat.URelativeString rs = new RelativeDateFormat.URelativeString(k, v);
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(datesSet, rs);
            }
            fDates = new RelativeDateFormat.URelativeString [0];
            fDates = (RelativeDateFormat.URelativeString [])ILOG.J2CsMapping.Collections.Generics.Collections.ToArray(datesSet, fDates);
        }
Пример #11
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);
        }
Пример #12
0
        static internal String[] GetStringArrayHelper(UResourceBundle res_0)
        {
            try {
                int type = res_0.GetType();
                switch (type)
                {
                case IBM.ICU.Util.UResourceBundle.ARRAY:
                    return(res_0.GetStringArray());

                case IBM.ICU.Util.UResourceBundle.STRING:
                    return(new String[] { res_0.GetString() });

                default:
                    throw new UResourceTypeMismatchException(
                              "Only accept ARRAY and STRING types.");
                }
            } catch (UResourceTypeMismatchException e) {
                // #if defined(FOUNDATION10) || defined(J2SE13)
                // ## throw new DataModuleFormatError(e.getMessage());
                // #else
                throw new TestDataModule_Constants.DataModuleFormatError(e);
                // #endif
            }
        }
Пример #13
0
        private static void InitFromResourceBundle()
        {
            UResourceBundle keyTypeDataRes = UResourceBundle.GetBundleInstance(
                ICUData.ICU_BASE_NAME,
                "keyTypeData",
                ICUResourceBundle.ICU_DATA_CLASS_LOADER);

            GetKeyInfo(keyTypeDataRes.Get("keyInfo"));
            GetTypeInfo(keyTypeDataRes.Get("typeInfo"));

            UResourceBundle keyMapRes  = keyTypeDataRes.Get("keyMap");
            UResourceBundle typeMapRes = keyTypeDataRes.Get("typeMap");

            // alias data is optional
            UResourceBundle typeAliasRes    = null;
            UResourceBundle bcpTypeAliasRes = null;

            try
            {
                typeAliasRes = keyTypeDataRes.Get("typeAlias");
            }
            catch (MissingManifestResourceException e)
            {
                // fall through
            }

            try
            {
                bcpTypeAliasRes = keyTypeDataRes.Get("bcpTypeAlias");
            }
            catch (MissingManifestResourceException e)
            {
                // fall through
            }

            // iterate through keyMap resource
            using (UResourceBundleEnumerator keyMapItr = keyMapRes.GetEnumerator())
            {
                IDictionary <string, IList <string> > _Bcp47Keys = new Dictionary <string, IList <string> >(); // ICU4N NOTE: As long as we don't delete, Dictionary keeps insertion order the same as LinkedHashMap

                while (keyMapItr.MoveNext())
                {
                    UResourceBundle keyMapEntry = keyMapItr.Current;
                    string          legacyKeyId = keyMapEntry.Key;
                    string          bcpKeyId    = keyMapEntry.GetString();

                    bool hasSameKey = false;
                    if (bcpKeyId.Length == 0)
                    {
                        // Empty value indicates that BCP key is same with the legacy key.
                        bcpKeyId   = legacyKeyId;
                        hasSameKey = true;
                    }
                    IList <string> _bcp47Types = new List <string>(); // ICU4N: Mimic LinkedHashSet with List by ensuring no duplicates are added
                    _Bcp47Keys[bcpKeyId] = _bcp47Types.ToUnmodifiableList();

                    bool isTZ = legacyKeyId.Equals("timezone");

                    // reverse type alias map
                    IDictionary <string, ISet <string> > typeAliasMap = null;
                    if (typeAliasRes != null)
                    {
                        UResourceBundle typeAliasResByKey = null;
                        try
                        {
                            typeAliasResByKey = typeAliasRes.Get(legacyKeyId);
                        }
                        catch (MissingManifestResourceException e)
                        {
                            // fall through
                        }
                        if (typeAliasResByKey != null)
                        {
                            typeAliasMap = new Dictionary <string, ISet <string> >();
                            using (UResourceBundleEnumerator typeAliasResItr = typeAliasResByKey.GetEnumerator())
                            {
                                while (typeAliasResItr.MoveNext())
                                {
                                    UResourceBundle typeAliasDataEntry = typeAliasResItr.Current;
                                    string          from = typeAliasDataEntry.Key;
                                    string          to   = typeAliasDataEntry.GetString();
                                    if (isTZ)
                                    {
                                        from = from.Replace(':', '/');
                                    }
                                    ISet <string> aliasSet = typeAliasMap.Get(to);
                                    if (aliasSet == null)
                                    {
                                        aliasSet         = new HashSet <string>();
                                        typeAliasMap[to] = aliasSet;
                                    }
                                    aliasSet.Add(from);
                                }
                            }
                        }
                    }

                    // reverse bcp type alias map
                    IDictionary <string, ISet <string> > bcpTypeAliasMap = null;
                    if (bcpTypeAliasRes != null)
                    {
                        UResourceBundle bcpTypeAliasResByKey = null;
                        try
                        {
                            bcpTypeAliasResByKey = bcpTypeAliasRes.Get(bcpKeyId);
                        }
                        catch (MissingManifestResourceException e)
                        {
                            // fall through
                        }
                        if (bcpTypeAliasResByKey != null)
                        {
                            bcpTypeAliasMap = new Dictionary <string, ISet <string> >();
                            using (UResourceBundleEnumerator bcpTypeAliasResItr = bcpTypeAliasResByKey.GetEnumerator())
                            {
                                while (bcpTypeAliasResItr.MoveNext())
                                {
                                    UResourceBundle bcpTypeAliasDataEntry = bcpTypeAliasResItr.Current;
                                    string          from     = bcpTypeAliasDataEntry.Key;
                                    string          to       = bcpTypeAliasDataEntry.GetString();
                                    ISet <string>   aliasSet = bcpTypeAliasMap.Get(to);
                                    if (aliasSet == null)
                                    {
                                        aliasSet            = new HashSet <string>();
                                        bcpTypeAliasMap[to] = aliasSet;
                                    }
                                    aliasSet.Add(from);
                                }
                            }
                        }
                    }

                    IDictionary <string, Type> typeDataMap    = new Dictionary <string, Type>();
                    ISet <SpecialType>         specialTypeSet = null;

                    // look up type map for the key, and walk through the mapping data
                    UResourceBundle typeMapResByKey = null;
                    try
                    {
                        typeMapResByKey = typeMapRes.Get(legacyKeyId);
                    }
                    catch (MissingManifestResourceException e)
                    {
                        // type map for each key must exist
                        Debug.Assert(false);
                    }
                    if (typeMapResByKey != null)
                    {
                        using (UResourceBundleEnumerator typeMapResByKeyItr = typeMapResByKey.GetEnumerator())
                            while (typeMapResByKeyItr.MoveNext())
                            {
                                UResourceBundle typeMapEntry = typeMapResByKeyItr.Current;
                                string          legacyTypeId = typeMapEntry.Key;
                                string          bcpTypeId    = typeMapEntry.GetString();

                                // special types
                                char first         = legacyTypeId[0];
                                bool isSpecialType = '9' < first && first < 'a' && bcpTypeId.Length == 0;
                                if (isSpecialType)
                                {
                                    if (specialTypeSet == null)
                                    {
                                        specialTypeSet = new HashSet <SpecialType>();
                                    }
                                    specialTypeSet.Add((SpecialType)Enum.Parse(typeof(SpecialType), legacyTypeId, true));
                                    if (!_bcp47Types.Contains(legacyTypeId)) // ICU4N: Mimic LinkedHashSet with a List by not allowing duplicates
                                    {
                                        _bcp47Types.Add(legacyTypeId);
                                    }
                                    continue;
                                }

                                if (isTZ)
                                {
                                    // a timezone key uses a colon instead of a slash in the resource.
                                    // e.g. America:Los_Angeles
                                    legacyTypeId = legacyTypeId.Replace(':', '/');
                                }

                                bool hasSameType = false;
                                if (bcpTypeId.Length == 0)
                                {
                                    // Empty value indicates that BCP type is same with the legacy type.
                                    bcpTypeId   = legacyTypeId;
                                    hasSameType = true;
                                }
                                if (!_bcp47Types.Contains(legacyTypeId)) // ICU4N: Mimic LinkedHashSet with a List by not allowing duplicates
                                {
                                    _bcp47Types.Add(bcpTypeId);
                                }

                                // Note: legacy type value should never be
                                // equivalent to bcp type value of a different
                                // type under the same key. So we use a single
                                // map for lookup.
                                Type t = new Type(legacyTypeId, bcpTypeId);
                                typeDataMap[AsciiUtil.ToLower(legacyTypeId)] = t;
                                if (!hasSameType)
                                {
                                    typeDataMap[AsciiUtil.ToLower(bcpTypeId)] = t;
                                }

                                // Also put aliases in the map
                                if (typeAliasMap != null)
                                {
                                    ISet <string> typeAliasSet = typeAliasMap.Get(legacyTypeId);
                                    if (typeAliasSet != null)
                                    {
                                        foreach (string alias in typeAliasSet)
                                        {
                                            typeDataMap[AsciiUtil.ToLower(alias)] = t;
                                        }
                                    }
                                }
                                if (bcpTypeAliasMap != null)
                                {
                                    ISet <string> bcpTypeAliasSet = bcpTypeAliasMap.Get(bcpTypeId);
                                    if (bcpTypeAliasSet != null)
                                    {
                                        foreach (string alias in bcpTypeAliasSet)
                                        {
                                            typeDataMap[AsciiUtil.ToLower(alias)] = t;
                                        }
                                    }
                                }
                            }
                    }

                    KeyData keyData = new KeyData(legacyKeyId, bcpKeyId, typeDataMap, specialTypeSet);

                    KEYMAP[AsciiUtil.ToLower(legacyKeyId)] = keyData;
                    if (!hasSameKey)
                    {
                        KEYMAP[AsciiUtil.ToLower(bcpKeyId)] = keyData;
                    }
                }

                BCP47_KEYS = _Bcp47Keys.ToUnmodifiableDictionary();
            }
        }
Пример #14
0
        /// <summary>
        /// Lazily constructs the localeIdToRulesId and rulesIdToEquivalentULocale
        /// maps if necessary. These exactly reflect the contents of the locales
        /// resource in plurals.res.
        /// </summary>
        private void CheckBuildRulesIdMaps()
        {
            bool haveMap;

            lock (syncLock)
            {
                haveMap = localeIdToCardinalRulesId != null;
            }
            if (!haveMap)
            {
                IDictionary <string, string>  tempLocaleIdToCardinalRulesId;
                IDictionary <string, string>  tempLocaleIdToOrdinalRulesId;
                IDictionary <string, ULocale> tempRulesIdToEquivalentULocale;
                try
                {
                    UResourceBundle pluralb = GetPluralBundle();
                    // Read cardinal-number rules.
                    UResourceBundle localeb = pluralb.Get("locales");

                    // sort for convenience of getAvailableULocales
                    tempLocaleIdToCardinalRulesId = new SortedDictionary <string, string>(StringComparer.Ordinal);
                    // not visible
                    tempRulesIdToEquivalentULocale = new Dictionary <string, ULocale>();

                    for (int i = 0; i < localeb.Length; ++i)
                    {
                        UResourceBundle b     = localeb.Get(i);
                        string          id    = b.Key;
                        string          value = b.GetString().Intern();
                        tempLocaleIdToCardinalRulesId[id] = value;

                        if (!tempRulesIdToEquivalentULocale.ContainsKey(value))
                        {
                            tempRulesIdToEquivalentULocale[value] = new ULocale(id);
                        }
                    }

                    // Read ordinal-number rules.
                    localeb = pluralb.Get("locales_ordinals");
                    tempLocaleIdToOrdinalRulesId = new SortedDictionary <string, string>(StringComparer.Ordinal);
                    for (int i = 0; i < localeb.Length; ++i)
                    {
                        UResourceBundle b     = localeb.Get(i);
                        string          id    = b.Key;
                        string          value = b.GetString().Intern();
                        tempLocaleIdToOrdinalRulesId[id] = value;
                    }
                }
                catch (MissingManifestResourceException)
                {
                    // dummy so we don't try again
                    tempLocaleIdToCardinalRulesId  = new Dictionary <string, string>();
                    tempLocaleIdToOrdinalRulesId   = new Dictionary <string, string>();
                    tempRulesIdToEquivalentULocale = new Dictionary <string, ULocale>();
                }

                lock (syncLock)
                {
                    if (localeIdToCardinalRulesId == null)
                    {
                        localeIdToCardinalRulesId  = tempLocaleIdToCardinalRulesId;
                        localeIdToOrdinalRulesId   = tempLocaleIdToOrdinalRulesId;
                        rulesIdToEquivalentULocale = tempRulesIdToEquivalentULocale;
                    }
                }
            }
        }
Пример #15
0
            internal UArrayResource(UResourceBundle theHeader, UResourceBundle theData)
            {
                IBM.ICU.Charset.ResourceModule.Assert_is(theHeader != null && theData != null);
                String[] header_0;

                header_0 = IBM.ICU.Charset.ResourceModule.GetStringArrayHelper(theHeader);
                if (theData.GetSize() != header_0.Length)
                {
                    throw new TestDataModule_Constants.DataModuleFormatError(
                              "The count of Header and Data is mismatch.");
                }
                theMap = new Hashtable();
                for (int i = 0; i < header_0.Length; i++)
                {
                    if (theData.GetType() == IBM.ICU.Util.UResourceBundle.ARRAY)
                    {
                        ILOG.J2CsMapping.Collections.Collections.Put(theMap, header_0[i], theData.Get(i));
                    }
                    else if (theData.GetType() == IBM.ICU.Util.UResourceBundle.STRING)
                    {
                        ILOG.J2CsMapping.Collections.Collections.Put(theMap, header_0[i], theData.GetString());
                    }
                    else
                    {
                        throw new TestDataModule_Constants.DataModuleFormatError(
                                  "Did not get the expected data!");
                    }
                }
            }