Example #1
0
        private NamePrepTransform()
        {
            // load the resource bundle
            //ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.GetBundleInstance("com/ibm/icu/dev/data/testdata", "idna_rules", typeof(NamePrepTransform).GetTypeInfo().Assembly, true);
            ICUResourceBundle bundle   = (ICUResourceBundle)ICUResourceBundle.GetBundleInstance("Dev/Data/TestData", "idna_rules", typeof(NamePrepTransform).GetTypeInfo().Assembly, true);
            String            mapRules = bundle.GetString("MapNoNormalization");

            mapRules += bundle.GetString("MapNFKC");
            // disable
            mapTransform      = new MapTransform("CaseMap", mapRules, 0 /*Transliterator.FORWARD*/);
            labelSeparatorSet = new UnicodeSet(bundle.GetString("LabelSeparatorSet"));
            prohibitedSet     = new UnicodeSet(bundle.GetString("ProhibitedSet"));
            unassignedSet     = new UnicodeSet(bundle.GetString("UnassignedSet"));
        }
Example #2
0
        // /CLOVER:ON

        /// <summary>
        /// Returns the set of exemplar characters for a locale.
        /// </summary>
        ///
        /// <param name="locale">Locale for which the exemplar character set is to beretrieved.</param>
        /// <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>
        /// <returns>The set of exemplar characters for the given locale.</returns>
        /// @stable ICU 3.0
        public static UnicodeSet GetExemplarSet(ULocale locale, int options)
        {
            ICUResourceBundle bundle_0 = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                         .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale);
            String pattern = bundle_0.GetString(EXEMPLAR_CHARS);

            return(new UnicodeSet(pattern, IBM.ICU.Text.UnicodeSet.IGNORE_SPACE | options));
        }
Example #3
0
        /// <summary>
        /// Returns the string in a given resource at the specified index.
        /// </summary>
        /// <param name="index">An index to the wanted string.</param>
        /// <returns>A string which lives in the resource.</returns>
        /// <exception cref="IndexOutOfRangeException">If the index value is out of bounds of accepted values.</exception>
        /// <exception cref="UResourceTypeMismatchException">If resource bundle type mismatch.</exception>
        /// <stable>ICU 3.8</stable>
        public virtual string GetString(int index)
        {
            ICUResourceBundle temp = (ICUResourceBundle)Get(index);

            if (temp.Type == UResourceType.String)
            {
                return(temp.GetString());
            }
            throw new UResourceTypeMismatchException("");
        }
        /// <summary>
        /// Returns the string in a given resource at the specified index.
        /// </summary>
        ///
        /// <param name="index">an index to the wanted string.</param>
        /// <returns>a string which lives in the resource.</returns>
        /// <exception cref="IndexOutOfBoundsException"></exception>
        /// <exception cref="UResourceTypeMismatchException"></exception>
        /// @draft ICU 3.8
        /// @provisional This API might change or be removed in a future release.
        public String GetString(int index)
        {
            ICUResourceBundle temp = (ICUResourceBundle)Get(index);

            if (temp.GetType() == STRING)
            {
                return(temp.GetString());
            }
            throw new UResourceTypeMismatchException("");
        }
Example #5
0
        /// <summary>
        /// Retrieves a delimiter string from the locale data.
        /// </summary>
        /// <param name="type">
        /// The type of delimiter string desired.  Currently,
        /// the valid choices are <see cref="DelimiterType.QuotationStart"/>, <see cref="DelimiterType.QuotationEnd"/>,
        /// <see cref="DelimiterType.AlternateQuotationStart"/>, or <see cref="DelimiterType.AlternateQuotationEnd"/>.
        /// </param>
        /// <returns>The desired delimiter string.</returns>
        /// <stable>ICU 3.4</stable>
        public string GetDelimiter(DelimiterType type)
        {
            ICUResourceBundle delimitersBundle = (ICUResourceBundle)bundle.Get("delimiters");
            // Only some of the quotation marks may be here. So we make sure that we do a multilevel fallback.
            ICUResourceBundle stringBundle = delimitersBundle.GetWithFallback(DELIMITER_TYPES[(int)type]);

            if (noSubstitute && !bundle.IsRoot && stringBundle.IsRoot)
            {
                return(null);
            }
            return(stringBundle.GetString());
        }
Example #6
0
        /// <summary>
        /// Retrieves a delimiter string from the locale data.
        /// </summary>
        ///
        /// <param name="type">The type of delimiter string desired. Currently, the validchoices are QUOTATION_START, QUOTATION_END,ALT_QUOTATION_START, or ALT_QUOTATION_END.</param>
        /// <returns>The desired delimiter string.</returns>
        /// @stable ICU 3.4
        public String GetDelimiter(int type)
        {
            String[] delimiterTypes = { "quotationStart",          "quotationEnd",
                                        "alternateQuotationStart", "alternateQuotationEnd" };

            ICUResourceBundle stringBundle = (ICUResourceBundle)bundle.Get(
                "delimiters").Get(delimiterTypes[type]);

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

            return(stringBundle.GetString());
        }
            /// <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>
        /// 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 #10
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 #11
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;
            }
        }
Example #12
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);
        }