void next() throws PropertyException {
currentTokenValue = null;
currentTokenStartIndex = exprIndex;
boolean currentMaybeOperator = recognizeOperator;
boolean bSawDecimal;
recognizeOperator = true;
for (; ;) {
if (exprIndex >= exprLength) {
currentToken = TOK_EOF;
return;
}
char c = expr.charAt(exprIndex++);
switch (c) {
case ' ":
case '\t":
case '\r":
case '\n":
currentTokenStartIndex = exprIndex;
break;
case ',":
recognizeOperator = false;
currentToken = TOK_COMMA;
return;
case '+":
recognizeOperator = false;
currentToken = TOK_PLUS;
return;
case '-":
recognizeOperator = false;
currentToken = TOK_MINUS;
return;
case '(":
currentToken = TOK_LPAR;
recognizeOperator = false;
return;
case ')":
currentToken = TOK_RPAR;
return;
case '"":
case '\'":
exprIndex = expr.indexOf(c, exprIndex);
if (exprIndex < 0) {
exprIndex = currentTokenStartIndex + 1;
throw new PropertyException("missing quote");
}
currentTokenValue = expr.substring(currentTokenStartIndex
+ 1, exprIndex++);
currentToken = TOK_LITERAL;
return;
case '*":
/*
* if (currentMaybeOperator) {
* recognizeOperator = false;
*/
currentToken = TOK_MULTIPLY;
/*
* }
* else
* throw new PropertyException("illegal operator *");
*/
return;
case '0":
case '1":
case '2":
case '3":
case '4":
case '5":
case '6":
case '7":
case '8":
case '9":
scanDigits();
if (exprIndex < exprLength && expr.charAt(exprIndex) == '.") {
exprIndex++;
bSawDecimal = true;
if (exprIndex < exprLength
&& isDigit(expr.charAt(exprIndex))) {
exprIndex++;
scanDigits();
}
} else {
bSawDecimal = false;
}
if (exprIndex < exprLength && expr.charAt(exprIndex) == '%") {
exprIndex++;
currentToken = TOK_PERCENT;
} else {
// Check for possible unit name following number
currentUnitLength = exprIndex;
scanName();
currentUnitLength = exprIndex - currentUnitLength;
currentToken = (currentUnitLength > 0) ? TOK_NUMERIC
: (bSawDecimal ? TOK_FLOAT : TOK_INTEGER);
}
currentTokenValue = expr.substring(currentTokenStartIndex,
exprIndex);
return;
case '.":
nextDecimalPoint();
return;
case '#": // Start of color value
nextColor();
return;
default:
--exprIndex;
scanName();
if (exprIndex == currentTokenStartIndex) {
throw new PropertyException("illegal character");
}
currentTokenValue = expr.substring(currentTokenStartIndex,
exprIndex);
// if (currentMaybeOperator) {
if (currentTokenValue.equals("mod")) {
currentToken = TOK_MOD;
return;
} else if (currentTokenValue.equals("div")) {
currentToken = TOK_DIV;
return;
}
/*
* else
* throw new PropertyException("unrecognized operator name");
* recognizeOperator = false;
* return;
* }
*/
if (followingParen()) {
currentToken = TOK_FUNCTION_LPAR;
recognizeOperator = false;
} else {
currentToken = TOK_NCNAME;
recognizeOperator = false;
}
return;
}
}
}
Return the next token in the expression string.
This sets the following package visible variables:
currentToken An enumerated value identifying the recognized token
currentTokenValue A String containing the token contents
currentUnitLength If currentToken = TOK_NUMERIC, the number of
characters in the unit name. |