Example #1
0
        protected override void InitInternal(ICollection <string> locales, CollatorOptions options)
        {
            this.Usage = options.Usage;
            LocaleMatcher matcher = options.LocaleMatcher;
            Hashtable     ht      = new Hashtable();

            ht["kn"] = options.Numeric == true ? "" : null;
            ht["kf"] = IntlProviderOptions.ToStringValue(options.CaseFirst);

            this.Locale      = ResolveLocale(locales, matcher, relevantExtensionKeys, ht, out ht);
            this.Collation   = (string)ht["co"];
            this.Numeric     = String.Empty.Equals(ht["kn"]);
            this.CaseFirst   = IntlProviderOptions.ParseEnum <CollatorCaseFirst>((string)ht["kf"]);
            this.Sensitivity = options.Sensitivity;
            if (this.Sensitivity == CollatorSensitivity.Unspecified)
            {
                if (this.Usage == CollatorUsage.Sort)
                {
                    this.Sensitivity = CollatorSensitivity.Variant;
                }
                else
                {
                    this.Sensitivity = CollatorSensitivity.Variant;
                }
            }
            this.IgnorePunctuation = options.IgnorePunctuation;
            this.BoundCompare      = Literal.FunctionLiteral(this.Compare);
            this.comparer          = CultureInfo.GetCultureInfo(this.Locale).CompareInfo;
        }
Example #2
0
        public EcmaValue ToValue()
        {
            EcmaObject obj = new EcmaObject();

            obj.CreateDataPropertyOrThrow(PropertyKey.Type, IntlProviderOptions.ToStringValue(this.Type));
            obj.CreateDataPropertyOrThrow(PropertyKey.Value, this.Value);
            return(obj);
        }
Example #3
0
        protected override void InitInternal(ICollection <string> locales, DateTimeFormatOptions options)
        {
            Hashtable     ht      = new Hashtable();
            LocaleMatcher matcher = options.LocaleMatcher;

            ht["ca"] = options.Calendar;
            ht["nu"] = options.NumberingSystem;

            bool?     hour12    = options.Hour12;
            HourCycle hourCycle = options.HourCycle;

            if (hour12 != default)
            {
                hourCycle = HourCycle.Unspecified;
            }
            ht["hc"]             = IntlProviderOptions.ToStringValue(hourCycle);
            this.Locale          = ResolveLocale(locales, matcher, relevantExtensionKeys, ht, out ht);
            this.Calendar        = (string)ht["ca"];
            this.NumberingSystem = (string)ht["nu"];

            string tz = options.TimeZone;

            if (tz != null)
            {
                if (!IntlUtility.IsValidTimeZoneName(tz))
                {
                    throw new EcmaRangeErrorException("Invalid time zone specified: {0}", tz);
                }
                this.TimeZone = IntlUtility.CanonicalizeTimeZoneName(tz);
            }
            else
            {
                this.TimeZone = IntlContext.DefaultTimeZone;
            }
            this.FormatMatcher = options.FormatMatcher;

            DateTimePartStyles styles         = new DateTimePartStyles(options);
            HourCycle          finalHourCycle = IntlProviderOptions.ParseEnum <HourCycle>((string)ht["hc"]);

            this.HourCycle = hour12 == default ? finalHourCycle : NormalizeHourCycle(finalHourCycle, hour12.Value);
            this.Hour12    = this.HourCycle == HourCycle.Hour11 || this.HourCycle == HourCycle.Hour12;

            this.format             = GetBestFormat(styles);
            this.calendar           = IntlUtility.SupportedCalendars[this.Calendar];
            this.DateTimePartStyles = format.Styles;
            this.BoundFormat        = Literal.FunctionLiteral(this.FormatInternal);
        }
Example #4
0
 public EcmaValue Select(EcmaValue value)
 {
     return(IntlProviderOptions.ToStringValue(ResolveCategory(value.ToNumber().ToDouble())));
 }