/// <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); }
public void TestGetWithFallback() { /* * UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN"); * String key = bundle.getStringWithFallback("Keys/collation"); * if(!key.equals("COLLATION")){ * Errln("Did not get the expected result from getStringWithFallback method."); * } * String type = bundle.getStringWithFallback("Types/collation/direct"); * if(!type.equals("DIRECT")){ * Errln("Did not get the expected result form getStringWithFallback method."); * } */ ICUResourceBundle bundle = null; String key = null; try { bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuCollationBaseName, ULocale.Canonicalize("de__PHONEBOOK")); if (!bundle.GetULocale().GetName().Equals("de")) { Errln("did not get the expected bundle"); } key = bundle.GetStringWithFallback("collations/collation/default"); if (!key.Equals("phonebook")) { Errln("Did not get the expected result from getStringWithFallback method."); } } catch (MissingManifestResourceException ex) { Logln("got the expected exception"); } bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuCollationBaseName, "fr_FR"); key = bundle.GetStringWithFallback("collations/default"); if (!key.Equals("standard")) { Errln("Did not get the expected result from getStringWithFallback method."); } }
public static DictionaryMatcher LoadDictionaryFor(string dictType) { ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBreakIteratorBaseName); // com/ibm/icu/impl/data/icudt60b/brkitr string dictFileName = rb.GetStringWithFallback("dictionaries/" + dictType); // ICU4N TODO: Possibly rename the above and use this syntax instead...? //var rm = new ResourceManager(ICUData.ICU_BRKITR_BASE_NAME, typeof(DictionaryData).GetTypeInfo().Assembly); //string dictFileName = rm.GetString("dictionaries_" + dictType); dictFileName = ICUData.IcuBreakIteratorName + '/' + dictFileName; ByteBuffer bytes = ICUBinary.GetRequiredData(dictFileName); ICUBinary.ReadHeader(bytes, DATA_FORMAT_ID, null); int[] indexes = new int[IX_COUNT]; // TODO: read indexes[IX_STRING_TRIE_OFFSET] first, then read a variable-length indexes[] for (int i = 0; i < IX_COUNT; i++) { indexes[i] = bytes.GetInt32(); } int offset = indexes[IX_STRING_TRIE_OFFSET]; Assert.Assrt(offset >= (4 * IX_COUNT)); if (offset > (4 * IX_COUNT)) { int diff = offset - (4 * IX_COUNT); ICUBinary.SkipBytes(bytes, diff); } int trieType = indexes[IX_TRIE_TYPE] & TRIE_TYPE_MASK; int totalSize = indexes[IX_TOTAL_SIZE] - offset; DictionaryMatcher m = null; if (trieType == TRIE_TYPE_BYTES) { int transform = indexes[IX_TRANSFORM]; byte[] data = new byte[totalSize]; bytes.Get(data); m = new BytesDictionaryMatcher(data, transform); } else if (trieType == TRIE_TYPE_UCHARS) { Assert.Assrt(totalSize % 2 == 0); string data = ICUBinary.GetString(bytes, totalSize / 2, totalSize & 1); m = new CharsDictionaryMatcher(data); } else { m = null; } return(m); }
/// <summary> /// Returns LocaleDisplaySeparator for this locale. /// </summary> /// <returns>Locale display separator as a char.</returns> /// <stable>ICU 4.2</stable> public string GetLocaleSeparator() { string sub0 = "{0}"; string sub1 = "{1}"; ICUResourceBundle locDispBundle = (ICUResourceBundle)langBundle.Get(LOCALE_DISPLAY_PATTERN); string localeSeparator = locDispBundle.GetStringWithFallback(SEPARATOR); int index0 = localeSeparator.IndexOf(sub0, StringComparison.Ordinal); int index1 = localeSeparator.IndexOf(sub1, StringComparison.Ordinal); if (index0 >= 0 && index1 >= 0 && index0 <= index1) { return(localeSeparator.Substring(index0 + sub0.Length, index1 - (index0 + sub0.Length))); // ICU4N: Corrected 2nd parameter } return(localeSeparator); }
private static BreakIterator CreateBreakInstance(ULocale locale, int kind) { BreakIterator iter = null; ICUResourceBundle rb = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BRKITR_BASE_NAME, locale); // // Get the binary rules. These are needed for both normal // RulesBasedBreakIterators // and for Dictionary iterators. // Stream ruleStream = null; try { String typeKey = KIND_NAMES[kind]; String brkfname = rb.GetStringWithFallback("boundaries/" + typeKey); String rulesFileName = IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME /*+ * IBM.ICU.Impl.ICUResourceBundle.ICU_BUNDLE*/ + IBM.ICU.Impl.ICUResourceBundle.ICU_BRKITR_NAME + "/" + brkfname; ruleStream = IBM.ICU.Impl.ICUData.GetStream(rulesFileName); } catch (Exception e) { throw new MissingManifestResourceException(e.ToString()); } // // Check whether a dictionary exists, and create a DBBI iterator is // one does. // if (DICTIONARY_POSSIBLE[kind]) { // This type of break iterator could potentially use a dictionary. // try { // ICUResourceBundle dictRes = // (ICUResourceBundle)rb.getObject("BreakDictionaryData"); // byte[] dictBytes = null; // dictBytes = dictRes.getBinary(dictBytes); // TODO: Hard code this for now! fix it once // CompactTrieDictionary is ported if (locale.Equals("th")) { String fileName = "data/th.brk"; Stream mask0 = IBM.ICU.Impl.ICUData.GetStream(fileName); iter = new DictionaryBasedBreakIterator(ruleStream, mask0); } } catch (MissingManifestResourceException e_0) { // Couldn't find a dictionary. // This is normal, and will occur whenever creating a word or // line // break iterator for a locale that does not have a // BreakDictionaryData // resource - meaning for all but Thai. // Fall through to creating a normal RulebasedBreakIterator. } catch (IOException e_1) { IBM.ICU.Impl.Assert.Fail(e_1); } } if (iter == null) { // // Create a normal RuleBasedBreakIterator. // We have determined that this is not supposed to be a dictionary // iterator. // try { iter = IBM.ICU.Text.RuleBasedBreakIterator .GetInstanceFromCompiledRules(ruleStream); } catch (IOException e_2) { // Shouldn't be possible to get here. // If it happens, the compiled rules are probably corrupted in // some way. IBM.ICU.Impl.Assert.Fail(e_2); } } // TODO: Determine valid and actual locale correctly. ULocale uloc = IBM.ICU.Util.ULocale.ForLocale(rb.GetLocale()); iter.SetLocale(uloc, uloc); return(iter); }
private static BreakIterator CreateBreakInstance(ULocale locale, int kind) { RuleBasedBreakIterator iter = null; ICUResourceBundle rb = ICUResourceBundle. GetBundleInstance(ICUData.ICU_BRKITR_BASE_NAME, locale, ICUResourceBundle.OpenType.LOCALE_ROOT); // // Get the binary rules. // ByteBuffer bytes = null; string typeKeyExt = null; if (kind == BreakIterator.KIND_LINE) { string lbKeyValue = locale.GetKeywordValue("lb"); if (lbKeyValue != null && (lbKeyValue.Equals("strict") || lbKeyValue.Equals("normal") || lbKeyValue.Equals("loose"))) { typeKeyExt = "_" + lbKeyValue; } } try { string typeKey = (typeKeyExt == null) ? KIND_NAMES[kind] : KIND_NAMES[kind] + typeKeyExt; string brkfname = rb.GetStringWithFallback("boundaries/" + typeKey); string rulesFileName = ICUData.ICU_BRKITR_NAME + '/' + brkfname; bytes = ICUBinary.GetData(rulesFileName); } catch (Exception e) { throw new MissingManifestResourceException(e.ToString(), e /*, "", ""*/); } // // Create a normal RuleBasedBreakIterator. // try { #pragma warning disable 612, 618 iter = RuleBasedBreakIterator.GetInstanceFromCompiledRules(bytes); #pragma warning restore 612, 618 } catch (IOException e) { // Shouldn't be possible to get here. // If it happens, the compiled rules are probably corrupted in some way. Assert.Fail(e); } // TODO: Determine valid and actual locale correctly. ULocale uloc = ULocale.ForLocale(rb.GetLocale()); iter.SetLocale(uloc, uloc); iter.BreakType = kind; // filtered break if (kind == BreakIterator.KIND_SENTENCE) { string ssKeyword = locale.GetKeywordValue("ss"); if (ssKeyword != null && ssKeyword.Equals("standard")) { ULocale @base = new ULocale(locale.GetBaseName()); return(FilteredBreakIteratorBuilder.GetInstance(@base).WrapIteratorWithFilter(iter)); } } return(iter); }