/// <summary> /// Attempt to find an entry in a single resource bundle. This is /// a one-sided lookup. <see cref="FindInStaticStore(Spec, Spec, string)"/> performs up to two such /// lookups, one for the source, and one for the target. /// <para/> /// Do not perform fallback. Return 0 on failure. /// <para/> /// On success, create a new Entry object, populate it, and return it. /// The caller owns the returned object. /// </summary> private object[] FindInBundle(Spec specToOpen, Spec specToFind, string variant, TransliterationDirection direction) { // assert(specToOpen.isLocale()); ResourceBundle res = specToOpen.GetBundle(); if (res == null) { // This means that the bundle's locale does not match // the current level of iteration for the spec. return(null); } for (int pass = 0; pass < 2; ++pass) { StringBuilder tag = new StringBuilder(); // First try either TransliteratorTo_xxx or // TransliterateFrom_xxx, then try the bidirectional // Transliterate_xxx. This precedence order is arbitrary // but must be consistent and documented. if (pass == 0) { tag.Append(direction == Transliterator.Forward ? "TransliterateTo" : "TransliterateFrom"); } else { tag.Append("Transliterate"); } tag.Append(specToFind.Get().ToUpperInvariant()); try { // The Transliterate*_xxx resource is an array of // strings of the format { <v0>, <r0>, ... }. Each // <vi> is a variant name, and each <ri> is a rule. string[] subres = res.GetStringArray(tag.ToString()); // assert(subres != null); // assert(subres.length % 2 == 0); int i = 0; if (variant.Length != 0) { for (i = 0; i < subres.Length; i += 2) { if (subres[i].Equals(variant, StringComparison.OrdinalIgnoreCase)) { break; } } } if (i < subres.Length) { // We have a match, or there is no variant and i == 0. // We have succeeded in loading a string from the // locale resources. Return the rule string which // will itself become the registry entry. // The direction is always forward for the // TransliterateTo_xxx and TransliterateFrom_xxx // items; those are unidirectional forward rules. // For the bidirectional Transliterate_xxx items, // the direction is the value passed in to this // function. TransliterationDirection dir = (pass == 0) ? Transliterator.Forward : direction; return(new Object[] { new LocaleEntry(subres[i + 1], dir) }); } } catch (MissingManifestResourceException e) { ////CLOVER:OFF if (DEBUG) { Console.Out.WriteLine("missing resource: " + e); } ////CLOVER:ON } } // If we get here we had a missing resource exception or we // failed to find a desired variant. return(null); }