IsHexDigit() public static method

public static IsHexDigit ( Char ch ) : System.Boolean
ch Char
return System.Boolean
Ejemplo n.º 1
0
        // ReadChar : Char -> ()
        // =====================
        // Implementation of the FSA
        //
        public override void ReadChar(Char ch)
        {
            this._scanned = this._scanned + ch;
            switch (this._state)
            {
            case State.END:
            case State.ERROR:
                this._state = State.ERROR;
                break;

            case State.START:
                if (IsChar(ch))
                {
                    this._state = State.C;
                }
                else if (ch == '\\')
                {
                    this._state = State.S;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.C:
                this._state = State.END;
                break;

            case State.S:
                if (Utils.IsEscapeChar(ch))
                {
                    this._state = State.C;
                }
                else if (Utils.IsOctDigit(ch))
                {
                    this._state = State.SO;
                }
                else if (ch == 'x' || ch == 'X')
                {
                    this._state = State.SX;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.SX:
                if (Utils.IsHexDigit(ch))
                {
                    this._state = State.SXH;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.SXH:
                if (Utils.IsHexDigit(ch))
                {
                    this._state = State.SXHH;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.SXHH:
                this._state = State.END;
                break;

            case State.SO:
                if (Utils.IsOctDigit(ch))
                {
                    this._state = State.SOO;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.SOO:
                if (Utils.IsOctDigit(ch))
                {
                    this._state = State.SOOO;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.SOOO:
                this._state = State.END;
                break;

            default:
                this._state = State.ERROR;
                break;
            }
        }
Ejemplo n.º 2
0
        public override void ReadChar(Char ch)
        {
            this._raw += ch;
            switch (this._state)
            {
            case State.ERROR:
            case State.END:
                this._state = State.ERROR;
                break;

            case State.START:
                if (ch == '0')
                {
                    this._state = State.Z;
                }
                else if (Char.IsDigit(ch))
                {
                    this._state = State.D;
                    this._val  += ch - '0';
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.Z:
                if (ch == 'x' || ch == 'X')
                {
                    this._state = State.ZX;
                }
                else if (Utils.IsOctDigit(ch))
                {
                    this._val  *= 8;
                    this._val  += ch - '0';
                    this._state = State.O;
                }
                else if (ch == 'u' || ch == 'U')
                {
                    this._suffix = TokenInt.IntSuffix.U;
                    this._state  = State.U;
                }
                else if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenInt.IntSuffix.L;
                    this._state  = State.L;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.D:
                if (Char.IsDigit(ch))
                {
                    this._val  *= 10;
                    this._val  += ch - '0';
                    this._state = State.D;
                }
                else if (ch == 'u' || ch == 'U')
                {
                    this._suffix = TokenInt.IntSuffix.U;
                    this._state  = State.U;
                }
                else if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenInt.IntSuffix.L;
                    this._state  = State.L;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.ZX:
                if (Utils.IsHexDigit(ch))
                {
                    this._val  *= 0x10;
                    this._val  += Utils.GetHexDigit(ch);
                    this._state = State.H;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.O:
                if (Utils.IsOctDigit(ch))
                {
                    this._val  *= 8;
                    this._val  += ch - '0';
                    this._state = State.O;
                }
                else if (ch == 'u' || ch == 'U')
                {
                    this._suffix = TokenInt.IntSuffix.U;
                    this._state  = State.U;
                }
                else if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenInt.IntSuffix.L;
                    this._state  = State.L;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.L:
                if (ch == 'u' || ch == 'U')
                {
                    this._suffix = TokenInt.IntSuffix.UL;
                    this._state  = State.UL;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.H:
                if (Utils.IsHexDigit(ch))
                {
                    this._val  *= 0x10;
                    this._val  += Utils.GetHexDigit(ch);
                    this._state = State.H;
                }
                else if (ch == 'u' || ch == 'U')
                {
                    this._suffix = TokenInt.IntSuffix.U;
                    this._state  = State.U;
                }
                else if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenInt.IntSuffix.L;
                    this._state  = State.L;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.U:
                if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenInt.IntSuffix.UL;
                    this._state  = State.UL;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.UL:
                this._state = State.END;
                break;

            default:
                this._state = State.ERROR;
                break;
            }
        }