in common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java [89:165]
private static List<Op> participle(String expression) {
List<Op> segments = new ArrayList<>();
int size = expression.length();
int wordStartIndex = -1;
int wordLen = 0;
Type preType = Type.NULL;
for (int i = 0; i < size; i++) {
int chValue = (int) expression.charAt(i);
if (97 <= chValue && chValue <= 122 || 65 <= chValue && chValue <= 90
|| 49 <= chValue && chValue <= 57 || 95 == chValue) {
if (Type.OPERATOR == preType || Type.SEPAERATOR == preType || Type.NULL == preType
|| Type.PARENTHESIS == preType) {
if (Type.OPERATOR == preType) {
segments.add(createOperator(expression.substring(wordStartIndex, wordStartIndex
+ wordLen)));
}
wordStartIndex = i;
wordLen = 0;
}
preType = Type.OPERAND;
wordLen++;
} else if (40 == chValue || 41 == chValue) {
if (Type.OPERATOR == preType) {
segments.add(createOperator(expression
.substring(wordStartIndex, wordStartIndex + wordLen)));
wordStartIndex = -1;
wordLen = 0;
} else if (Type.OPERAND == preType) {
segments.add(new Operand(expression.substring(wordStartIndex, wordStartIndex + wordLen)));
wordStartIndex = -1;
wordLen = 0;
}
preType = Type.PARENTHESIS;
segments.add(createOperator((char) chValue + ""));
} else if (38 == chValue || 124 == chValue) {
if (Type.OPERAND == preType || Type.SEPAERATOR == preType || Type.PARENTHESIS == preType) {
if (Type.OPERAND == preType) {
segments.add(new Operand(expression.substring(wordStartIndex, wordStartIndex
+ wordLen)));
}
wordStartIndex = i;
wordLen = 0;
}
preType = Type.OPERATOR;
wordLen++;
} else if (32 == chValue || 9 == chValue) {
if (Type.OPERATOR == preType) {
segments.add(createOperator(expression
.substring(wordStartIndex, wordStartIndex + wordLen)));
wordStartIndex = -1;
wordLen = 0;
} else if (Type.OPERAND == preType) {
segments.add(new Operand(expression.substring(wordStartIndex, wordStartIndex + wordLen)));
wordStartIndex = -1;
wordLen = 0;
}
preType = Type.SEPAERATOR;
} else {
throw new IllegalArgumentException("illegal expression, at index " + i + " " + (char) chValue);
}
}
if (wordLen > 0) {
segments.add(new Operand(expression.substring(wordStartIndex, wordStartIndex + wordLen)));
}
return segments;
}