java.lang.CharSequence#charAt ( )源码实例Demo

下面列出了java.lang.CharSequence#charAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: microMathematics   文件: UnitFormat.java
private long readLong (CharSequence csq, ParsePosition pos) {
    final int length = csq.length();
    int result = 0;
    boolean isNegative = false;
    while (pos.getIndex() < length) {
        char c = csq.charAt(pos.getIndex());
        if (c == '-') {
            isNegative = true;
        } else if ((c >= '0') && (c <= '9')) {
            result = result * 10 + (c - '0');
        } else {
            break;
        }
        pos.setIndex(pos.getIndex()+1);
    }
    return isNegative ? -result : result;
}
 
源代码2 项目: microMathematics   文件: UnitFormat.java
private int nextToken(CharSequence csq, ParsePosition pos) {
    final int length = csq.length();
    while (pos.getIndex() < length) {
        char c = csq.charAt(pos.getIndex());
        if (isUnitIdentifierPart(c)) {
            return IDENTIFIER;
        } else if (c == '(') {
            return OPEN_PAREN;
        } else if (c == ')') {
            return CLOSE_PAREN;
        } else if ((c == '^') || (c == '¹') || (c == '²') || (c == '³')) {
            return EXPONENT;
        } else if (c == '*') {
            char c2 = csq.charAt(pos.getIndex() + 1);
            if (c2 == '*') {
                return EXPONENT;
            } else {
                return MULTIPLY;
            }
        } else if (c == '·') {
            return MULTIPLY;
        } else if (c == '/') {
            return DIVIDE;
        } else if (c == '+') {
            return PLUS;
        } else if ((c == '-') || Character.isDigit(c)) {
            int index = pos.getIndex()+1;
            while ((index < length) && 
                   (Character.isDigit(c) || (c == '-') || (c == '.') || (c == 'E'))) {
                c = csq.charAt(index++);
                if (c == '.') {
                    return FLOAT;
                }
            }
            return INTEGER;
        }
        pos.setIndex(pos.getIndex() + 1);
    }
    return EOF;
}
 
源代码3 项目: nix-idea   文件: NixParserUtil.java
public static int indentationLevel(CharSequence c) {
    int i = 0;
    while(i < c.length() && c.charAt(i) == ' ') {
        i++;
    }
    return i;
}
 
源代码4 项目: microMathematics   文件: UnitFormat.java
private Exponent readExponent (CharSequence csq, ParsePosition pos) {
    char c = csq.charAt(pos.getIndex());
    if (c == '^') {
        pos.setIndex(pos.getIndex()+1);
    } else if (c == '*') {
        pos.setIndex(pos.getIndex()+2);
    }
    final int length = csq.length();
    int pow = 0;
    boolean isPowNegative = false;
    int root = 0;
    boolean isRootNegative = false;
    boolean isRoot = false;
    while (pos.getIndex() < length) {
        c = csq.charAt(pos.getIndex());
        if (c == '¹') {
            if (isRoot) {
                root = root * 10 + 1;
            } else {
                pow = pow * 10 + 1;
            }
        } else if (c == '²') {
            if (isRoot) {
                root = root * 10 + 2;
            } else {
                pow = pow * 10 + 2;
            }
        } else if (c == '³') {
            if (isRoot) {
                root = root * 10 + 3;
            } else {
                pow = pow * 10 + 3;
            }
        } else if (c == '-') {
            if (isRoot) {
                isRootNegative = true;
            } else {
                isPowNegative = true;
            }
        } else if ((c >= '0') && (c <= '9')) {
            if (isRoot) {
                root = root * 10 + (c - '0');
            } else {
                pow = pow * 10 + (c - '0');
            }
        } else if (c == ':') {
            isRoot = true;
        } else {
            break;
        }
        pos.setIndex(pos.getIndex()+1);
    }
    if (pow == 0) pow = 1;
    if (root == 0) root = 1;
    return new Exponent(isPowNegative ? -pow : pow, 
                      isRootNegative ? -root : root);
}
 
 方法所在类
 同类方法