Example #1
0
        /// <summary>
        /// Returns LocaleDisplayPattern for this locale, e.g., {0}({1})
        /// </summary>
        /// <returns>Locale display pattern as a <see cref="string"/>.</returns>
        /// <stable>ICU 4.2</stable>
        public string GetLocaleDisplayPattern()
        {
            ICUResourceBundle locDispBundle        = (ICUResourceBundle)langBundle.Get(LOCALE_DISPLAY_PATTERN);
            string            localeDisplayPattern = locDispBundle.GetStringWithFallback(PATTERN);

            return(localeDisplayPattern);
        }
Example #2
0
        /// <summary>
        /// Returns the set of exemplar characters for a locale.
        /// </summary>
        /// <param name="options">
        /// Bitmask for options to apply to the exemplar pattern.
        /// Specify zero to retrieve the exemplar set as it is
        /// defined in the locale data.  Specify <see cref="PatternOptions.Case"/>
        /// to retrieve a case-folded exemplar
        /// set.  See <see cref="PatternOptions"/> for a complete list of valid options.  The
        /// <see cref="PatternOptions.IgnoreSpace"/> bit is always set, regardless of the
        /// value of <paramref name="options"/>.
        /// </param>
        /// <param name="extype">The type of exemplar set to be retrieved,
        /// <see cref="ExemplarSetType.Standard"/>, <see cref="ExemplarSetType.Index"/>,
        /// <see cref="ExemplarSetType.Auxiliary"/>, or <see cref="ExemplarSetType.Punctuation"/>.</param>
        /// <returns>
        /// The set of exemplar characters for the given locale.
        /// If there is nothing available for the locale,
        /// then null is returned if <see cref="NoSubstitute"/> is <c>true</c>, otherwise the
        /// root value is returned (which may be <see cref="UnicodeSet.Empty"/>.
        /// </returns>
        /// <exception cref="IndexOutOfRangeException">If <paramref name="extype"/> is invalid.</exception>
        /// <stable>ICU 3.4</stable>
        public UnicodeSet GetExemplarSet(PatternOptions options, ExemplarSetType extype)
        {
            string[] exemplarSetTypes =
            {
                "ExemplarCharacters",
                "AuxExemplarCharacters",
                "ExemplarCharactersIndex",
                "ExemplarCharactersCurrency",
                "ExemplarCharactersPunctuation"
            };

            // ICU4N: Currency was never supported in .NET
//#pragma warning disable 612, 618
//            if (extype == ES_CURRENCY)
//#pragma warning restore 612, 618
//            {
//                // currency symbol exemplar is no longer available
//                return noSubstitute ? null : UnicodeSet.Empty;
//            }

            try
            {
                string            aKey         = exemplarSetTypes[(int)extype]; // will throw an out-of-bounds exception
                ICUResourceBundle stringBundle = (ICUResourceBundle)bundle.Get(aKey);

                if (noSubstitute && !bundle.IsRoot && stringBundle.IsRoot)
                {
                    return(null);
                }
                string unicodeSetPattern = stringBundle.GetString();
                return(new UnicodeSet(unicodeSetPattern, UnicodeSet.IgnoreSpace | options));
            }
            catch (IndexOutOfRangeException aiooe)
            {
                throw new ArgumentException(aiooe.Message, aiooe);
            }
            catch (Exception)
            {
                return(noSubstitute ? null : UnicodeSet.Empty);
            }
        }
Example #3
0
        /// <summary>
        /// Instantiate a currency from a resource bundle found in Locale loc.
        /// </summary>
        ///
        /* package */ static internal Currency CreateCurrency(ULocale loc)
        {
            String country   = loc.GetCountry();
            String variant   = loc.GetVariant();
            bool   isPreEuro = variant.Equals("PREEURO");
            bool   isEuro    = variant.Equals("EURO");
            // TODO: ICU4C has service registration, and the currency is requested
            // from the service here.
            ICUResourceBundle bundle = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                       .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME,
                                                          "supplementalData",
                                                          IBM.ICU.Impl.ICUResourceBundle.ICU_DATA_CLASS_LOADER);

            if (bundle == null)
            {
                // throw new MissingResourceException()
                return(null);
            }
            try {
                UResourceBundle cm           = bundle.Get("CurrencyMap");
                String          curriso      = null;
                UResourceBundle countryArray = cm.Get(country);
                // Some regions can have more than one current currency in use.
                // The latest default currency is always the first one.
                UResourceBundle currencyReq = countryArray.Get(0);
                curriso = currencyReq.GetString("id");
                if (isPreEuro && curriso.Equals(EUR_STR))
                {
                    currencyReq = countryArray.Get(1);
                    curriso     = currencyReq.GetString("id");
                }
                else if (isEuro)
                {
                    curriso = EUR_STR;
                }
                if (curriso != null)
                {
                    return(new Currency(curriso));
                }
            } catch (MissingManifestResourceException ex) {
                // We don't know about this region.
                // As of CLDR 1.5.1, the data includes deprecated region history
                // too.
                // So if we get here, either the region doesn't exist, or the data
                // is really bad.
                // Deprecated regions should return the last valid currency for that
                // region in the data.
                // We don't try to resolve it to a new region.
            }
            return(null);
        }
Example #4
0
        /**
         * Returns the set of exemplar characters for a locale.
         *
         * @param options   Bitmask for options to apply to the exemplar pattern.
         *                  Specify zero to retrieve the exemplar set as it is
         *                  defined in the locale data.  Specify
         *                  UnicodeSet.CASE to retrieve a case-folded exemplar
         *                  set.  See {@link UnicodeSet#applyPattern(String,
         *                  int)} for a complete list of valid options.  The
         *                  IGNORE_SPACE bit is always set, regardless of the
         *                  value of 'options'.
         * @param extype    The type of exemplar set to be retrieved,
         *                  ES_STANDARD, ES_INDEX, ES_AUXILIARY, or ES_PUNCTUATION
         * @return          The set of exemplar characters for the given locale.
         *                  If there is nothing available for the locale,
         *                  then null is returned if {@link #getNoSubstitute()} is true, otherwise the
         *                  root value is returned (which may be UnicodeSet.EMPTY).
         * @exception       RuntimeException if the extype is invalid.
         * @stable ICU 3.4
         */
        public UnicodeSet GetExemplarSet(int options, int extype)
        {
            string[] exemplarSetTypes =
            {
                "ExemplarCharacters",
                "AuxExemplarCharacters",
                "ExemplarCharactersIndex",
                "ExemplarCharactersCurrency",
                "ExemplarCharactersPunctuation"
            };

            if (extype == ES_CURRENCY)
            {
                // currency symbol exemplar is no longer available
                return(noSubstitute ? null : UnicodeSet.EMPTY);
            }

            try
            {
                string            aKey         = exemplarSetTypes[extype]; // will throw an out-of-bounds exception
                ICUResourceBundle stringBundle = (ICUResourceBundle)bundle.Get(aKey);

                if (noSubstitute && !bundle.IsRoot && stringBundle.IsRoot)
                {
                    return(null);
                }
                String unicodeSetPattern = stringBundle.GetString();
                return(new UnicodeSet(unicodeSetPattern, UnicodeSet.IGNORE_SPACE | options));
            }
            catch (IndexOutOfRangeException aiooe)
            {
                throw new ArgumentException(aiooe.Message, aiooe);
            }
            catch (Exception ex)
            {
                return(noSubstitute ? null : UnicodeSet.EMPTY);
            }
        }
Example #5
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]);
        }
Example #6
0
        /// <summary>
        /// Returns the set of exemplar characters for a locale.
        /// </summary>
        ///
        /// <param name="options">Bitmask for options to apply to the exemplar pattern. Specifyzero to retrieve the exemplar set as it is defined in thelocale data. Specify UnicodeSet.CASE to retrieve a case-foldedexemplar set. See <see cref="null"/>for a complete list of valid options. The IGNORE_SPACE bit isalways set, regardless of the value of 'options'.</param>
        /// <param name="extype">The type of exemplar set to be retrieved, ES_STANDARD orES_AUXILIARY</param>
        /// <returns>The set of exemplar characters for the given locale.</returns>
        /// @stable ICU 3.4
        public UnicodeSet GetExemplarSet(int options, int extype)
        {
            String[] exemplarSetTypes = { "ExemplarCharacters",
                                          "AuxExemplarCharacters" };
            try {
                ICUResourceBundle stringBundle = (ICUResourceBundle)bundle
                                                 .Get(exemplarSetTypes[extype]);

                if (noSubstitute &&
                    (stringBundle.GetLoadingStatus() == IBM.ICU.Impl.ICUResourceBundle.FROM_ROOT))
                {
                    return(null);
                }

                return(new UnicodeSet(stringBundle.GetString(),
                                      IBM.ICU.Text.UnicodeSet.IGNORE_SPACE | options));
            } catch (MissingManifestResourceException ex) {
                if (extype == LocaleData.ES_AUXILIARY)
                {
                    return(new UnicodeSet());
                }
                throw ex;
            }
        }
            /// <summary>
            /// Create <see cref="SimpleFilteredSentenceBreakIterator.Builder"/> using given locale.
            /// </summary>
            /// <param name="loc">The locale to get filtered iterators.</param>
            public Builder(ULocale loc)
#pragma warning disable 612, 618
                : base()
#pragma warning restore 612, 618
            {
                ICUResourceBundle rb = ICUResourceBundle.GetBundleInstance(
                    ICUData.ICU_BRKITR_BASE_NAME, loc, OpenType.LOCALE_ROOT);

                ICUResourceBundle breaks = rb.FindWithFallback("exceptions/SentenceBreak");

                if (breaks != null)
                {
                    for (int index = 0, size = breaks.Length; index < size; ++index)
                    {
                        ICUResourceBundle b  = (ICUResourceBundle)breaks.Get(index);
                        string            br = b.GetString();
                        filterSet.Add(br.ToCharSequence());
                    }
                }
            }
Example #8
0
        /// <summary>
        /// Create <see cref="SimpleFilteredSentenceBreakIteratorBuilder"/> using given locale.
        /// </summary>
        /// <param name="loc">The locale to get filtered iterators.</param>
        public SimpleFilteredSentenceBreakIteratorBuilder(UCultureInfo loc)
#pragma warning disable 612, 618
            : base()
#pragma warning restore 612, 618
        {
            ICUResourceBundle rb = ICUResourceBundle.GetBundleInstance(
                ICUData.IcuBreakIteratorBaseName, loc, OpenType.LocaleRoot);

            ICUResourceBundle breaks = rb.FindWithFallback("exceptions/SentenceBreak");

            if (breaks != null)
            {
                for (int index = 0, size = breaks.Length; index < size; ++index)
                {
                    ICUResourceBundle b  = (ICUResourceBundle)breaks.Get(index);
                    string            br = b.GetString();
                    filterSet.Add(br.AsCharSequence());
                }
            }
        }
Example #9
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);
        }