Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the set of exemplar characters for a <paramref name="locale"/>.
 /// Equivalent to calling <c>new LocaleData(locale)</c>. <see cref="GetExemplarSet(PatternOptions, ExemplarSetType)"/>.
 /// </summary>
 /// <param name="locale">Locale for which the exemplar character set
 /// is to be retrieved.</param>
 /// <param name="options">
 /// <see cref="PatternOptions"/> flags to apply to the exemplar pattern.
 /// Specify <see cref="PatternOptions.Default"/> 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 <paramref name="locale"/>.</returns>
 /// <stable>ICU 3.0</stable>
 public static UnicodeSet GetExemplarSet(ULocale locale, PatternOptions options, ExemplarSetType extype)
 {
     return(LocaleData.GetInstance(locale).GetExemplarSet(options, extype));
 }