private final int scan_for_numeric_type()

in src/com/amazon/ion/impl/IonReaderTextRawTokensX.java [1029:1106]


    private final int scan_for_numeric_type(int c1) throws IOException
    {
        int   t = IonTokenConstsX.TOKEN_UNKNOWN_NUMERIC;
        int[] read_chars = new int[6];
        int   read_char_count = 0;
        int   c;

        if (!IonTokenConstsX.isDigit(c1)) {
            error(String.format("Expected digit, got U+%04X", c1));
        }

        // the caller needs to unread this if they want to: read_chars[read_char_count++] = c1;

        c = read_char();
        read_chars[read_char_count++] = c;

        if (c1 == '0') {
            // check for hex
            switch(c) {
            case 'x':
            case 'X':
                t = IonTokenConstsX.TOKEN_HEX;
                break;
            case 'd':
            case 'D':
                t = IonTokenConstsX.TOKEN_DECIMAL;
                break;
            case 'e':
            case 'E':
                t = IonTokenConstsX.TOKEN_FLOAT;
                break;
            case 'b':
            case 'B':
                t = IonTokenConstsX.TOKEN_BINARY;
                break;
            case '.':
                // the decimal might have an 'e' somewhere down the line so we
                // don't really know the type here
                break;
            default:
                if (is_value_terminating_character(c)) {
                    t = IonTokenConstsX.TOKEN_INT;
                }
                break;
            }
        }
        if (t == IonTokenConstsX.TOKEN_UNKNOWN_NUMERIC) { // oh for goto :(
            if (IonTokenConstsX.isDigit(c)) { // 2nd digit
                // it might be a timestamp if we have 4 digits, a dash,
                // and a digit
                c = read_char();
                read_chars[read_char_count++] = c;
                if (IonTokenConstsX.isDigit(c)) { // digit 3
                    c = read_char();
                    read_chars[read_char_count++] = c;
                    if (IonTokenConstsX.isDigit(c)) {
                        // last digit of possible year
                        c = read_char();
                        read_chars[read_char_count++] = c;
                        if (c == '-' || c =='T') {
                            // we have dddd- or ddddT looks like a timestamp
                            // (or invalid input)
                            t = IonTokenConstsX.TOKEN_TIMESTAMP;
                        }
                    }
                }
            }
        }

        // unread whatever we read, including the passed in char
        do {
            read_char_count--;
            c = read_chars[read_char_count];
            unread_char(c);
        } while (read_char_count > 0);

        return t;
    }