Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 解决以数字开头的字符串变量KEY解析报错问题 #367

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/com/ql/util/express/ExpressUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.ql.util.express.config.QLExpressRunStrategy;
import com.ql.util.express.exception.QLException;
import com.ql.util.express.util.QLAliasUtils;
import org.apache.commons.lang.StringUtils;

/**
* 表达式工具类
Expand Down Expand Up @@ -754,4 +755,32 @@ private static boolean hasOnlyOneAbstractMethod(Method[] methods) {
}
return count == 1;
}

public static boolean isNumber(String tempWord) {
if (StringUtils.isBlank(tempWord)) {
return false;
}
if (tempWord.length() == 1) {
char c = tempWord.charAt(0);
return c >= '0' && c <= '9';
}
int lastIndex = tempWord.length() - 1;
boolean hasDecimalPoint = false;
for (int i = 0; i <= lastIndex; i++) {
char c = Character.toLowerCase(tempWord.charAt(i));
if (c == '.' && !hasDecimalPoint) {
hasDecimalPoint = true;
continue;
}
if (i == lastIndex) {
if (c == 'd' || c == 'f' || c == 'l') {
return true;
}
}
if (!Character.isDigit(c)){
return false;
}
}
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/ql/util/express/parse/ExpressParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public List<ExpressNode> transferWord2ExpressNode(ExpressPackage rootExpressPack

char firstChar = tempWord.charAt(0);
char lastChar = tempWord.substring(tempWord.length() - 1).toLowerCase().charAt(0);
if (firstChar >= '0' && firstChar <= '9') {
if (ExpressUtil.isNumber(tempWord)) {
if (!result.isEmpty()) {
// 对负号进行特殊处理
if ("-".equals(result.get(result.size() - 1).getValue())) {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/ql/util/express/parse/WordSplit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.List;

import com.ql.util.express.ExpressUtil;
import com.ql.util.express.exception.QLCompileException;

/**
Expand Down Expand Up @@ -136,12 +137,7 @@ public static void sortSplitWord(String[] splitWord) {
}

protected static boolean isNumber(String str) {
if (str == null || "".equals(str)) {
return false;
}
char c = str.charAt(0);
// 数字
return c >= '0' && c <= '9';
return ExpressUtil.isNumber(str);
}

public static String getPrintInfo(Object[] list, String splitOp) {
Expand Down