Search in sources :

Example 6 with ResolvedLocale

use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.

the class NumberFormatConstructor method InitializeDefaultNumberFormat.

/**
     * 11.1.1 InitializeNumberFormat (numberFormat, locales, options)
     * 
     * @param realm
     *            the realm instance
     * @param numberFormat
     *            the number format object
     */
public static void InitializeDefaultNumberFormat(Realm realm, NumberFormatObject numberFormat) {
    /* steps 1-2 (FIXME: spec bug - unnecessary internal slot) */
    /* steps 3-8 (not applicable) */
    /* step 9 */
    NumberFormatLocaleData localeData = new NumberFormatLocaleData();
    /* step 10 */
    ResolvedLocale r = ResolveDefaultLocale(realm, relevantExtensionKeys, localeData);
    /* step 11 */
    numberFormat.setLocale(r.getLocale());
    /* step 12 */
    numberFormat.setNumberingSystem(r.getValue(ExtensionKey.nu));
    /* step 13 (not applicable) */
    /* steps 14-15 */
    numberFormat.setStyle("decimal");
    /* steps 16-21 (not applicable) */
    /* steps 22-23 */
    numberFormat.setMinimumIntegerDigits(1);
    /* steps 24-26 */
    numberFormat.setMinimumFractionDigits(0);
    /* steps 27-29 */
    numberFormat.setMaximumFractionDigits(3);
    /* steps 30-32 (not applicable) */
    /* steps 33-34 */
    numberFormat.setUseGrouping(true);
    /* steps 35-40 (not applicable) */
    /* step 41 */
    numberFormat.setBoundFormat(null);
/* step 42 (FIXME: spec bug - unnecessary internal slot) */
/* step 43 (omitted) */
}
Also used : ResolvedLocale(com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale)

Example 7 with ResolvedLocale

use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.

the class PluralRulesConstructor method InitializePluralRules.

/**
     * InitializePluralRules (pluralRules, locales, options)
     * 
     * @param cx
     *            the execution context
     * @param pluralRules
     *            the pluralRules object
     * @param locales
     *            the locales array
     * @param opts
     *            the options object
     */
public static void InitializePluralRules(ExecutionContext cx, PluralRulesObject pluralRules, Object locales, Object opts) {
    /* steps 1-2 (not applicable) */
    /* step 3 */
    Set<String> requestedLocales = CanonicalizeLocaleList(cx, locales);
    /* steps 4-5 */
    ScriptObject options;
    if (Type.isUndefined(opts)) {
        options = ObjectCreate(cx, Intrinsics.ObjectPrototype);
    } else {
        options = ToObject(cx, opts);
    }
    /* step 6 */
    OptionsRecord opt = new OptionsRecord(OptionsRecord.MatcherType.forName("lookup"));
    /* step 7 */
    String s = GetStringOption(cx, options, "type", set("cardinal", "ordinal"), "cardinal");
    /* step 8 */
    pluralRules.setType(s);
    /* step 9 */
    PluralRulesLocaleData localeData = new PluralRulesLocaleData();
    /* step 10 */
    ResolvedLocale r = ResolveLocale(cx.getRealm(), getAvailableLocalesLazy(cx), requestedLocales, opt, relevantExtensionKeys, localeData);
    /* step 11 */
    pluralRules.setLocale(r.getLocale());
    /* steps 12-16 (not applicable) */
    /* step 17 */
    pluralRules.setBoundResolve(null);
/* step 18 (not applicable) */
/* step 19 (return) */
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OptionsRecord(com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.OptionsRecord) ResolvedLocale(com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale)

Example 8 with ResolvedLocale

use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.

the class CollatorConstructor method InitializeCollator.

/**
     * 10.1.1 InitializeCollator (collator, locales, options)
     * 
     * @param cx
     *            the execution context
     * @param collator
     *            the collator object
     * @param locales
     *            the locales array
     * @param opts
     *            the options object
     */
public static void InitializeCollator(ExecutionContext cx, CollatorObject collator, Object locales, Object opts) {
    /* steps 1-2 (FIXME: spec bug - unnecessary internal slot) */
    /* step 3 */
    Set<String> requestedLocals = CanonicalizeLocaleList(cx, locales);
    /* steps 4-5 */
    ScriptObject options;
    if (Type.isUndefined(opts)) {
        options = ObjectCreate(cx, Intrinsics.ObjectPrototype);
    } else {
        options = ToObject(cx, opts);
    }
    /* step 6 */
    String u = GetStringOption(cx, options, "usage", set("sort", "search"), "sort");
    /* step 7 */
    collator.setUsage(u);
    /* steps 8-9 */
    CollatorLocaleData localeData = new CollatorLocaleData(u);
    /* step 11 */
    String matcher = GetStringOption(cx, options, "localeMatcher", set("lookup", "best fit"), "best fit");
    /* steps 10, 12 */
    OptionsRecord opt = new OptionsRecord(OptionsRecord.MatcherType.forName(matcher));
    // FIXME: spec should propably define exact iteration order here
    /* step 13 (kn-numeric) */
    Boolean numeric = GetBooleanOption(cx, options, "numeric", null);
    if (numeric != null) {
        opt.set(ExtensionKey.kn, numeric.toString());
    }
    /* step 13 (kf-caseFirst) */
    String caseFirst = GetStringOption(cx, options, "caseFirst", set("upper", "lower", "false"), null);
    if (caseFirst != null) {
        opt.set(ExtensionKey.kf, caseFirst);
    }
    /* steps 14-15 */
    ResolvedLocale r = ResolveLocale(cx.getRealm(), getAvailableLocalesLazy(cx), requestedLocals, opt, relevantExtensionKeys, localeData);
    /* step 16 */
    collator.setLocale(r.getLocale());
    /* steps 17-20 (co-collation) */
    String collation = r.getValue(ExtensionKey.co);
    collator.setCollation(collation != null ? collation : "default");
    /* steps 17-20 (kn-numeric) */
    collator.setNumeric("true".equals(r.getValue(ExtensionKey.kn)));
    /* steps 17-20 (kf-caseFirst) */
    collator.setCaseFirst(r.getValue(ExtensionKey.kf));
    /* step 21 */
    String s = GetStringOption(cx, options, "sensitivity", set("base", "accent", "case", "variant"), null);
    /* step 22 */
    if (s == null) {
        // The specification differentiates between "sort" and "search" usage, but effectively
        // you'll end up with "variant" in both cases, so take the short path here.
        s = "variant";
    }
    /* step 23 */
    collator.setSensitivity(s);
    /* step 24 */
    boolean ip = GetBooleanOption(cx, options, "ignorePunctuation", false);
    /* step 25 */
    collator.setIgnorePunctuation(ip);
    /* step 26 */
    collator.setBoundCompare(null);
/* step 27 (FIXME: spec bug - unnecessary internal slot) */
/* step 28 (omitted) */
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OptionsRecord(com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.OptionsRecord) ResolvedLocale(com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale)

Aggregations

ResolvedLocale (com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale)8 OptionsRecord (com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.OptionsRecord)4 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)4 ToObject (com.github.anba.es6draft.runtime.AbstractOperations.ToObject)1 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1