示例#1
0
        internal static int HandleHex(CharacterStream cs, int start)
        {
            while (CharacterStream.IsHex(cs.CurrentChar))
            {
                cs.MoveToNextChar();
            }

            // TODO: handle C99 floating point hex syntax like 0x1.1p-2
            if (cs.CurrentChar == 'L')
            {
                cs.MoveToNextChar();
            }

            return(cs.Position - start);
        }
示例#2
0
        // public static object CharacterSteam { get; private set; }

        public static int HandleNumber(CharacterStream cs)
        {
            int start = cs.Position;

            if (cs.CurrentChar == '-' || cs.CurrentChar == '+')
            {
                cs.MoveToNextChar();
            }

            if (cs.CurrentChar == '0' && cs.NextChar == 'x')
            {
                cs.Advance(2);
                return(HandleHex(cs, start));
            }

            if (cs.CurrentChar == 'x' && CharacterStream.IsHex(cs.NextChar))
            {
                cs.MoveToNextChar();
                return(HandleHex(cs, start));
            }

            int  integerPartStart   = cs.Position;
            int  integerPartLength  = 0;
            int  fractionPartLength = 0;
            bool isDouble           = false;

            // collect decimals (there may be none like in .1e+20
            while (cs.IsDecimal())
            {
                cs.MoveToNextChar();
                integerPartLength++;
            }

            if (cs.CurrentChar == '.')
            {
                isDouble = true;

                // float/double
                cs.MoveToNextChar();

                // If we've seen don we need to collect factional part of any
                while (cs.IsDecimal())
                {
                    cs.MoveToNextChar();
                    fractionPartLength++;
                }
            }

            if (integerPartLength + fractionPartLength == 0)
            {
                return(0); // +e or +.e is not a number and neither is lonely + or -
            }

            int numberLength;

            if (cs.CurrentChar == 'e' || cs.CurrentChar == 'E')
            {
                isDouble     = true;
                numberLength = HandleExponent(cs, start);
            }
            else
            {
                numberLength = cs.Position - start;
            }

            // Verify double format
            if (isDouble && !IsValidDouble(cs, start, cs.Position))
            {
                numberLength = 0;
            }

            if (numberLength > 0)
            {
                // skip over trailing 'L' if any
                if (cs.CurrentChar == 'L')
                {
                    cs.MoveToNextChar();
                    numberLength++;
                }
            }

            return(numberLength);
        }