Skip to content

Commit

Permalink
非浮点型科学计数解析异常问题fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwenxing committed May 12, 2022
1 parent 922529c commit db36124
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/com/ql/util/express/parse/ExpressParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ public List<ExpressNode> transferWord2ExpressNode(ExpressPackage rootExpressPack
tempWord = tempWord.substring(0, tempWord.length() - 1);
objectValue = Long.valueOf(tempWord);
} else {
long tempLong = Long.parseLong(tempWord);
long tempLong;
if (tempWord.indexOf("e") >=0 || tempWord.indexOf("E") >=0) {
tempLong = Double.valueOf(tempWord).longValue();
} else {
tempLong = Long.parseLong(tempWord);
}
if (tempLong <= Integer.MAX_VALUE && tempLong >= Integer.MIN_VALUE) {
tempType = nodeTypeManager.findNodeType("CONST_INTEGER");
objectValue = (int)tempLong;
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/ql/util/express/bugfix/ScientificNumberTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ql.util.express.bugfix;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.IExpressContext;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
* created by jiwenxing on 2022/5/12
*/
public class ScientificNumberTest {

static List<String> express = new ArrayList<>();
static {
express.add("2e2==200");
express.add("2E2==200");
express.add("2.0e2==200");
express.add("2.0E2==200");
}

@Test
public void testFunction() throws Exception {
ExpressRunner runner = new ExpressRunner();
IExpressContext<String, Object> context = new DefaultContext<>();
for (String exp: express) {
Object result = runner.execute(exp, context, null, false, false);
System.out.println(exp + ": " + result);
assert ((Boolean)result);
}
}
}

0 comments on commit db36124

Please sign in to comment.