use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.
the class PluralRulesConstructor method InitializeDefaultPluralRules.
/**
* InitializePluralRules (pluralRules, locales, options)
*
* @param realm
* the realm instance
* @param pluralRules
* the pluralRules object
*/
public static void InitializeDefaultPluralRules(Realm realm, PluralRulesObject pluralRules) {
/* steps 1-2 (not applicable) */
/* steps 3-6 (not applicable) */
/* steps 7-8 */
pluralRules.setType("cardinal");
/* step 9 */
PluralRulesLocaleData localeData = new PluralRulesLocaleData();
/* step 10 */
ResolvedLocale r = ResolveDefaultLocale(realm, 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) */
}
use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.
the class DateTimeFormatConstructor method InitializeDateTimeFormat.
/**
* 12.1.1 InitializeDateTimeFormat (dateTimeFormat, locales, options)
*
* @param cx
* the execution context
* @param dateTimeFormat
* the date format object
* @param locales
* the locales array
* @param opts
* the options object
*/
public static void InitializeDateTimeFormat(ExecutionContext cx, DateTimeFormatObject dateTimeFormat, Object locales, Object opts) {
/* steps 1-2 (FIXME: spec bug - unnecessary internal slot) */
/* step 3 */
Set<String> requestedLocales = CanonicalizeLocaleList(cx, locales);
/* step 4 */
ScriptObject options = ToDateTimeOptions(cx, opts, "any", "date");
/* step 6 */
String matcher = GetStringOption(cx, options, "localeMatcher", set("lookup", "best fit"), "best fit");
/* step 5, 7 */
OptionsRecord opt = new OptionsRecord(OptionsRecord.MatcherType.forName(matcher));
/* step 8 */
DateTimeFormatLocaleData localeData = new DateTimeFormatLocaleData();
/* step 9 */
ResolvedLocale r = ResolveLocale(cx.getRealm(), getAvailableLocalesLazy(cx), requestedLocales, opt, relevantExtensionKeys, localeData);
/* step 10 */
dateTimeFormat.setLocale(r.getLocale());
/* step 11 */
dateTimeFormat.setCalendar(r.getValue(ExtensionKey.ca));
/* step 12 */
dateTimeFormat.setNumberingSystem(r.getValue(ExtensionKey.nu));
/* step 13 */
String dataLocale = r.getDataLocale();
/* step 14 */
Object tz = Get(cx, options, "timeZone");
/* steps 15-16 */
String timeZone;
if (!Type.isUndefined(tz)) {
/* step 15.a */
timeZone = ToFlatString(cx, tz);
/* step 15.b */
if (!IsValidTimeZoneName(timeZone)) {
throw newRangeError(cx, Messages.Key.IntlInvalidOption, timeZone);
}
/* step 15.c */
timeZone = CanonicalizeTimeZoneName(timeZone);
} else {
/* step 16.a */
timeZone = DefaultTimeZone(cx.getRealm());
}
/* step 17 */
dateTimeFormat.setTimeZone(timeZone);
/* step 18 (moved) */
/* step 19 */
// FIXME: spec should propably define exact iteration order here
String weekday = GetStringOption(cx, options, "weekday", set("narrow", "short", "long"), null);
String era = GetStringOption(cx, options, "era", set("narrow", "short", "long"), null);
String year = GetStringOption(cx, options, "year", set("2-digit", "numeric"), null);
String month = GetStringOption(cx, options, "month", set("2-digit", "numeric", "narrow", "short", "long"), null);
String day = GetStringOption(cx, options, "day", set("2-digit", "numeric"), null);
String hour = GetStringOption(cx, options, "hour", set("2-digit", "numeric"), null);
String minute = GetStringOption(cx, options, "minute", set("2-digit", "numeric"), null);
String second = GetStringOption(cx, options, "second", set("2-digit", "numeric"), null);
String timeZoneName = GetStringOption(cx, options, "timeZoneName", set("short", "long"), null);
/* steps 20-21 (moved) */
/* step 22 */
String formatMatcher = GetStringOption(cx, options, "formatMatcher", set("basic", "best fit"), "best fit");
/* steps 23-26 (moved) */
/* step 27 */
Boolean hour12 = GetBooleanOption(cx, options, "hour12", null);
/* steps 18, 20-21, 23-26, 28-29 */
FormatMatcherRecord formatRecord = new FormatMatcherRecord(weekday, era, year, month, day, hour, minute, second, timeZoneName, hour12);
Lazy<String> pattern;
if ("basic".equals(formatMatcher)) {
pattern = new BasicFormatPattern(formatRecord, dataLocale);
} else {
pattern = new BestFitFormatPattern(formatRecord, dataLocale);
}
/* step 30 */
dateTimeFormat.setPattern(pattern);
/* step 31 */
dateTimeFormat.setBoundFormat(null);
/* step 32 (FIXME: spec bug - unnecessary internal slot) */
/* step 33 (omitted) */
}
use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.
the class CollatorConstructor method InitializeDefaultCollator.
/**
* 10.1.1 InitializeCollator (collator, locales, options)
*
* @param realm
* the realm instance
* @param collator
* the collator object
*/
public static void InitializeDefaultCollator(Realm realm, CollatorObject collator) {
/* steps 1-2 (FIXME: spec bug - unnecessary internal slot) */
/* steps 3-5 (not applicable) */
/* step 6 */
String u = "sort";
/* step 7 */
collator.setUsage(u);
/* steps 8-9 */
CollatorLocaleData localeData = new CollatorLocaleData(u);
/* steps 10-13 (not applicable) */
/* steps 14-15 */
ResolvedLocale r = ResolveDefaultLocale(realm, 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));
/* steps 21-23 */
collator.setSensitivity("variant");
/* steps 24-25 */
collator.setIgnorePunctuation(false);
/* step 26 */
collator.setBoundCompare(null);
/* step 27 (FIXME: spec bug - unnecessary internal slot) */
/* step 28 (omitted) */
}
use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.
the class DateTimeFormatConstructor method InitializeDefaultDateTimeFormat.
/**
* 12.1.1 InitializeDateTimeFormat (dateTimeFormat, locales, options)
*
* @param realm
* the realm instance
* @param dateTimeFormat
* the date format object
*/
public static void InitializeDefaultDateTimeFormat(Realm realm, DateTimeFormatObject dateTimeFormat) {
/* steps 1-2 (FIXME: spec bug - unnecessary internal slot) */
/* steps 3-7 (not applicable) */
/* step 8 */
DateTimeFormatLocaleData localeData = new DateTimeFormatLocaleData();
/* step 9 */
ResolvedLocale r = ResolveDefaultLocale(realm, relevantExtensionKeys, localeData);
/* step 10 */
dateTimeFormat.setLocale(r.getLocale());
/* step 11 */
dateTimeFormat.setCalendar(r.getValue(ExtensionKey.ca));
/* step 12 */
dateTimeFormat.setNumberingSystem(r.getValue(ExtensionKey.nu));
/* step 13 */
String dataLocale = r.getDataLocale();
/* steps 14-17 */
dateTimeFormat.setTimeZone(DefaultTimeZone(realm));
/* steps 18-29 */
FormatMatcherRecord formatRecord = new FormatMatcherRecord(null, null, "numeric", "numeric", "numeric", null, null, null, null, null);
Lazy<String> pattern = new BestFitFormatPattern(formatRecord, dataLocale);
/* step 30 */
dateTimeFormat.setPattern(pattern);
/* step 31 */
dateTimeFormat.setBoundFormat(null);
/* step 32 (FIXME: spec bug - unnecessary internal slot) */
/* step 33 (omitted) */
}
use of com.github.anba.es6draft.runtime.objects.intl.IntlAbstractOperations.ResolvedLocale in project es6draft by anba.
the class NumberFormatConstructor method InitializeNumberFormat.
/**
* 11.1.1 InitializeNumberFormat (numberFormat, locales, options)
*
* @param cx
* the execution context
* @param numberFormat
* the number format object
* @param locales
* the locales array
* @param opts
* the options object
*/
public static void InitializeNumberFormat(ExecutionContext cx, NumberFormatObject numberFormat, Object locales, Object opts) {
/* steps 1-2 (FIXME: spec bug - unnecessary internal slot) */
/* 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 7 */
String matcher = GetStringOption(cx, options, "localeMatcher", set("lookup", "best fit"), "best fit");
/* step 6, 8 */
OptionsRecord opt = new OptionsRecord(OptionsRecord.MatcherType.forName(matcher));
/* step 9 */
NumberFormatLocaleData localeData = new NumberFormatLocaleData();
/* step 10 */
ResolvedLocale r = ResolveLocale(cx.getRealm(), getAvailableLocalesLazy(cx), requestedLocales, opt, relevantExtensionKeys, localeData);
/* step 11 */
numberFormat.setLocale(r.getLocale());
/* step 12 */
numberFormat.setNumberingSystem(r.getValue(ExtensionKey.nu));
/* step 13 (not applicable) */
/* step 14 */
String s = GetStringOption(cx, options, "style", set("decimal", "percent", "currency"), "decimal");
/* step 15 */
numberFormat.setStyle(s);
/* step 16 */
String c = GetStringOption(cx, options, "currency", null, null);
/* step 17 */
if (c != null && !IsWellFormedCurrencyCode(c)) {
throw newRangeError(cx, Messages.Key.IntlInvalidCurrency, c);
}
/* step 18 */
if ("currency".equals(s) && c == null) {
throw newTypeError(cx, Messages.Key.IntlInvalidCurrency, "null");
}
/* step 19 */
int cDigits = -1;
if ("currency".equals(s)) {
c = ToUpperCase(c);
numberFormat.setCurrency(c);
cDigits = CurrencyDigits(c);
}
/* step 20 */
String cd = GetStringOption(cx, options, "currencyDisplay", set("code", "symbol", "name"), "symbol");
/* step 21 */
if ("currency".equals(s)) {
numberFormat.setCurrencyDisplay(cd);
}
/* step 22 */
int mnid = GetNumberOption(cx, options, "minimumIntegerDigits", 1, 21, 1);
/* step 23 */
numberFormat.setMinimumIntegerDigits(mnid);
/* step 24 */
int mnfdDefault = "currency".equals(s) ? cDigits : 0;
/* step 25 */
int mnfd = GetNumberOption(cx, options, "minimumFractionDigits", 0, 20, mnfdDefault);
/* step 26 */
numberFormat.setMinimumFractionDigits(mnfd);
/* step 27 */
int mxfdDefault = "currency".equals(s) ? Math.max(mnfd, cDigits) : "percent".equals(s) ? Math.max(mnfd, 0) : Math.max(mnfd, 3);
/* step 28 */
int mxfd = GetNumberOption(cx, options, "maximumFractionDigits", mnfd, 20, mxfdDefault);
/* step 29 */
numberFormat.setMaximumFractionDigits(mxfd);
/* step 30 */
Object mnsd = Get(cx, options, "minimumSignificantDigits");
/* step 31 */
Object mxsd = Get(cx, options, "maximumSignificantDigits");
/* step 32 */
if (!Type.isUndefined(mnsd) || !Type.isUndefined(mxsd)) {
int _mnsd = GetNumberOption(cx, options, "minimumSignificantDigits", 1, 21, 1);
int _mxsd = GetNumberOption(cx, options, "maximumSignificantDigits", _mnsd, 21, 21);
numberFormat.setMinimumSignificantDigits(_mnsd);
numberFormat.setMaximumSignificantDigits(_mxsd);
}
/* step 33 */
boolean g = GetBooleanOption(cx, options, "useGrouping", true);
/* step 34 */
numberFormat.setUseGrouping(g);
/* steps 35-40 (not applicable) */
/* step 41 */
numberFormat.setBoundFormat(null);
/* step 42 (FIXME: spec bug - unnecessary internal slot) */
/* step 43 (omitted) */
}
Aggregations