bug 33160, original patch and testcase supplied by Amol Deshmukh.. thanks. This version slightly more generic
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353641 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c27f7ab5e5
commit
f931d7cf7e
@ -484,12 +484,28 @@ public class FormulaParser {
|
|||||||
if (IsDigit(look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234."
|
if (IsDigit(look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234."
|
||||||
tokens.add(new NumberPtg(number));
|
tokens.add(new NumberPtg(number));
|
||||||
} else {
|
} else {
|
||||||
tokens.add(new IntPtg(number)); //TODO:what if the number is too big to be a short? ..add factory to return Int or Number!
|
tokens.add(getNumberPtgFromString(number)); //TODO:what if the number is too big to be a short? ..add factory to return Int or Number!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StringLiteral()
|
/** Get a PTG for an integer from its string representation.
|
||||||
|
* return Int or Number Ptg based on size of input
|
||||||
|
* @param number
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Ptg getNumberPtgFromString(String number) {
|
||||||
|
try {
|
||||||
|
return new IntPtg(number);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Caught NFE, returning Number Ptg");
|
||||||
|
return new NumberPtg(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void StringLiteral()
|
||||||
{
|
{
|
||||||
// Can't use match here 'cuz it consumes whitespace
|
// Can't use match here 'cuz it consumes whitespace
|
||||||
// which we need to preserve inside the string.
|
// which we need to preserve inside the string.
|
||||||
|
@ -23,6 +23,7 @@ import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
|
|||||||
import org.apache.poi.hssf.record.formula.AddPtg;
|
import org.apache.poi.hssf.record.formula.AddPtg;
|
||||||
import org.apache.poi.hssf.record.formula.AttrPtg;
|
import org.apache.poi.hssf.record.formula.AttrPtg;
|
||||||
import org.apache.poi.hssf.record.formula.BoolPtg;
|
import org.apache.poi.hssf.record.formula.BoolPtg;
|
||||||
|
import org.apache.poi.hssf.record.formula.DividePtg;
|
||||||
import org.apache.poi.hssf.record.formula.EqualPtg;
|
import org.apache.poi.hssf.record.formula.EqualPtg;
|
||||||
import org.apache.poi.hssf.record.formula.FuncVarPtg;
|
import org.apache.poi.hssf.record.formula.FuncVarPtg;
|
||||||
import org.apache.poi.hssf.record.formula.IntPtg;
|
import org.apache.poi.hssf.record.formula.IntPtg;
|
||||||
@ -30,6 +31,7 @@ import org.apache.poi.hssf.record.formula.LessEqualPtg;
|
|||||||
import org.apache.poi.hssf.record.formula.LessThanPtg;
|
import org.apache.poi.hssf.record.formula.LessThanPtg;
|
||||||
import org.apache.poi.hssf.record.formula.NamePtg;
|
import org.apache.poi.hssf.record.formula.NamePtg;
|
||||||
import org.apache.poi.hssf.record.formula.NotEqualPtg;
|
import org.apache.poi.hssf.record.formula.NotEqualPtg;
|
||||||
|
import org.apache.poi.hssf.record.formula.NumberPtg;
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
import org.apache.poi.hssf.record.formula.Ptg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
||||||
import org.apache.poi.hssf.record.formula.StringPtg;
|
import org.apache.poi.hssf.record.formula.StringPtg;
|
||||||
@ -352,6 +354,29 @@ public class TestFormulaParser extends TestCase {
|
|||||||
assertTrue("got 3 ptg", ptg.length == 3);
|
assertTrue("got 3 ptg", ptg.length == 3);
|
||||||
assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE);
|
assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** bug 33160*/
|
||||||
|
public void testLargeInt() {
|
||||||
|
FormulaParser fp = new FormulaParser("40", null);
|
||||||
|
fp.parse();
|
||||||
|
Ptg[] ptg=fp.getRPNPtg();
|
||||||
|
assertTrue("ptg is Int, is "+ptg[0].getClass(),ptg[0] instanceof IntPtg);
|
||||||
|
|
||||||
|
fp = new FormulaParser("40000", null);
|
||||||
|
fp.parse();
|
||||||
|
ptg=fp.getRPNPtg();
|
||||||
|
assertTrue("ptg should be Number, is "+ptg[0].getClass(), ptg[0] instanceof NumberPtg);
|
||||||
|
}
|
||||||
|
/** bug 33160, testcase by Amol Deshmukh*/
|
||||||
|
public void testSimpleLongFormula() {
|
||||||
|
FormulaParser fp = new FormulaParser("40000/2", null);
|
||||||
|
fp.parse();
|
||||||
|
Ptg[] ptgs = fp.getRPNPtg();
|
||||||
|
assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3);
|
||||||
|
assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg));
|
||||||
|
assertTrue("IntPtg",(ptgs[1] instanceof IntPtg));
|
||||||
|
assertTrue("DividePtg",(ptgs[2] instanceof DividePtg));
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
|
System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
|
||||||
|
Loading…
Reference in New Issue
Block a user