Search in sources :

Example 46 with Collator

use of java.text.Collator in project hackpad by dropbox.

the class NativeString method execIdCall.

@Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
    if (!f.hasTag(STRING_TAG)) {
        return super.execIdCall(f, cx, scope, thisObj, args);
    }
    int id = f.methodId();
    again: for (; ; ) {
        switch(id) {
            case ConstructorId_charAt:
            case ConstructorId_charCodeAt:
            case ConstructorId_indexOf:
            case ConstructorId_lastIndexOf:
            case ConstructorId_split:
            case ConstructorId_substring:
            case ConstructorId_toLowerCase:
            case ConstructorId_toUpperCase:
            case ConstructorId_substr:
            case ConstructorId_concat:
            case ConstructorId_slice:
            case ConstructorId_equalsIgnoreCase:
            case ConstructorId_match:
            case ConstructorId_search:
            case ConstructorId_replace:
            case ConstructorId_localeCompare:
            case ConstructorId_toLocaleLowerCase:
                {
                    if (args.length > 0) {
                        thisObj = ScriptRuntime.toObject(scope, ScriptRuntime.toString(args[0]));
                        Object[] newArgs = new Object[args.length - 1];
                        for (int i = 0; i < newArgs.length; i++) newArgs[i] = args[i + 1];
                        args = newArgs;
                    } else {
                        thisObj = ScriptRuntime.toObject(scope, ScriptRuntime.toString(thisObj));
                    }
                    id = -id;
                    continue again;
                }
            case ConstructorId_fromCharCode:
                {
                    int N = args.length;
                    if (N < 1)
                        return "";
                    StringBuffer sb = new StringBuffer(N);
                    for (int i = 0; i != N; ++i) {
                        sb.append(ScriptRuntime.toUint16(args[i]));
                    }
                    return sb.toString();
                }
            case Id_constructor:
                {
                    String s = (args.length >= 1) ? ScriptRuntime.toString(args[0]) : "";
                    if (thisObj == null) {
                        // new String(val) creates a new String object.
                        return new NativeString(s);
                    }
                    // String(val) converts val to a string value.
                    return s;
                }
            case Id_toString:
            case Id_valueOf:
                // ECMA 15.5.4.2: 'the toString function is not generic.
                return realThis(thisObj, f).string;
            case Id_toSource:
                {
                    String s = realThis(thisObj, f).string;
                    return "(new String(\"" + ScriptRuntime.escapeString(s) + "\"))";
                }
            case Id_charAt:
            case Id_charCodeAt:
                {
                    // See ECMA 15.5.4.[4,5]
                    String target = ScriptRuntime.toString(thisObj);
                    double pos = ScriptRuntime.toInteger(args, 0);
                    if (pos < 0 || pos >= target.length()) {
                        if (id == Id_charAt)
                            return "";
                        else
                            return ScriptRuntime.NaNobj;
                    }
                    char c = target.charAt((int) pos);
                    if (id == Id_charAt)
                        return String.valueOf(c);
                    else
                        return ScriptRuntime.wrapInt(c);
                }
            case Id_indexOf:
                return ScriptRuntime.wrapInt(js_indexOf(ScriptRuntime.toString(thisObj), args));
            case Id_lastIndexOf:
                return ScriptRuntime.wrapInt(js_lastIndexOf(ScriptRuntime.toString(thisObj), args));
            case Id_split:
                return ScriptRuntime.checkRegExpProxy(cx).js_split(cx, scope, ScriptRuntime.toString(thisObj), args);
            case Id_substring:
                return js_substring(cx, ScriptRuntime.toString(thisObj), args);
            case Id_toLowerCase:
                // See ECMA 15.5.4.11
                return ScriptRuntime.toString(thisObj).toLowerCase(ScriptRuntime.ROOT_LOCALE);
            case Id_toUpperCase:
                // See ECMA 15.5.4.12
                return ScriptRuntime.toString(thisObj).toUpperCase(ScriptRuntime.ROOT_LOCALE);
            case Id_substr:
                return js_substr(ScriptRuntime.toString(thisObj), args);
            case Id_concat:
                return js_concat(ScriptRuntime.toString(thisObj), args);
            case Id_slice:
                return js_slice(ScriptRuntime.toString(thisObj), args);
            case Id_bold:
                return tagify(thisObj, "b", null, null);
            case Id_italics:
                return tagify(thisObj, "i", null, null);
            case Id_fixed:
                return tagify(thisObj, "tt", null, null);
            case Id_strike:
                return tagify(thisObj, "strike", null, null);
            case Id_small:
                return tagify(thisObj, "small", null, null);
            case Id_big:
                return tagify(thisObj, "big", null, null);
            case Id_blink:
                return tagify(thisObj, "blink", null, null);
            case Id_sup:
                return tagify(thisObj, "sup", null, null);
            case Id_sub:
                return tagify(thisObj, "sub", null, null);
            case Id_fontsize:
                return tagify(thisObj, "font", "size", args);
            case Id_fontcolor:
                return tagify(thisObj, "font", "color", args);
            case Id_link:
                return tagify(thisObj, "a", "href", args);
            case Id_anchor:
                return tagify(thisObj, "a", "name", args);
            case Id_equals:
            case Id_equalsIgnoreCase:
                {
                    String s1 = ScriptRuntime.toString(thisObj);
                    String s2 = ScriptRuntime.toString(args, 0);
                    return ScriptRuntime.wrapBoolean((id == Id_equals) ? s1.equals(s2) : s1.equalsIgnoreCase(s2));
                }
            case Id_match:
            case Id_search:
            case Id_replace:
                {
                    int actionType;
                    if (id == Id_match) {
                        actionType = RegExpProxy.RA_MATCH;
                    } else if (id == Id_search) {
                        actionType = RegExpProxy.RA_SEARCH;
                    } else {
                        actionType = RegExpProxy.RA_REPLACE;
                    }
                    return ScriptRuntime.checkRegExpProxy(cx).action(cx, scope, thisObj, args, actionType);
                }
            // ECMA-262 1 5.5.4.9
            case Id_localeCompare:
                {
                    // For now, create and configure a collator instance. I can't
                    // actually imagine that this'd be slower than caching them
                    // a la ClassCache, so we aren't trying to outsmart ourselves
                    // with a caching mechanism for now.
                    Collator collator = Collator.getInstance(cx.getLocale());
                    collator.setStrength(Collator.IDENTICAL);
                    collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
                    return ScriptRuntime.wrapNumber(collator.compare(ScriptRuntime.toString(thisObj), ScriptRuntime.toString(args, 0)));
                }
            case Id_toLocaleLowerCase:
                {
                    return ScriptRuntime.toString(thisObj).toLowerCase(cx.getLocale());
                }
            case Id_toLocaleUpperCase:
                {
                    return ScriptRuntime.toString(thisObj).toUpperCase(cx.getLocale());
                }
            case Id_trim:
                {
                    String str = ScriptRuntime.toString(thisObj);
                    char[] chars = str.toCharArray();
                    int start = 0;
                    while (start < chars.length && ScriptRuntime.isJSWhitespaceOrLineTerminator(chars[start])) {
                        start++;
                    }
                    int end = chars.length;
                    while (end > start && ScriptRuntime.isJSWhitespaceOrLineTerminator(chars[end - 1])) {
                        end--;
                    }
                    return str.substring(start, end);
                }
        }
        throw new IllegalArgumentException(String.valueOf(id));
    }
}
Also used : Collator(java.text.Collator)

Example 47 with Collator

use of java.text.Collator in project ADWLauncher2 by boombuler.

the class Preferences method getAppNameComparator.

private Comparator<IconItemInfo> getAppNameComparator() {
    final IconCache myIconCache = mLauncher.getIconCache();
    final Collator sCollator = Collator.getInstance();
    return new Comparator<IconItemInfo>() {

        @Override
        public final int compare(IconItemInfo a, IconItemInfo b) {
            return sCollator.compare(a.getTitle(myIconCache), b.getTitle(myIconCache));
        }
    };
}
Also used : IconCache(org.adw.launcher2.IconCache) IconItemInfo(org.adw.launcher2.IconItemInfo) Collator(java.text.Collator) Comparator(java.util.Comparator)

Example 48 with Collator

use of java.text.Collator in project Android-Terminal-Emulator by jackpal.

the class Term method makePathFromBundle.

private String makePathFromBundle(Bundle extras) {
    if (extras == null || extras.size() == 0) {
        return "";
    }
    String[] keys = new String[extras.size()];
    keys = extras.keySet().toArray(keys);
    Collator collator = Collator.getInstance(Locale.US);
    Arrays.sort(keys, collator);
    StringBuilder path = new StringBuilder();
    for (String key : keys) {
        String dir = extras.getString(key);
        if (dir != null && !dir.equals("")) {
            path.append(dir);
            path.append(":");
        }
    }
    return path.substring(0, path.length() - 1);
}
Also used : Collator(java.text.Collator)

Example 49 with Collator

use of java.text.Collator in project j2objc by google.

the class CollatorTest method test_equalsLjava_lang_Object.

/**
	 * @tests java.text.Collator#equals(java.lang.Object)
	 */
public void test_equalsLjava_lang_Object() {
    Collator c = Collator.getInstance(Locale.ENGLISH);
    Collator c2 = (Collator) c.clone();
    assertTrue("Cloned collators not equal", c.equals(c2));
    c2.setStrength(Collator.SECONDARY);
    assertTrue("Collators with different strengths equal", !c.equals(c2));
}
Also used : Collator(java.text.Collator)

Example 50 with Collator

use of java.text.Collator in project j2objc by google.

the class CollatorTest method failing_test_getAvailableLocales.

/**
     * @tests java.text.Collator#getAvailableLocales()
     */
//FIXME This test fails on Harmony ClassLibrary
public void failing_test_getAvailableLocales() {
    Locale[] locales = Collator.getAvailableLocales();
    assertTrue("No locales", locales.length > 0);
    boolean english = false, german = false;
    for (int i = locales.length; --i >= 0; ) {
        if (locales[i].equals(Locale.ENGLISH))
            english = true;
        if (locales[i].equals(Locale.GERMAN))
            german = true;
        // Output the working locale to help diagnose a hang
        Collator c1 = Collator.getInstance(locales[i]);
        assertTrue("Doesn't work", c1.compare("a", "b") < 0);
        assertTrue("Wrong decomposition", c1.getDecomposition() == Collator.NO_DECOMPOSITION);
        assertTrue("Wrong strength", c1.getStrength() == Collator.TERTIARY);
    }
    assertTrue("Missing locales", english && german);
}
Also used : Locale(java.util.Locale) Collator(java.text.Collator)

Aggregations

Collator (java.text.Collator)70 ArrayList (java.util.ArrayList)14 RuleBasedCollator (java.text.RuleBasedCollator)8 HashMap (java.util.HashMap)7 Comparator (java.util.Comparator)5 List (java.util.List)5 GraphObject (com.facebook.model.GraphObject)4 Context (android.content.Context)3 InputMethodInfo (android.view.inputmethod.InputMethodInfo)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 Locale (java.util.Locale)3 Entry (java.util.Map.Entry)3 SharedPreferences (android.content.SharedPreferences)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageInfo (android.content.pm.PackageInfo)2 DBObject (com.mongodb.DBObject)2 SMSException (com.sun.identity.sm.SMSException)2 ServiceSchema (com.sun.identity.sm.ServiceSchema)2 AutoPilot (com.ximpleware.AutoPilot)2