Esempio n. 1
0
            /// <summary>
            /// Returns a String if found, or null if not found or if the key item is not a string.
            /// </summary>
            internal virtual string FindString(string key)
            {
                ICUResourceBundleReader reader = wholeBundle.reader;
                int index = ((ICUResourceBundleReader.Table)value).FindTableItem(reader, key);

                if (index < 0)
                {
                    return(null);
                }
                return(reader.GetString(value.GetContainerResource(reader, index)));
            }
Esempio n. 2
0
            internal override ISet <string> HandleKeySet() // ICU4N: Marked internal, since base class functionality is obsolete
            {
                ICUResourceBundleReader reader = wholeBundle.reader;
                SortedSet <string>      keySet = new SortedSet <string>(StringComparer.Ordinal);

                ICUResourceBundleReader.Table table = (ICUResourceBundleReader.Table)value;
                for (int i = 0; i < table.Length; ++i)
                {
                    keySet.Add(table.GetKey(reader, i));
                }
                return(keySet);
            }
Esempio n. 3
0
            protected override ISet <string> HandleKeySet()
            {
                ICUResourceBundleReader reader = wholeBundle.reader;
                SortedSet <string>      keySet = new SortedSet <string>(StringComparer.Ordinal);

                ICUResourceBundleReader.Table table = (ICUResourceBundleReader.Table)value;
                for (int i = 0; i < table.Length; ++i)
                {
                    keySet.Add(table.GetKey(reader, i));
                }
                return(keySet);
            }
Esempio n. 4
0
        /**
         * {@icu} Returns a resource in a given resource that has a given key.
         *
         * @param aKey               a key associated with the wanted resource
         * @return                  a resource bundle object representing the resource
         * @throws MissingResourceException If resource bundle is missing.
         * @stable ICU 3.8
         */
        public virtual UResourceBundle Get(string aKey) // ICU4N TODO: API make into indexer property
        {
            UResourceBundle obj = FindTopLevel(aKey);

            if (obj == null)
            {
                string fullName = ICUResourceBundleReader.GetFullName(GetBaseName(), GetLocaleID());
                throw new MissingManifestResourceException(
                          "Can't find resource for bundle " + fullName + ", key "
                          + aKey + "Type: " + this.GetType().FullName + " Key: " + aKey);
            }
            return(obj);
        }
Esempio n. 5
0
        /// <summary>
        /// <icu/> Returns a resource in a given resource that has a given key.
        /// </summary>
        /// <param name="aKey">A key associated with the wanted resource.</param>
        /// <returns>A resource bundle object representing the resource.</returns>
        /// <exception cref="MissingManifestResourceException">If resource bundle is missing.</exception>
        /// <stable>ICU 3.8</stable>
        public virtual UResourceBundle Get(string aKey) // ICU4N TODO: API make into indexer property
        {
#pragma warning disable 612, 618
            UResourceBundle obj = FindTopLevel(aKey);
#pragma warning restore 612, 618
            if (obj == null)
            {
                string fullName = ICUResourceBundleReader.GetFullName(BaseName, LocaleID);
                throw new MissingManifestResourceException(
                          "Can't find resource for bundle " + fullName + ", key "
                          + aKey + "Type: " + this.GetType().FullName + " Key: " + aKey);
            }
            return(obj);
        }
Esempio n. 6
0
            protected override string[] HandleGetStringArray()
            {
                ICUResourceBundleReader reader = wholeBundle.reader;
                int length = value.Length;

                string[] strings = new string[length];
                for (int i = 0; i < length; ++i)
                {
                    string s = reader.GetString(value.GetContainerResource(reader, i));
                    if (s == null)
                    {
                        throw new UResourceTypeMismatchException("");
                    }
                    strings[i] = s;
                }
                return(strings);
            }
Esempio n. 7
0
            protected override object HandleGetObject(string key)
            {
                // Fast path for common cases: Avoid creating UResourceBundles if possible.
                // It would be even better if we could override getString(key)/getStringArray(key),
                // so that we know the expected object type,
                // but those are final in java.util.ResourceBundle.
                ICUResourceBundleReader reader = wholeBundle.reader;
                int index = ((ICUResourceBundleReader.Table)value).FindTableItem(reader, key);

                if (index >= 0)
                {
                    int res = value.GetContainerResource(reader, index);
                    // getString(key)
                    string s = reader.GetString(res);
                    if (s != null)
                    {
                        return(s);
                    }
                    // getStringArray(key)
                    ICUResourceBundleReader.Container array = reader.GetArray(res);
                    if (array != null)
                    {
                        int      length  = array.Length;
                        string[] strings = new string[length];
                        for (int j = 0; ; ++j)
                        {
                            if (j == length)
                            {
                                return(strings);
                            }
                            s = reader.GetString(array.GetContainerResource(reader, j));
                            if (s == null)
                            {
                                // Equivalent to resolveObject(key, requested):
                                // If this is not a string array,
                                // then build and return a UResourceBundle.
                                break;
                            }
                            strings[j] = s;
                        }
                    }
                }
                return(base.HandleGetObject(key));
            }
Esempio n. 8
0
        protected ICUResourceBundle CreateBundleObject(string _key,
                                                       int _resource,
                                                       IDictionary <string, string> aliasesVisited,
                                                       UResourceBundle requested)
        {
            switch (ICUResourceBundleReader.RES_GET_TYPE(_resource))
            {
            case UResourceType.String:
            case UResourceType.StringV2:
                return(new ICUResourceBundleImpl.ResourceString(this, _key, _resource));

            case UResourceType.Binary:
                return(new ICUResourceBundleImpl.ResourceBinary(this, _key, _resource));

            case UResourceType.Alias:
                return(GetAliasedResource(this, null, 0, _key, _resource, aliasesVisited, requested));

            case UResourceType.Int32:
                return(new ICUResourceBundleImpl.ResourceInt(this, _key, _resource));

            case UResourceType.Int32Vector:
                return(new ICUResourceBundleImpl.ResourceIntVector(this, _key, _resource));

            case UResourceType.Array:
            case UResourceType.Array16:
                return(new ICUResourceBundleImpl.ResourceArray(this, _key, _resource));

            case UResourceType.Table:
            case UResourceType.Table16:
            case UResourceType.Table32:
                return(new ICUResourceBundleImpl.ResourceTable(this, _key, _resource));

            default:
                throw new InvalidOperationException("The resource type is unknown");
            }
        }
Esempio n. 9
0
        protected ICUResourceBundle CreateBundleObject(string _key,
                                                       int _resource,
                                                       IDictionary <string, string> aliasesVisited,
                                                       UResourceBundle requested)
        {
            switch (ICUResourceBundleReader.RES_GET_TYPE(_resource))
            {
            case STRING:
            case STRING_V2:
                return(new ICUResourceBundleImpl.ResourceString(this, _key, _resource));

            case BINARY:
                return(new ICUResourceBundleImpl.ResourceBinary(this, _key, _resource));

            case ALIAS:
                return(GetAliasedResource(this, null, 0, _key, _resource, aliasesVisited, requested));

            case INT32:
                return(new ICUResourceBundleImpl.ResourceInt(this, _key, _resource));

            case INT32_VECTOR:
                return(new ICUResourceBundleImpl.ResourceIntVector(this, _key, _resource));

            case ARRAY:
            case ARRAY16:
                return(new ICUResourceBundleImpl.ResourceArray(this, _key, _resource));

            case TABLE:
            case TABLE16:
            case TABLE32:
                return(new ICUResourceBundleImpl.ResourceTable(this, _key, _resource));

            default:
                throw new InvalidOperationException("The resource type is unknown");
            }
        }
Esempio n. 10
0
 public override int GetInt32()
 {
     return(ICUResourceBundleReader.RES_GET_INT(resource));
 }
Esempio n. 11
0
 public override int GetUInt32() // ICU4N TODO: API - should this actually be uint rather than int?
 {
     return(ICUResourceBundleReader.RES_GET_UINT(resource));
 }