/*
         * public DateNumberFormat(char zeroDigit, char minusSign) { this.zeroDigit
         * = zeroDigit; this.minusSign = minusSign; }
         */

        private void Initialize(ULocale loc)
        {
            char[] elems = (char[])CACHE.Get(loc);
            if (elems == null)
            {
                // Missed cache
                ICUResourceBundle rb = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                       .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, loc);
                String[] numberElements = rb.GetStringArray("NumberElements");
                elems    = new char[2];
                elems[0] = numberElements[4][0];
                elems[1] = numberElements[6][0];
                CACHE.Put(loc, elems);
            }
            zeroDigit = elems[0];
            minusSign = elems[1];
        }
Example #2
0
        public String[] GetEras(String subkey)
        {
            ICUResourceBundle bundle = Get("eras/" + subkey);

            return(bundle.GetStringArray());
        }
Example #3
0
        /// <summary>
        /// Initializes the symbols from the LocaleElements resource bundle. Note:
        /// The organization of LocaleElements badly needs to be cleaned up.
        /// </summary>
        ///
        private void Initialize(ULocale locale)
        {
            this.requestedLocale = locale.ToLocale();
            this.ulocale         = locale;

            /* try the cache first */
            String[][] data = (String[][])cachedLocaleData[locale];
            String[]   numberElements;
            if (data == null)       /* cache miss */
            {
                data = new String[1][];
                ICUResourceBundle rb = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                       .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale);
                data[0] = rb.GetStringArray("NumberElements");
                /* update cache */
                ILOG.J2CsMapping.Collections.Collections.Put(cachedLocaleData, locale, data);
            }
            numberElements = data[0];

            ICUResourceBundle r = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                  .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale);

            // TODO: Determine actual and valid locale correctly.
            ULocale uloc = r.GetULocale();

            SetLocale(uloc, uloc);

            // {dlf} clean up below now that we have our own resource data
            decimalSeparator  = numberElements[0][0];
            groupingSeparator = numberElements[1][0];
            // Temporary hack to support old JDK 1.1 resources
            // patternSeparator = numberElements[2].length() > 0 ?
            // numberElements[2].charAt(0) : ';';
            patternSeparator = numberElements[2][0];
            percent          = numberElements[3][0];
            zeroDigit        = numberElements[4][0]; // different for Arabic,etc.
            digit            = numberElements[5][0];
            minusSign        = numberElements[6][0];

            // Temporary hack to support JDK versions before 1.1.6 (?)
            // exponentSeparator = numberElements.length >= 9 ?
            // numberElements[7] : DecimalFormat.PATTERN_EXPONENT;
            // perMill = numberElements.length >= 9 ?
            // numberElements[8].charAt(0) : '\u2030';
            // infinity = numberElements.length >= 10 ?
            // numberElements[9] : "\u221e";
            // NaN = numberElements.length >= 11 ?
            // numberElements[10] : "\ufffd";
            exponentSeparator = numberElements[7];
            perMill           = numberElements[8][0];
            infinity          = numberElements[9];
            NaN = numberElements[10];

            plusSign  = numberElements[11][0];
            padEscape = IBM.ICU.Text.DecimalFormat.PATTERN_PAD_ESCAPE;
            sigDigit  = IBM.ICU.Text.DecimalFormat.PATTERN_SIGNIFICANT_DIGIT;

            // Obtain currency data from the currency API. This is strictly
            // for backward compatibility; we don't use DecimalFormatSymbols
            // for currency data anymore.
            String currname = null;

            currency = IBM.ICU.Util.Currency.GetInstance(locale);
            if (currency != null)
            {
                intlCurrencySymbol = currency.GetCurrencyCode();
                bool[] isChoiceFormat = new bool[1];
                currname = currency.GetName(locale, IBM.ICU.Util.Currency.SYMBOL_NAME,
                                            isChoiceFormat);
                // If this is a ChoiceFormat currency, then format an
                // arbitrary value; pick something != 1; more common.
                currencySymbol = (isChoiceFormat[0]) ? new ChoiceFormat(currname)
                                 .Format(2.0d) : currname;
            }
            else
            {
                intlCurrencySymbol = "XXX";
                currencySymbol     = "\u00A4"; // 'OX' currency symbol
            }
            // If there is a currency decimal, use it.
            monetarySeparator         = decimalSeparator;
            monetaryGroupingSeparator = groupingSeparator;
            Currency curr = IBM.ICU.Util.Currency.GetInstance(locale);

            if (curr != null)
            {
                String currencyCode = curr.GetCurrencyCode();
                if (currencyCode != null)
                {
                    /* An explicit currency was requested */
                    ICUResourceBundle resource = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                                 .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME,
                                                                    locale);
                    ICUResourceBundle currencyRes = resource
                                                    .GetWithFallback("Currencies");
                    try {
                        currencyRes = currencyRes.GetWithFallback(currencyCode);
                        if (currencyRes.GetSize() > 2)
                        {
                            currencyRes               = (ICUResourceBundle)currencyRes.Get(2);
                            currencyPattern           = currencyRes.GetString(0);
                            monetarySeparator         = currencyRes.GetString(1)[0];
                            monetaryGroupingSeparator = currencyRes.GetString(2)[0];
                        }
                    } catch (MissingManifestResourceException ex) {
                        /*
                         * else An explicit currency was requested and is unknown or
                         * locale data is malformed.
                         */
                        /* decimal format API will get the correct value later on. */
                    }
                }
                /* else no currency keyword used. */
            }
            // monetarySeparator = numberElements[11].charAt(0);
        }