/// <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()); } } }
/// <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()); } } }
/// <summary> /// Utility to fetch locale display data from resource bundle tables. Uses fallback /// through the "Fallback" resource if available. /// </summary> public static string GetTableString(ICUResourceBundle bundle, string tableName, string subtableName, string item, string defaultValue) { string result = null; try { for (; ;) { ICUResourceBundle table = bundle.FindWithFallback(tableName); if (table == null) { return(defaultValue); } ICUResourceBundle stable = table; if (subtableName != null) { stable = table.FindWithFallback(subtableName); } if (stable != null) { result = stable.FindStringWithFallback(item); if (result != null) { break; // possible real exception } } // if we get here, stable was null, or there was no string for the item if (subtableName == null) { // may be a deprecated code string currentName = null; if (tableName.Equals("Countries")) { currentName = LocaleIDs.GetCurrentCountryID(item); } else if (tableName.Equals("Languages")) { currentName = LocaleIDs.GetCurrentLanguageID(item); } if (currentName != null) { result = table.FindStringWithFallback(currentName); if (result != null) { break; // possible real exception } } } // still can't figure it out? try the fallback mechanism string fallbackLocale = table.FindStringWithFallback("Fallback"); // again, possible exception if (fallbackLocale == null) { return(defaultValue); } if (fallbackLocale.Length == 0) { fallbackLocale = "root"; } if (fallbackLocale.Equals(table.GetULocale().GetName())) { return(defaultValue); } bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance( bundle.GetBaseName(), fallbackLocale); } } catch (Exception) { // If something is seriously wrong, we might call getString on a resource that is // not a string. That will throw an exception, which we catch and ignore here. } // If the result is empty return item instead return((result != null && result.Length > 0) ? result : defaultValue); }