⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokenizer.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    int getLongNameFirstType() throws HsqlException {        if (bWait) {            Trace.doAssert(false, "Querying state when in Wait mode");        }        return typeLongNameFirst;    }    boolean wasSimpleToken() throws HsqlException {        return iType != QUOTED_IDENTIFIER && iType != LONG_NAME               && iType != STRING;    }    String getSimpleToken() throws HsqlException {        getToken();        if (iType == QUOTED_IDENTIFIER || iType == LONG_NAME                || iType == STRING) {            String token = iType == LONG_NAME ? sLongNameFirst                                              : sToken;            throw Trace.error(Trace.UNEXPECTED_TOKEN, token);        }        return sToken;    }    public boolean wasThis(String match) throws HsqlException {        if (sToken.equals(match) && iType != QUOTED_IDENTIFIER                && iType != LONG_NAME) {            return true;        }        return false;    }    /**     * getName() is more broad than getSimpleName() in that it includes     * 2-part names as well     *     * @return popped name     * @throws HsqlException if next token is not an AName     */    String getName() throws HsqlException {        getToken();        if (!wasName()) {            throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);        }        return sToken;    }    /**     * Returns a single, unqualified name (identifier)     *     * @return name     * @throws HsqlException     */    public String getSimpleName() throws HsqlException {        getToken();        if (!wasSimpleName()) {            String token = iType == LONG_NAME ? sLongNameFirst                                              : sToken;            throw Trace.error(Trace.UNEXPECTED_TOKEN, token);        }        return sToken;    }    /**     * Return any token.     *     *     * @return     *     * @throws HsqlException     */    public String getString() throws HsqlException {        getToken();        return sToken;    }    int getInt() throws HsqlException {        long v = getBigint();        if (v > Integer.MAX_VALUE || v < Integer.MIN_VALUE) {            throw Trace.error(Trace.WRONG_DATA_TYPE,                              Types.getTypeString(getType()));        }        return (int) v;    }    long getBigint() throws HsqlException {        boolean minus = false;        getToken();        if (sToken.equals(Token.T_MINUS)) {            minus = true;            getToken();        }        Object o = getAsValue();        int    t = getType();        if (t != Types.INTEGER && t != Types.BIGINT && t != Types.DECIMAL) {            throw Trace.error(Trace.WRONG_DATA_TYPE, Types.getTypeString(t));        }        if (t == Types.DECIMAL) {            // only Long.MAX_VALUE + 1 together with minus is acceptable            BigDecimal bd = (BigDecimal) o;            if (minus && bd.subtract(new BigDecimal(Long.MAX_VALUE)).equals(                    new BigDecimal(1))) {                return Long.MIN_VALUE;            } else {                throw Trace.error(Trace.WRONG_DATA_TYPE,                                  Types.getTypeString(t));            }        }        long v = ((Number) o).longValue();        return minus ? -v                     : v;    }    Object getInType(int type) throws HsqlException {        getToken();        Object o = getAsValue();        int    t = getType();        if (t != type) {            throw Trace.error(Trace.WRONG_DATA_TYPE, Types.getTypeString(t));        }        return o;    }    /**     *     *     *     * @return     */    public int getType() throws HsqlException {        if (bWait) {            Trace.doAssert(false, "Querying state when in Wait mode");        }        // todo: make sure it's used only for Values!        // todo: synchronize iType with hColumn        switch (iType) {            case STRING :                return Types.VARCHAR;            case NUMBER :                return Types.INTEGER;            case LONG :                return Types.BIGINT;            case FLOAT :                return Types.DOUBLE;            case DECIMAL :                return Types.DECIMAL;            case BOOLEAN :                return Types.BOOLEAN;            case DATE :                return Types.DATE;            case TIME :                return Types.TIME;            case TIMESTAMP :                return Types.TIMESTAMP;            default :                return Types.NULL;        }    }    /**     * Method declaration     *     *     * @return     *     * @throws HsqlException     */    Object getAsValue() throws HsqlException {        if (!wasValue()) {            throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);        }        switch (iType) {            case NULL :                return null;            case STRING :                //fredt - no longer returning string with a singlequote as last char                return sToken;            case LONG :                return ValuePool.getLong(Long.parseLong(sToken));            case NUMBER :                // fredt - this returns unsigned values which are later negated.                // as a result Integer.MIN_VALUE or Long.MIN_VALUE are promoted                // to a wider type.                if (sToken.length() < 11) {                    try {                        return ValuePool.getInt(Integer.parseInt(sToken));                    } catch (Exception e1) {}                }                if (sToken.length() < 20) {                    try {                        iType = LONG;                        return ValuePool.getLong(Long.parseLong(sToken));                    } catch (Exception e2) {}                }                iType = DECIMAL;                return new BigDecimal(sToken);            case FLOAT ://#ifdef JAVA1TARGET/*                double d = new Double(sToken).doubleValue();*///#else                double d = Double.parseDouble(sToken);//#endif JAVA1TARGET                long l = Double.doubleToLongBits(d);                return ValuePool.getDouble(l);            case DECIMAL :                return new BigDecimal(sToken);            case BOOLEAN :                return sToken.equalsIgnoreCase("TRUE") ? Boolean.TRUE                                                       : Boolean.FALSE;            case DATE :                return HsqlDateTime.dateValue(sToken);            case TIME :                return HsqlDateTime.timeValue(sToken);            case TIMESTAMP :                return HsqlDateTime.timestampValue(sToken);            default :                return sToken;        }    }    /**     * return the current position to be used for VIEW processing     *     * @return     */    int getPosition() {        return iIndex;    }    /**     * mark the current position to be used for future getLastPart() calls     *     * @return     */    String getPart(int begin, int end) {        return sCommand.substring(begin, end);    }    /**     * mark the current position to be used for future getLastPart() calls     *     * @return     */    int getPartMarker() {        return beginIndex;    }    /**     * mark the current position to be used for future getLastPart() calls     *     */    void setPartMarker() {        beginIndex = iIndex;    }    /**     * mark the position to be used for future getLastPart() calls     *     */    void setPartMarker(int position) {        beginIndex = position;    }    /**     * return part of the command string from the last marked position     *     * @return     */    String getLastPart() {        return sCommand.substring(beginIndex, iIndex);    }// fredt@users 20020910 - patch 1.7.1 by Nitin Chauhan - rewrite as switch    /**     * Method declaration     *     *     * @throws HsqlException     */    private void getToken() throws HsqlException {        if (bWait) {            bWait  = false;            iIndex = nextTokenIndex;            return;        }        if (!retainFirst) {            sLongNameFirst    = null;            typeLongNameFirst = NO_TYPE;        }        while (iIndex < iLength                && Character.isWhitespace(sCommand.charAt(iIndex))) {            iIndex++;        }        sToken     = "";        tokenIndex = iIndex;        if (iIndex >= iLength) {            iType = NO_TYPE;            return;        }        char    c        = sCommand.charAt(iIndex);        boolean point    = false,                digit    = false,                exp      = false,                afterexp = false;        boolean end      = false;        char    cfirst   = 0;        lastTokenQuotedID = false;        if (Character.isJavaIdentifierStart(c)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -