IsWhite() private static method

private static IsWhite ( char ch ) : Boolean
ch char
return Boolean
示例#1
0
        private static unsafe bool ParseNumber(ref char *str, NumberStyles options, ref Number.NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal)
        {
            number.scale = 0;
            number.sign  = false;
            string str1  = (string)null;
            string str2  = (string)null;
            string str3  = (string)null;
            string str4  = (string)null;
            bool   flag1 = false;
            string decimalSeparator;
            string str5;

            if ((options & NumberStyles.AllowCurrencySymbol) != NumberStyles.None)
            {
                str1 = numfmt.CurrencySymbol;
                if (numfmt.ansiCurrencySymbol != null)
                {
                    str2 = numfmt.ansiCurrencySymbol;
                }
                str3             = numfmt.NumberDecimalSeparator;
                str4             = numfmt.NumberGroupSeparator;
                decimalSeparator = numfmt.CurrencyDecimalSeparator;
                str5             = numfmt.CurrencyGroupSeparator;
                flag1            = true;
            }
            else
            {
                decimalSeparator = numfmt.NumberDecimalSeparator;
                str5             = numfmt.NumberGroupSeparator;
            }
            int   num1  = 0;
            bool  flag2 = sb != null;
            bool  flag3 = flag2 && (uint)(options & NumberStyles.AllowHexSpecifier) > 0U;
            int   num2  = flag2 ? int.MaxValue : 50;
            char *p     = str;
            char  ch    = *p;

            while (true)
            {
                if (!Number.IsWhite(ch) || (options & NumberStyles.AllowLeadingWhite) == NumberStyles.None || (num1 & 1) != 0 && ((num1 & 1) == 0 || (num1 & 32) == 0 && numfmt.numberNegativePattern != 2))
                {
                    bool  flag4;
                    char *chPtr1;
                    if ((flag4 = (options & NumberStyles.AllowLeadingSign) != NumberStyles.None && (num1 & 1) == 0) && (IntPtr)(chPtr1 = Number.MatchChars(p, numfmt.positiveSign)) != IntPtr.Zero)
                    {
                        num1 |= 1;
                        p     = (char *)((IntPtr)chPtr1 - 2);
                    }
                    else
                    {
                        char *chPtr2;
                        if (flag4 && (IntPtr)(chPtr2 = Number.MatchChars(p, numfmt.negativeSign)) != IntPtr.Zero)
                        {
                            num1       |= 1;
                            number.sign = true;
                            p           = (char *)((IntPtr)chPtr2 - 2);
                        }
                        else if ((int)ch == 40 && (options & NumberStyles.AllowParentheses) != NumberStyles.None && (num1 & 1) == 0)
                        {
                            num1       |= 3;
                            number.sign = true;
                        }
                        else
                        {
                            char *chPtr3;
                            if (str1 != null && (IntPtr)(chPtr3 = Number.MatchChars(p, str1)) != IntPtr.Zero || str2 != null && (IntPtr)(chPtr3 = Number.MatchChars(p, str2)) != IntPtr.Zero)
                            {
                                num1 |= 32;
                                str1  = (string)null;
                                str2  = (string)null;
                                p     = (char *)((IntPtr)chPtr3 - 2);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                ch = *(p += 2);
            }
            int num3  = 0;
            int index = 0;

            while (true)
            {
                if ((int)ch >= 48 && (int)ch <= 57 || (options & NumberStyles.AllowHexSpecifier) != NumberStyles.None && ((int)ch >= 97 && (int)ch <= 102 || (int)ch >= 65 && (int)ch <= 70))
                {
                    num1 |= 4;
                    if ((((int)ch != 48 ? 1 : ((uint)(num1 & 8) > 0U ? 1 : 0)) | (flag3 ? 1 : 0)) != 0)
                    {
                        if (num3 < num2)
                        {
                            if (flag2)
                            {
                                sb.Append(ch);
                            }
                            else
                            {
                                number.digits[num3++] = ch;
                            }
                            if ((int)ch != 48 | parseDecimal)
                            {
                                index = num3;
                            }
                        }
                        if ((num1 & 16) == 0)
                        {
                            ++number.scale;
                        }
                        num1 |= 8;
                    }
                    else if ((num1 & 16) != 0)
                    {
                        --number.scale;
                    }
                }
                else
                {
                    char *chPtr1;
                    if ((options & NumberStyles.AllowDecimalPoint) != NumberStyles.None && (num1 & 16) == 0 && ((IntPtr)(chPtr1 = Number.MatchChars(p, decimalSeparator)) != IntPtr.Zero || flag1 && (num1 & 32) == 0 && (IntPtr)(chPtr1 = Number.MatchChars(p, str3)) != IntPtr.Zero))
                    {
                        num1 |= 16;
                        p     = (char *)((IntPtr)chPtr1 - 2);
                    }
                    else
                    {
                        char *chPtr2;
                        if ((options & NumberStyles.AllowThousands) != NumberStyles.None && (num1 & 4) != 0 && (num1 & 16) == 0 && ((IntPtr)(chPtr2 = Number.MatchChars(p, str5)) != IntPtr.Zero || flag1 && (num1 & 32) == 0 && (IntPtr)(chPtr2 = Number.MatchChars(p, str4)) != IntPtr.Zero))
                        {
                            p = (char *)((IntPtr)chPtr2 - 2);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                ch = *(p += 2);
            }
            bool flag5 = false;

            number.precision = index;
            if (flag2)
            {
                sb.Append(char.MinValue);
            }
            else
            {
                number.digits[index] = char.MinValue;
            }
            if ((num1 & 4) != 0)
            {
                if (((int)ch == 69 || (int)ch == 101) && (options & NumberStyles.AllowExponent) != NumberStyles.None)
                {
                    char *chPtr1 = p;
                    ch = *(p += 2);
                    char *chPtr2;
                    if ((IntPtr)(chPtr2 = Number.MatchChars(p, numfmt.positiveSign)) != IntPtr.Zero)
                    {
                        ch = *(p = chPtr2);
                    }
                    else
                    {
                        char *chPtr3;
                        if ((IntPtr)(chPtr3 = Number.MatchChars(p, numfmt.negativeSign)) != IntPtr.Zero)
                        {
                            ch    = *(p = chPtr3);
                            flag5 = true;
                        }
                    }
                    if ((int)ch >= 48 && (int)ch <= 57)
                    {
                        int num4 = 0;
                        do
                        {
                            num4 = num4 * 10 + ((int)ch - 48);
                            ch   = *(p += 2);
                            if (num4 > 1000)
                            {
                                num4 = 9999;
                                while ((int)ch >= 48 && (int)ch <= 57)
                                {
                                    ch = *(p += 2);
                                }
                            }
                        }while ((int)ch >= 48 && (int)ch <= 57);
                        if (flag5)
                        {
                            num4 = -num4;
                        }
                        number.scale += num4;
                    }
                    else
                    {
                        p  = chPtr1;
                        ch = *p;
                    }
                }
                while (true)
                {
                    if (!Number.IsWhite(ch) || (options & NumberStyles.AllowTrailingWhite) == NumberStyles.None)
                    {
                        bool  flag4;
                        char *chPtr1;
                        if ((flag4 = (options & NumberStyles.AllowTrailingSign) != NumberStyles.None && (num1 & 1) == 0) && (IntPtr)(chPtr1 = Number.MatchChars(p, numfmt.positiveSign)) != IntPtr.Zero)
                        {
                            num1 |= 1;
                            p     = (char *)((IntPtr)chPtr1 - 2);
                        }
                        else
                        {
                            char *chPtr2;
                            if (flag4 && (IntPtr)(chPtr2 = Number.MatchChars(p, numfmt.negativeSign)) != IntPtr.Zero)
                            {
                                num1       |= 1;
                                number.sign = true;
                                p           = (char *)((IntPtr)chPtr2 - 2);
                            }
                            else if ((int)ch == 41 && (num1 & 2) != 0)
                            {
                                num1 &= -3;
                            }
                            else
                            {
                                char *chPtr3;
                                if (str1 != null && (IntPtr)(chPtr3 = Number.MatchChars(p, str1)) != IntPtr.Zero || str2 != null && (IntPtr)(chPtr3 = Number.MatchChars(p, str2)) != IntPtr.Zero)
                                {
                                    str1 = (string)null;
                                    str2 = (string)null;
                                    p    = (char *)((IntPtr)chPtr3 - 2);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    ch = *(p += 2);
                }
                if ((num1 & 2) == 0)
                {
                    if ((num1 & 8) == 0)
                    {
                        if (!parseDecimal)
                        {
                            number.scale = 0;
                        }
                        if ((num1 & 16) == 0)
                        {
                            number.sign = false;
                        }
                    }
                    str = p;
                    return(true);
                }
            }
            str = p;
            return(false);
        }
        private unsafe static bool ParseNumber(ref char *str, NumberStyles options, ref Number.NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal)
        {
            number.scale = 0;
            number.sign  = false;
            string text  = null;
            string text2 = null;
            string str2  = null;
            string str3  = null;
            bool   flag  = false;
            string str4;
            string str5;

            if ((options & NumberStyles.AllowCurrencySymbol) != NumberStyles.None)
            {
                text = numfmt.CurrencySymbol;
                if (numfmt.ansiCurrencySymbol != null)
                {
                    text2 = numfmt.ansiCurrencySymbol;
                }
                str2 = numfmt.NumberDecimalSeparator;
                str3 = numfmt.NumberGroupSeparator;
                str4 = numfmt.CurrencyDecimalSeparator;
                str5 = numfmt.CurrencyGroupSeparator;
                flag = true;
            }
            else
            {
                str4 = numfmt.NumberDecimalSeparator;
                str5 = numfmt.NumberGroupSeparator;
            }
            int   num   = 0;
            bool  flag2 = sb != null;
            bool  flag3 = flag2 && (options & NumberStyles.AllowHexSpecifier) > NumberStyles.None;
            int   num2  = flag2 ? int.MaxValue : 50;
            char *ptr   = str;
            char  c     = *ptr;

            for (;;)
            {
                if (!Number.IsWhite(c) || (options & NumberStyles.AllowLeadingWhite) == NumberStyles.None || ((num & 1) != 0 && ((num & 1) == 0 || ((num & 32) == 0 && numfmt.numberNegativePattern != 2))))
                {
                    bool  flag4;
                    char *ptr2;
                    if ((flag4 = ((options & NumberStyles.AllowLeadingSign) != NumberStyles.None && (num & 1) == 0)) && (ptr2 = Number.MatchChars(ptr, numfmt.positiveSign)) != null)
                    {
                        num |= 1;
                        ptr  = ptr2 - 1;
                    }
                    else if (flag4 && (ptr2 = Number.MatchChars(ptr, numfmt.negativeSign)) != null)
                    {
                        num        |= 1;
                        number.sign = true;
                        ptr         = ptr2 - 1;
                    }
                    else if (c == '(' && (options & NumberStyles.AllowParentheses) != NumberStyles.None && (num & 1) == 0)
                    {
                        num        |= 3;
                        number.sign = true;
                    }
                    else
                    {
                        if ((text == null || (ptr2 = Number.MatchChars(ptr, text)) == null) && (text2 == null || (ptr2 = Number.MatchChars(ptr, text2)) == null))
                        {
                            break;
                        }
                        num  |= 32;
                        text  = null;
                        text2 = null;
                        ptr   = ptr2 - 1;
                    }
                }
                c = *(++ptr);
            }
            int num3 = 0;
            int num4 = 0;

            for (;;)
            {
                char *ptr2;
                if ((c >= '0' && c <= '9') || ((options & NumberStyles.AllowHexSpecifier) != NumberStyles.None && ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))))
                {
                    num |= 4;
                    if (c != '0' || (num & 8) != 0 || flag3)
                    {
                        if (num3 < num2)
                        {
                            if (flag2)
                            {
                                sb.Append(c);
                            }
                            else
                            {
                                number.digits[(IntPtr)(num3++) * 2] = c;
                            }
                            if (c != '0' || parseDecimal)
                            {
                                num4 = num3;
                            }
                        }
                        if ((num & 16) == 0)
                        {
                            number.scale++;
                        }
                        num |= 8;
                    }
                    else if ((num & 16) != 0)
                    {
                        number.scale--;
                    }
                }
                else if ((options & NumberStyles.AllowDecimalPoint) != NumberStyles.None && (num & 16) == 0 && ((ptr2 = Number.MatchChars(ptr, str4)) != null || (flag && (num & 32) == 0 && (ptr2 = Number.MatchChars(ptr, str2)) != null)))
                {
                    num |= 16;
                    ptr  = ptr2 - 1;
                }
                else
                {
                    if ((options & NumberStyles.AllowThousands) == NumberStyles.None || (num & 4) == 0 || (num & 16) != 0 || ((ptr2 = Number.MatchChars(ptr, str5)) == null && (!flag || (num & 32) != 0 || (ptr2 = Number.MatchChars(ptr, str3)) == null)))
                    {
                        break;
                    }
                    ptr = ptr2 - 1;
                }
                c = *(++ptr);
            }
            bool flag5 = false;

            number.precision = num4;
            if (flag2)
            {
                sb.Append('\0');
            }
            else
            {
                number.digits[num4] = '\0';
            }
            if ((num & 4) != 0)
            {
                if ((c == 'E' || c == 'e') && (options & NumberStyles.AllowExponent) != NumberStyles.None)
                {
                    char *ptr3 = ptr;
                    c = *(++ptr);
                    char *ptr2;
                    if ((ptr2 = Number.MatchChars(ptr, numfmt.positiveSign)) != null)
                    {
                        c = *(ptr = ptr2);
                    }
                    else if ((ptr2 = Number.MatchChars(ptr, numfmt.negativeSign)) != null)
                    {
                        c     = *(ptr = ptr2);
                        flag5 = true;
                    }
                    if (c >= '0' && c <= '9')
                    {
                        int num5 = 0;
                        do
                        {
                            num5 = num5 * 10 + (int)(c - '0');
                            c    = *(++ptr);
                            if (num5 > 1000)
                            {
                                num5 = 9999;
                                while (c >= '0' && c <= '9')
                                {
                                    c = *(++ptr);
                                }
                            }
                        }while (c >= '0' && c <= '9');
                        if (flag5)
                        {
                            num5 = -num5;
                        }
                        number.scale += num5;
                    }
                    else
                    {
                        ptr = ptr3;
                        c   = *ptr;
                    }
                }
                for (;;)
                {
                    if (!Number.IsWhite(c) || (options & NumberStyles.AllowTrailingWhite) == NumberStyles.None)
                    {
                        bool  flag4;
                        char *ptr2;
                        if ((flag4 = ((options & NumberStyles.AllowTrailingSign) != NumberStyles.None && (num & 1) == 0)) && (ptr2 = Number.MatchChars(ptr, numfmt.positiveSign)) != null)
                        {
                            num |= 1;
                            ptr  = ptr2 - 1;
                        }
                        else if (flag4 && (ptr2 = Number.MatchChars(ptr, numfmt.negativeSign)) != null)
                        {
                            num        |= 1;
                            number.sign = true;
                            ptr         = ptr2 - 1;
                        }
                        else if (c == ')' && (num & 2) != 0)
                        {
                            num &= -3;
                        }
                        else
                        {
                            if ((text == null || (ptr2 = Number.MatchChars(ptr, text)) == null) && (text2 == null || (ptr2 = Number.MatchChars(ptr, text2)) == null))
                            {
                                break;
                            }
                            text  = null;
                            text2 = null;
                            ptr   = ptr2 - 1;
                        }
                    }
                    c = *(++ptr);
                }
                if ((num & 2) == 0)
                {
                    if ((num & 8) == 0)
                    {
                        if (!parseDecimal)
                        {
                            number.scale = 0;
                        }
                        if ((num & 16) == 0)
                        {
                            number.sign = false;
                        }
                    }
                    str = ptr;
                    return(true);
                }
            }
            str = ptr;
            return(false);
        }