Skip to content
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