Пример #1
0
        /// <summary>
        /// Determines whether the format string is valid.
        /// </summary>
        /// <param name="token">The token to evaluate.</param>
        /// <returns>
        /// <c>true</c> if the specified format contains the text; otherwise, <c>false</c>.
        /// </returns>
        internal static bool EvaluateFormat(string token)
        {
            if ((token == null) || (token == string.Empty))
            {
                return(false);
            }
            string str = DefaultTokens.TrimSquareBracket(token);

            if ((str == null) || (str == string.Empty))
            {
                return(false);
            }
            str = str.ToLower();
            char ch = '\0';

            for (int i = 0; i < str.Length; i++)
            {
                if (ch == '\0')
                {
                    ch = str[i];
                }
                if (((ch != HoursABSContent) && (ch != MinuteABSContent)) && (ch != SecondABSContent))
                {
                    return(false);
                }
                if (ch != str[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Dt.Cells.Data.NumberFormatDigital" /> class.
        /// </summary>
        /// <param name="format">The format.</param>
        /// <param name="partLocaleID">The part locale ID.</param>
        /// <param name="dbNumberFormatPart">The number format part.</param>
        /// <param name="culture">The culture.</param>
        public NumberFormatDigital(string format, object partLocaleID, object dbNumberFormatPart, CultureInfo culture) : base(partLocaleID, dbNumberFormatPart, culture)
        {
            this.excelFormatString = string.Empty;
            string s = NumberFormatBase.TrimNotSupportSymbol(format);

            this.fullFormatString  = DefaultTokens.Filter(s, DefaultTokens.LeftSquareBracket, DefaultTokens.RightSquareBracket);
            this.excelFormatString = s;
            if (partLocaleID != null)
            {
                string str2 = s;
                s = DefaultTokens.ReplaceKeyword(str2, base.PartLocaleID.OriginalToken, base.PartLocaleID.CurrencySymbol);
            }
            if (base.PartDBNumberFormat != null)
            {
                this.excelFormatString = DefaultTokens.ReplaceKeyword(this.excelFormatString, base.PartDBNumberFormat.OriginalToken, base.PartDBNumberFormat.ToString());
            }
            s = DefaultTokens.Filter(s, DefaultTokens.LeftSquareBracket, DefaultTokens.RightSquareBracket);
            if (s.IndexOf(DefaultTokens.SolidusSign) > -1)
            {
                s = s.Replace(DefaultTokens.QuestionMark, DefaultTokens.Zero);
                string[] strArray = DefaultTokens.Split(s, DefaultTokens.SolidusSign);
                if ((strArray != null) && (strArray.Length == 2))
                {
                    this.fractionDenominatorFormat = strArray[1];
                    string[] integerAndNumeratorParts = this.GetIntegerAndNumeratorParts(strArray[0]);
                    if ((integerAndNumeratorParts != null) && (integerAndNumeratorParts.Length == 3))
                    {
                        this.fractionIntegerFormat   = integerAndNumeratorParts[0];
                        this.constString             = integerAndNumeratorParts[1];
                        this.fractionNumeratorFormat = integerAndNumeratorParts[2];
                    }
                }
            }
            this.numberFormatString = s;
        }
Пример #3
0
 /// <summary>
 /// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </returns>
 public override string ToString()
 {
     if (this.content != null)
     {
         return(DefaultTokens.AddSquareBracket(this.content));
     }
     return(string.Empty);
 }
Пример #4
0
 /// <summary>
 /// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </returns>
 public override string ToString()
 {
     if (this.type <= -1)
     {
         throw new FormatException();
     }
     return(DefaultTokens.AddSquareBracket("DBNum" + ((int)this.type)));
 }
Пример #5
0
        /// <summary>
        /// Fixes the format.
        /// </summary>
        /// <param name="format">The format</param>
        /// <returns>Returns the fixed format string</returns>
        string FixFormat(string format)
        {
            string        str     = format;
            StringBuilder builder = new StringBuilder();
            bool          flag    = false;
            char          ch2     = HoursSingleDigit[0];

            if (str.IndexOf(((char)ch2).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase) <= -1)
            {
                char ch3 = SecondSingleDigit[0];
                str.IndexOf(((char)ch3).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase);
            }
            char ch4 = YearTwoDigit[0];

            if (str.IndexOf(((char)ch4).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase) <= -1)
            {
                char ch5 = DaySingleDigit[0];
                str.IndexOf(((char)ch5).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase);
            }
            for (int i = 0; i < str.Length; i++)
            {
                char c = str[i];
                if (c == '"')
                {
                    flag = !flag;
                }
                else if (!flag)
                {
                    switch (c)
                    {
                    case 'Y':
                    case 'D':
                    case 'S':
                    case 'E':
                    case 'G':
                        c = char.ToLower(c);
                        goto Label_010B;
                    }
                    if (c == 'M')
                    {
                        if (i > 1)
                        {
                            if (!DefaultTokens.IsEquals('A', str[i - 1], true) && !DefaultTokens.IsEquals('P', str[i - 1], true))
                            {
                                c = char.ToLower(c);
                            }
                        }
                        else
                        {
                            c = char.ToLower(c);
                        }
                    }
                }
Label_010B:
                builder.Append(c);
            }
            return(builder.ToString());
        }
Пример #6
0
        /// <summary>
        /// Numbers the string.
        /// </summary>
        /// <param name="s">The string to replace</param>
        /// <param name="dbNumber">The db number</param>
        /// <param name="isNumber">Indicates whether the number should be formatted by number rules</param>
        /// <returns>Returns the formatted value</returns>
        internal string ReplaceNumberString(string s, DBNumber dbNumber, bool isNumber)
        {
            if ((s == null) || (s == string.Empty))
            {
                return(s);
            }
            string str        = s;
            string str2       = s;
            int    num        = -1;
            int    startIndex = -1;
            bool   flag       = false;

            for (int i = s.Length - 1; i >= 0; i--)
            {
                char c = str2[i];
                if (char.IsNumber(c) || (DefaultTokens.IsEquals(c, DefaultTokens.DecimalSeparator, false) && !flag))
                {
                    if (DefaultTokens.IsEquals(c, DefaultTokens.DecimalSeparator, false))
                    {
                        flag = true;
                    }
                    if (num == -1)
                    {
                        num = i;
                    }
                    startIndex = i;
                }
                else if ((startIndex > -1) && (num > -1))
                {
                    double num4;
                    string str3 = str2.Substring(startIndex, (num - startIndex) + 1);
                    if (double.TryParse(str3, out num4))
                    {
                        string str4 = this.NumberString(str3, dbNumber, isNumber);
                        str = str.Remove(startIndex, (num - startIndex) + 1).Insert(startIndex, str4);
                    }
                    num        = -1;
                    startIndex = -1;
                    flag       = false;
                }
            }
            if ((startIndex > -1) && (num > -1))
            {
                double num5;
                string str5 = str2.Substring(startIndex, (num - startIndex) + 1);
                if (double.TryParse(str5, out num5))
                {
                    string str6 = this.NumberString(str5, dbNumber, isNumber);
                    str = str.Remove(startIndex, (num - startIndex) + 1).Insert(startIndex, str6);
                }
                num        = -1;
                startIndex = -1;
                flag       = false;
            }
            return(str);
        }
Пример #7
0
        /// <summary>
        /// Determines whether the format string is valid.
        /// </summary>
        /// <param name="token">The token to evaluate.</param>
        /// <returns>
        /// <c>true</c> if the specified format contains the text; otherwise, <c>false</c>.
        /// </returns>
        internal static bool EvaluateFormat(string token)
        {
            if ((token == null) || (token == string.Empty))
            {
                return(false);
            }
            string str = DefaultTokens.TrimSquareBracket(token);

            return(((str != null) && !(str == string.Empty)) && DefaultTokens.IsEquals(str[0], DefaultTokens.Dollar, false));
        }
Пример #8
0
 /// <summary>
 /// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </returns>
 public override string ToString()
 {
     if (this.index > -1)
     {
         return(DefaultTokens.AddSquareBracket("Color" + ((int)this.index)));
     }
     if (this.colorName == null)
     {
         throw new FormatException();
     }
     return(DefaultTokens.AddSquareBracket(this.colorName));
 }
Пример #9
0
 /// <summary>
 /// Parses the specified format.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>Returns the value.</returns>
 public override object Parse(string s)
 {
     s = this.TrimSpecialSymbol(s);
     if ((s != null) && (s != string.Empty))
     {
         bool   flag;
         string str = NumberHelper.FixJapaneseChars(s);
         if (bool.TryParse(s, out flag))
         {
             return((bool)flag);
         }
         bool flag2 = DefaultTokens.IsDecimal(str, this.NumberFormatInfo);
         bool flag3 = str.IndexOf(DefaultTokens.ExponentialSymbol, (StringComparison)StringComparison.CurrentCultureIgnoreCase) > -1;
         bool flag4 = (str[0] == DefaultTokens.LeftParenthesis) && (str[str.Length - 1] == DefaultTokens.RightParenthesis);
         if (this.numberFormatString != null)
         {
             double num2;
             int    count = 0;
             s = this.TrimPercentSign(s, out count);
             if (this.TryParse(s, out num2, flag3 | flag4))
             {
                 if (count > 0)
                 {
                     num2 /= 100.0 * count;
                 }
                 if ((num2 != 0.0) && (Math.Abs((double)(num2 - Math.Floor(num2))) != 0.0))
                 {
                     flag2 = true;
                 }
                 if (flag3)
                 {
                     flag2 = true;
                 }
                 if (!flag2)
                 {
                     int  num3;
                     long num4;
                     if (NumberHelper.TryInteger(num2, out num3))
                     {
                         return((int)num3);
                     }
                     if (NumberHelper.TryLong(num2, out num4))
                     {
                         return((long)num4);
                     }
                 }
                 return((double)num2);
             }
         }
     }
     return(null);
 }
Пример #10
0
        /// <summary>
        /// Determines whether the format string is valid.
        /// </summary>
        /// <param name="token">The token to evaluate.</param>
        /// <returns>
        /// <c>true</c> if the specified format contains the text; otherwise, <c>false</c>.
        /// </returns>
        internal static bool EvaluateFormat(string token)
        {
            if ((token == null) || (token == string.Empty))
            {
                return(false);
            }
            string str = DefaultTokens.TrimSquareBracket(token);

            if ((str == null) || (str == string.Empty))
            {
                return(false);
            }
            return(str.StartsWith("DBNum", (StringComparison)StringComparison.CurrentCultureIgnoreCase));
        }
Пример #11
0
        /// <summary>
        /// Creates a new DB number format.
        /// </summary>
        /// <param name="token">The string expression for the format.</param>
        public DBNumberFormatPart(string token) : base(token)
        {
            if (!EvaluateFormat(token))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            this.token = token;
            string s = DefaultTokens.TrimSquareBracket(token).Remove(0, "dbnum".Length);

            this.type = int.Parse(s);
            if ((this.type < 0) || (this.type > 3))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
        }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Dt.Cells.Data.NumberFormatText" /> class.
        /// </summary>
        /// <param name="format">The format string</param>
        /// <param name="partLocaleID">The part locale ID.</param>
        /// <param name="dbNumberFormatPart">The db number format part.</param>
        /// <param name="culture">The culture.</param>
        internal NumberFormatText(string format, object partLocaleID, object dbNumberFormatPart, CultureInfo culture) : base(partLocaleID, dbNumberFormatPart, culture)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            string s = NumberFormatBase.TrimNotSupportSymbol(format, false);

            if (partLocaleID != null)
            {
                s = DefaultTokens.ReplaceKeyword(s, base.PartLocaleID.OriginalToken, base.PartLocaleID.CurrencySymbol);
            }
            this.excelFormatString = s;
            s = DefaultTokens.TrimEscape(DefaultTokens.Filter(s, DefaultTokens.LeftSquareBracket, DefaultTokens.RightSquareBracket));
            this.formatString = s;
        }
Пример #13
0
        /// <summary>
        /// Creates a new locale format with the specified token.
        /// </summary>
        /// <param name="token">The string expression for the format.</param>
        public LocaleIDFormatPart(string token) : base(token)
        {
            this.locateID = -1;
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (token == string.Empty)
            {
                throw new FormatException(ResourceStrings.FormatterIllegaTokenError);
            }
            this.content = DefaultTokens.TrimSquareBracket(token);
            string content = this.content;

            if ((content == null) || (content == string.Empty))
            {
                throw new FormatException(ResourceStrings.FormatterIllegaTokenError);
            }
            if (!DefaultTokens.IsEquals(content[0], DefaultTokens.Dollar, false))
            {
                throw new FormatException(ResourceStrings.FormatterIllegaTokenError);
            }
            content = content.Remove(0, 1);
            int index = content.IndexOf(DefaultTokens.HyphenMinus);

            if (index > -1)
            {
                this.currencySymbol = content.Substring(0, index);
                content             = content.Remove(0, index);
            }
            else
            {
                this.currencySymbol = content;
                return;
            }
            if (!DefaultTokens.IsEquals(content[0], DefaultTokens.HyphenMinus, false))
            {
                throw new FormatException(ResourceStrings.FormatterIllegaTokenError);
            }
            content = content.Remove(0, 1);
            if (content.Length <= 0)
            {
                throw new FormatException(ResourceStrings.FormatterIllegaTokenError);
            }
            this.locateID = NumberHelper.ParseHexString(content);
        }
Пример #14
0
        /// <summary>
        /// Determines whether the format string is valid.
        /// </summary>
        /// <param name="token">The token to evaluate.</param>
        /// <returns>
        /// <c>true</c> if the specified format contains the text; otherwise, <c>false</c>.
        /// </returns>
        internal static bool EvaluateFormat(string token)
        {
            if ((token == null) || (token == string.Empty))
            {
                return(false);
            }
            string str = DefaultTokens.TrimSquareBracket(token);

            if ((str == null) || (str == string.Empty))
            {
                return(false);
            }
            if (str.Length < 3)
            {
                return(false);
            }
            if (char.IsNumber(token[token.Length - 1]))
            {
                return(token.StartsWith("Color", (StringComparison)StringComparison.CurrentCultureIgnoreCase));
            }
            return(token[0] != token[1]);
        }
Пример #15
0
 /// <summary>
 /// Parses the specified string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>Returns the parsed object.</returns>
 public object Parse(string s)
 {
     if ((s != null) && (s != string.Empty))
     {
         if (DefaultTokens.IsDecimal(s, this.FormatProvider))
         {
             double num;
             if (double.TryParse(s, (NumberStyles)NumberStyles.Any, (IFormatProvider)this.FormatProvider, out num))
             {
                 return((double)num);
             }
         }
         else
         {
             int num2;
             if (int.TryParse(s, (NumberStyles)NumberStyles.Any, (IFormatProvider)this.FormatProvider, out num2))
             {
                 return((int)num2);
             }
         }
     }
     return(null);
 }
Пример #16
0
        /// <summary>
        /// Creates a new color format.
        /// </summary>
        /// <param name="token">The string expression for the color format.</param>
        /// <remarks>Use a string expression such as "[red]" or "[blue]" to specify the color format.</remarks>
        public ColorFormatPart(string token) : base(token)
        {
            this.foreColor = Colors.Black;
            this.index     = -1;
            string color = DefaultTokens.TrimSquareBracket(token);

            if ((color == null) || (color == string.Empty))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            try
            {
                Windows.UI.Color?nullable = FormatterColorHelper.FromStringValue(color);
                if (nullable.HasValue)
                {
                    this.foreColor = nullable.Value;
                    this.colorName = color;
                    return;
                }

                if (color.Length > "Color".Length)
                {
                    color = color.Remove(0, "Color".Length);
                    int result = -1;
                    if ((int.TryParse(color, out result) && (result >= 1)) && (result <= 0x38))
                    {
                        this.foreColor = FormatterColorHelper.ColorFromIndex(result);
                        this.index     = result;
                        return;
                    }
                }
            }
            catch
            {
            }
            throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
        }
Пример #17
0
        /// <summary>
        /// Returns a string that represents the current conditional format.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String" /> that represents the current <see cref="T:Dt.Cells.Data.ConditionFormatPart" /> object.
        /// </returns>
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            switch (this.compareOperator)
            {
            case GeneralCompareType.EqualsTo:
                builder.Append("=");
                break;

            case GeneralCompareType.NotEqualsTo:
                builder.Append("<>");
                break;

            case GeneralCompareType.GreaterThan:
                builder.Append(">");
                break;

            case GeneralCompareType.GreaterThanOrEqualsTo:
                builder.Append(">=");
                break;

            case GeneralCompareType.LessThan:
                builder.Append("<");
                break;

            case GeneralCompareType.LessThanOrEqualsTo:
                builder.Append("<=");
                break;

            default:
                throw new FormatException();
            }
            builder.Append(this.value);
            return(DefaultTokens.AddSquareBracket(builder.ToString()));
        }
Пример #18
0
        /// <summary>
        /// Formats the specified value.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>
        /// Returns the string of the formatted value.
        /// </returns>
        public override string Format(object obj)
        {
            string str = string.Empty;

            if (FormatConverter.IsNumber(obj))
            {
                bool   flag     = (base.PartLocaleID == null) || base.PartLocaleID.AllowScience;
                double?nullable = FormatConverter.TryDouble(obj, true);
                if (!nullable.HasValue)
                {
                    return("");
                }
                double num = nullable.Value;
                if (((Math.Abs(num) <= 99999999999) || !flag) && ((Math.Abs(num) >= 1E-11) || (num == 0.0)))
                {
                    return(this.DigitalFormat.Format(obj));
                }
                return(this.ExponentialDigitalFormat.Format(obj));
            }
            if (obj is string)
            {
                string newValue = FormatConverter.ToString(obj, true);
                string str3     = DefaultTokens.TrimEscape(this.FormatString.Replace("\"", ""));
                if (str3 != null)
                {
                    newValue = str3.Replace("General", newValue);
                }
                return(newValue);
            }
            if (obj is bool)
            {
                bool flag2 = (bool)((bool)obj);
                str = flag2.ToString().ToUpper();
            }
            return(str);
        }
Пример #19
0
        /// <summary>
        /// Parses the specified format.
        /// </summary>
        /// <param name="s">The string.</param>
        /// <returns>Returns the value.</returns>
        public override object Parse(string s)
        {
            if ((s == null) || (s == string.Empty))
            {
                return(null);
            }
            s = NumberHelper.FixJapaneseChars(s);
            bool flag  = false;
            int  index = s.IndexOf("-");

            if ((index > 0) && !DefaultTokens.IsEquals(s[index - 1], DefaultTokens.ExponentialSymbol, true))
            {
                flag = true;
            }
            List <string> list = new List <string>(new string[] { "/", ":", "." });

            list.Remove(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            bool flag2 = false;

            if (flag)
            {
                flag2 = true;
            }
            if (!flag2)
            {
                foreach (string str in list)
                {
                    if (s.Contains(str))
                    {
                        flag2 = true;
                        break;
                    }
                }
            }
            if (flag2)
            {
                DateTime time;
                if (DateTime.TryParseExact(s, GeneralMonthDay, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time))
                {
                    return(time);
                }
                if (DateTime.TryParseExact(s, generalYearMonth, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time))
                {
                    return(time);
                }
                if (DateTime.TryParseExact(s, GeneralYearMonthDay, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time))
                {
                    return(time);
                }
                if (DateTime.TryParseExact(s, AlternativeYearMonthDay, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time))
                {
                    return(time);
                }
                if (DateTime.TryParseExact(s, generalHourMinute, null, ((DateTimeStyles)DateTimeStyles.NoCurrentDateDefault) | ((DateTimeStyles)DateTimeStyles.AllowWhiteSpaces), out time))
                {
                    if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1))
                    {
                        return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond));
                    }
                    return(time);
                }
                if (DateTime.TryParseExact(s, generalHourMinuteSecond, null, ((DateTimeStyles)DateTimeStyles.NoCurrentDateDefault) | ((DateTimeStyles)DateTimeStyles.AllowWhiteSpaces), out time))
                {
                    if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1))
                    {
                        return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond));
                    }
                    return(time);
                }
                if (DateTime.TryParseExact(s, generalHourMinuteSecondSubSecond, null, ((DateTimeStyles)DateTimeStyles.NoCurrentDateDefault) | ((DateTimeStyles)DateTimeStyles.AllowWhiteSpaces), out time))
                {
                    if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1))
                    {
                        return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond));
                    }
                    return(time);
                }
                if (DateTime.TryParseExact(s, GeneralHourMinuteWithDate, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time))
                {
                    return(time);
                }
                if (DateTime.TryParseExact(s, GeneralHourMinuteSecondWithDate, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time))
                {
                    return(time);
                }
                if (DateTime.TryParseExact(s, GeneralHourMinuteSecondSubSecondWithDate, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time))
                {
                    return(time);
                }
            }
            string str2     = s;
            bool?  nullable = null;

            if (str2.Substring(0, 1) == DefaultTokens.NegativeSign)
            {
                nullable = true;
            }
            else if (str2.Substring(0, 1) == DefaultTokens.PositiveSign)
            {
                nullable = false;
            }
            bool flag3 = false;

            if ((nullable.HasValue && (str2.Length > 3)) && ((str2[1] == DefaultTokens.LeftParenthesis) && (str2[str2.Length - 1] == DefaultTokens.RightParenthesis)))
            {
                flag3 = true;
            }
            if (nullable.HasValue && flag3)
            {
                string str3 = s.Remove(0, 1);
                object obj2 = this.DigitalFormat.Parse(str3);
                if (obj2 == null)
                {
                    return(s);
                }
                if (obj2 is double)
                {
                    if (nullable.Value)
                    {
                        return((double)-Math.Abs((double)((double)obj2)));
                    }
                    return((double)Math.Abs((double)((double)obj2)));
                }
                if (!(obj2 is int))
                {
                    return(obj2);
                }
                if (nullable.Value)
                {
                    return((int)-Math.Abs((int)((int)obj2)));
                }
                return((int)Math.Abs((int)((int)obj2)));
            }
            object obj3 = this.DigitalFormat.Parse(s);

            if (obj3 != null)
            {
                return(obj3);
            }
            return(s);
        }
Пример #20
0
        /// <summary>
        /// Creates a new condition format with the specified string expression.
        /// </summary>
        /// <param name="token">The string expression for this format.</param>
        /// <remarks>Examples of conditional string expressions are "[&gt;10]" and "[&gt;=0]".</remarks>
        public ConditionFormatPart(string token) : base(token)
        {
            string str = DefaultTokens.TrimSquareBracket(token);

            if (string.IsNullOrEmpty(str))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            StringBuilder builder = null;
            int           num     = 0;

            while (num < str.Length)
            {
                char c = str[num];
                if (!DefaultTokens.IsOperator(c))
                {
                    break;
                }
                if (builder == null)
                {
                    builder = new StringBuilder();
                }
                builder.Append(c);
                num++;
            }
            if (builder == null)
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            string str2 = builder.ToString();

            builder = null;
            switch (str2)
            {
            case "<":
                this.compareOperator = GeneralCompareType.LessThan;
                break;

            case "<=":
                this.compareOperator = GeneralCompareType.LessThanOrEqualsTo;
                break;

            case "=":
                this.compareOperator = GeneralCompareType.EqualsTo;
                break;

            case ">=":
                this.compareOperator = GeneralCompareType.GreaterThanOrEqualsTo;
                break;

            case ">":
                this.compareOperator = GeneralCompareType.GreaterThan;
                break;

            case "<>":
                this.compareOperator = GeneralCompareType.NotEqualsTo;
                break;

            default:
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            while (num < str.Length)
            {
                char ch2 = str[num];
                if (DefaultTokens.IsOperator(ch2))
                {
                    throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
                }
                if (builder == null)
                {
                    builder = new StringBuilder();
                }
                builder.Append(ch2);
                num++;
            }
            if (builder == null)
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            if (!double.TryParse(builder.ToString(), out this.value))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
        }
Пример #21
0
        /// <summary>
        /// Replaces the specified format.
        /// </summary>
        /// <param name="format">The format</param>
        /// <param name="oldToken">The old token</param>
        /// <param name="newToken">The new token</param>
        /// <param name="isReplaceInDateFormat">if set to <c>true</c> should replace token in date area</param>
        /// <param name="isReplaceInTimeFormat">if set to <c>true</c>  should replace token in time area</param>
        /// <param name="result">The result.</param>
        /// <param name="justSearch">if set to <c>true</c> not really replace.</param>
        /// <param name="isIgnoreCase">if set to <c>true</c> is ignore case.</param>
        /// <returns>
        /// <c>true</c> if replace token successful; otherwise, <c>false</c>.
        /// </returns>
        bool Replace(string format, string oldToken, string newToken, bool isReplaceInDateFormat, bool isReplaceInTimeFormat, out string result, bool justSearch, bool isIgnoreCase)
        {
            result = format;
            if (!isReplaceInDateFormat && !isReplaceInTimeFormat)
            {
                return(false);
            }
            List <int> list  = new List <int>();
            bool       flag  = true;
            char       ch3   = HoursSingleDigit[0];
            bool       flag2 = (result.IndexOf(((char)ch3).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase) > -1) || (result.IndexOf(((char)SecondSingleDigit[0]).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase) > -1);
            char       ch5   = YearTwoDigit[0];

            if (((result.IndexOf(((char)ch5).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase) <= -1) && (result.IndexOf(((char)DaySingleDigit[0]).ToString(), (StringComparison)StringComparison.CurrentCultureIgnoreCase) <= -1)) && flag2)
            {
                flag = false;
            }
            bool flag4 = false;
            int  num   = 0;

            for (int i = 0; i < result.Length; i++)
            {
                char a = result[i];
                if (DefaultTokens.IsEquals(a, HoursSingleDigit[0], true) || DefaultTokens.IsEquals(a, SecondSingleDigit[0], true))
                {
                    flag = false;
                }
                else if (DefaultTokens.IsEquals(a, YearTwoDigit[0], true) || DefaultTokens.IsEquals(a, DaySingleDigit[0], true))
                {
                    flag = true;
                }
                if (((isReplaceInDateFormat && DefaultTokens.IsEquals(a, oldToken[num], isIgnoreCase)) && flag) || ((isReplaceInTimeFormat && DefaultTokens.IsEquals(a, oldToken[num], isIgnoreCase)) && !flag))
                {
                    bool flag5 = true;
                    for (int j = 0; j < oldToken.Length; j++)
                    {
                        if (((j + i) >= format.Length) || !DefaultTokens.IsEquals(oldToken[j], result[j + i], isIgnoreCase))
                        {
                            flag5 = false;
                            break;
                        }
                    }
                    int num4 = (i + oldToken.Length) - 1;
                    if (flag5 && ((num4 + 1) < result.Length))
                    {
                        char ch2  = result[num4];
                        int  num5 = -1;
                        num5 = num4 + 1;
                        while (num5 < result.Length)
                        {
                            if (!DefaultTokens.IsEquals(ch2, result[num5], isIgnoreCase))
                            {
                                break;
                            }
                            num5++;
                        }
                        if (num5 > (num4 + 1))
                        {
                            i     = num5;
                            flag5 = false;
                        }
                    }
                    if (flag5 && !flag4)
                    {
                        list.Insert(0, i);
                    }
                }
                if (a == '"')
                {
                    flag4 = !flag4;
                }
            }
            if (list.Count <= 0)
            {
                return(false);
            }
            if (!justSearch)
            {
                foreach (int num6 in list)
                {
                    result = result.Remove(num6, oldToken.Length);
                    result = result.Insert(num6, newToken);
                }
            }
            return(true);
        }