예제 #1
0
 protected override void InitInternal(ICollection <string> locales, ListFormatOptions options)
 {
     this.Locale      = ResolveLocale(locales, options.LocaleMatcher);
     this.Type        = options.Type;
     this.Style       = options.Style;
     this.BoundFormat = Literal.FunctionLiteral(this.FormatInternal);
 }
예제 #2
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;
        }
예제 #3
0
        protected override void InitInternal(ICollection <string> locales, RelativeTimeFormatOptions options)
        {
            LocaleMatcher matcher = options.LocaleMatcher;
            Hashtable     ht      = new Hashtable();

            ht["nu"]             = options.NumberingSystem;
            this.Locale          = ResolveLocale(locales, matcher, relevantExtensionKeys, ht, out ht);
            this.NumberingSystem = (string)ht["nu"];
            this.Style           = options.Style;
            this.Numeric         = options.Numeric;
            this.NumberFormat    = new NumberFormat(this.Locale);
            this.BoundFormat     = Literal.FunctionLiteral(this.FormatInternal);
        }
예제 #4
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);
        }
예제 #5
0
 public static EcmaValue CreateObject(Func <EcmaValue> toString = null, Func <EcmaValue> valueOf = null, Func <EcmaValue> toPrimitive = null)
 {
     return(CreateObject(toString == null ? default(EcmaValue?) : Literal.FunctionLiteral(toString), valueOf == null ? default(EcmaValue?) : Literal.FunctionLiteral(valueOf), toPrimitive == null ? default(EcmaValue?) : Literal.FunctionLiteral(toPrimitive)));
 }
예제 #6
0
        protected override void InitInternal(ICollection <string> locales, NumberFormatOptions options)
        {
            Hashtable     ht            = new Hashtable();
            LocaleMatcher localeMatcher = options.LocaleMatcher;

            ht["nu"]             = options.NumberingSystem;
            this.Locale          = ResolveLocale(locales, localeMatcher, relevantExtensionKeys, ht, out ht);
            this.NumberingSystem = (string)ht["nu"];
            this.Style           = options.Style;

            string currency = options.Currency;

            if (currency != null)
            {
                if (!IntlUtility.IsWellFormedCurrencyCode(currency))
                {
                    throw new EcmaRangeErrorException("Invalid currency codes: {0}", currency);
                }
                this.Currency = currency;
            }
            this.CurrencyDisplay = options.CurrencyDisplay;
            this.CurrencySign    = options.CurrencySign;

            this.Unit = options.Unit;
            if (this.Unit != null)
            {
                if (!IntlUtility.IsWellFormedUnitIdentifier(this.Unit))
                {
                    throw new EcmaRangeErrorException("Invalid unit identifier: {0}", this.Unit);
                }
            }
            this.UnitDisplay = options.UnitDisplay;

            NumberFormatInfo numberFormat = CultureInfo.GetCultureInfo(this.Locale).NumberFormat;
            int defaultMinFractionDigits, defaultMaxFractionDigits;

            if (this.Style == NumberStyle.Currency)
            {
                if (currency == null)
                {
                    throw new EcmaTypeErrorException("Currency code is required with currency style");
                }
                defaultMinFractionDigits = numberFormat.CurrencyDecimalDigits;
                defaultMaxFractionDigits = numberFormat.CurrencyDecimalDigits;
            }
            else
            {
                if (this.Style == NumberStyle.Unit && this.Unit == null)
                {
                    throw new EcmaTypeErrorException("Unit is required with unit style");
                }
                defaultMinFractionDigits = 0;
                defaultMaxFractionDigits = this.Style == NumberStyle.Percent ? 0 : 3;
            }
            this.Notation = options.Notation;
            this.Digits   = options.GetNumberFormatDigitOptions(defaultMinFractionDigits, defaultMaxFractionDigits, this.Notation);

            NumberCompactDisplayFormat compactDisplay = options.CompactDisplay;

            if (this.Notation == NumberNotation.Compact)
            {
                this.CompactDisplay = compactDisplay;
            }
            this.UseGrouping    = options.UseGrouping;
            this.SignDisplay    = options.SignDisplay;
            this.BoundFormat    = Literal.FunctionLiteral(this.FormatInternal);
            this.formatProvider = CldrNumberFormat.GetFormat(this.Locale, this.NumberingSystem);
            this.pluralRules    = CldrPluralRules.Resolve(PluralRuleType.Cardinal, this.Locale);

            NumberFormatInfo formatter = formatProvider.FormatProvider;

            this.symbolType = new Dictionary <string, FormattedPartType> {
                [formatter.PositiveSign]           = FormattedPartType.PlusSign,
                [formatter.NegativeSign]           = FormattedPartType.MinusSign,
                [formatter.NumberGroupSeparator]   = FormattedPartType.Group,
                [formatter.NumberDecimalSeparator] = FormattedPartType.Decimal,
                [formatter.PercentSymbol]          = FormattedPartType.PercentSign,
                ["E"] = FormattedPartType.ExponentSeparator
            };
            this.styleFormats = GetStyleFormat().ToDictionary(v => v.Key, v => v.Value);
            if (this.Notation == NumberNotation.Compact)
            {
                this.compactNotations = formatProvider.GetCompactNotationFormats(this.CompactDisplay);
            }
            else if (this.Notation == NumberNotation.Scientific)
            {
                this.notationFormats = formatProvider.GetScientificNotationFormat().ToDisplayFormat(this);
            }
            else
            {
                this.notationFormats = formatProvider.GetDecimalNotationFormat().ToDisplayFormat(this);
            }
        }