Search in sources :

Example 6 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class UtilityTest method TestCaseInsensitiveString.

@Test
public void TestCaseInsensitiveString() {
    CaseInsensitiveString str1 = new CaseInsensitiveString("ThIs is A tEst");
    CaseInsensitiveString str2 = new CaseInsensitiveString("This IS a test");
    if (!str1.equals(str2) || !str1.toString().equals(str1.getString()) || str1.toString().equals(str2.toString())) {
        errln("FAIL: str1(" + str1 + ") != str2(" + str2 + ")");
    }
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) Test(org.junit.Test)

Example 7 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class Transliterator method getDisplayName.

/**
 * Returns a name for this transliterator that is appropriate for
 * display to the user in the given locale.  This name is taken
 * from the locale resource data in the standard manner of the
 * <code>java.text</code> package.
 *
 * <p>If no localized names exist in the system resource bundles,
 * a name is synthesized using a localized
 * <code>MessageFormat</code> pattern from the resource data.  The
 * arguments to this pattern are an integer followed by one or two
 * strings.  The integer is the number of strings, either 1 or 2.
 * The strings are formed by splitting the ID for this
 * transliterator at the first '-'.  If there is no '-', then the
 * entire ID forms the only string.
 * @param inLocale the ULocale in which the display name should be
 * localized.
 * @see java.text.MessageFormat
 */
public static String getDisplayName(String id, ULocale inLocale) {
    // Resource bundle containing display name keys and the
    // RB_RULE_BASED_IDS array.
    // 
    // If we ever integrate this with the Sun JDK, the resource bundle
    // root will change to sun.text.resources.LocaleElements
    ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_TRANSLIT_BASE_NAME, inLocale);
    // Normalize the ID
    String[] stv = TransliteratorIDParser.IDtoSTV(id);
    if (stv == null) {
        // No target; malformed id
        return "";
    }
    String ID = stv[0] + '-' + stv[1];
    if (stv[2] != null && stv[2].length() > 0) {
        ID = ID + '/' + stv[2];
    }
    // Use the registered display name, if any
    String n = displayNameCache.get(new CaseInsensitiveString(ID));
    if (n != null) {
        return n;
    }
    // exists.
    try {
        return bundle.getString(RB_DISPLAY_NAME_PREFIX + ID);
    } catch (MissingResourceException e) {
    }
    try {
        // Construct the formatter first; if getString() fails
        // we'll exit the try block
        MessageFormat format = new MessageFormat(bundle.getString(RB_DISPLAY_NAME_PATTERN));
        // Construct the argument array
        Object[] args = new Object[] { Integer.valueOf(2), stv[0], stv[1] };
        // Use display names for the scripts, if they exist
        for (int j = 1; j <= 2; ++j) {
            try {
                args[j] = bundle.getString(RB_SCRIPT_DISPLAY_NAME_PREFIX + (String) args[j]);
            } catch (MissingResourceException e) {
            }
        }
        // Format it using the pattern in the resource
        return (stv[2].length() > 0) ? (format.format(args) + '/' + stv[2]) : format.format(args);
    } catch (MissingResourceException e2) {
    }
    // been deleted from the root RB_LOCALE_ELEMENTS resource.
    throw new RuntimeException();
}
Also used : MessageFormat(java.text.MessageFormat) MissingResourceException(java.util.MissingResourceException) ICUResourceBundle(android.icu.impl.ICUResourceBundle) CaseInsensitiveString(android.icu.util.CaseInsensitiveString) CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Example 8 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class Transliterator method unregister.

/**
 * Unregisters a transliterator or class.  This may be either
 * a system transliterator or a user transliterator or class.
 *
 * @param ID the ID of the transliterator or class
 * @see #registerClass
 */
public static void unregister(String ID) {
    displayNameCache.remove(new CaseInsensitiveString(ID));
    registry.remove(ID);
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Example 9 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class TransliteratorIDParser method specsToSpecialInverse.

/**
 * Given a Specs object, return a SingleID representing the
 * special inverse of that ID.  If there is no special inverse
 * then return null.
 * @return a SingleID or null.  Returned object always has
 * 'filter' field of null.
 */
private static SingleID specsToSpecialInverse(Specs specs) {
    if (!specs.source.equalsIgnoreCase(ANY)) {
        return null;
    }
    String inverseTarget = SPECIAL_INVERSES.get(new CaseInsensitiveString(specs.target));
    if (inverseTarget != null) {
        // If the original ID contained "Any-" then make the
        // special inverse "Any-Foo"; otherwise make it "Foo".
        // So "Any-NFC" => "Any-NFD" but "NFC" => "NFD".
        StringBuilder buf = new StringBuilder();
        if (specs.filter != null) {
            buf.append(specs.filter);
        }
        if (specs.sawSource) {
            buf.append(ANY).append(TARGET_SEP);
        }
        buf.append(inverseTarget);
        String basicID = ANY + TARGET_SEP + inverseTarget;
        if (specs.variant != null) {
            buf.append(VARIANT_SEP).append(specs.variant);
            basicID = basicID + VARIANT_SEP + specs.variant;
        }
        return new SingleID(buf.toString(), basicID);
    }
    return null;
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Aggregations

CaseInsensitiveString (android.icu.util.CaseInsensitiveString)9 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ICUResourceBundle (android.icu.impl.ICUResourceBundle)1 MessageFormat (java.text.MessageFormat)1 HashMap (java.util.HashMap)1 MissingResourceException (java.util.MissingResourceException)1 Test (org.junit.Test)1