Small fix for FormulaParser. Need case-insentive match for IF function name
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@660263 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
94c7876f74
commit
5ffa668496
@ -382,7 +382,7 @@ public final class FormulaParser {
|
|||||||
} else {
|
} else {
|
||||||
retval = new FuncPtg(funcIx);
|
retval = new FuncPtg(funcIx);
|
||||||
}
|
}
|
||||||
if (!name.equals(AbstractFunctionPtg.FUNCTION_NAME_IF)) {
|
if (!name.equalsIgnoreCase(AbstractFunctionPtg.FUNCTION_NAME_IF)) {
|
||||||
// early return for everything else besides IF()
|
// early return for everything else besides IF()
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -1014,19 +1014,8 @@ end;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final OperationPtg o = (OperationPtg) ptg;
|
OperationPtg o = (OperationPtg) ptg;
|
||||||
int nOperands = o.getNumberOfOperands();
|
String[] operands = getOperands(stack, o.getNumberOfOperands());
|
||||||
final String[] operands = new String[nOperands];
|
|
||||||
|
|
||||||
for (int j = nOperands-1; j >= 0; j--) { // reverse iteration because args were pushed in-order
|
|
||||||
if(stack.isEmpty()) {
|
|
||||||
String msg = "Too few arguments suppled to operation token ("
|
|
||||||
+ o.getClass().getName() + "). Expected (" + nOperands
|
|
||||||
+ ") operands but got (" + (nOperands - j - 1) + ")";
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
operands[j] = (String) stack.pop();
|
|
||||||
}
|
|
||||||
stack.push(o.toFormulaString(operands));
|
stack.push(o.toFormulaString(operands));
|
||||||
}
|
}
|
||||||
if(stack.isEmpty()) {
|
if(stack.isEmpty()) {
|
||||||
@ -1042,6 +1031,20 @@ end;
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String[] getOperands(Stack stack, int nOperands) {
|
||||||
|
String[] operands = new String[nOperands];
|
||||||
|
|
||||||
|
for (int j = nOperands-1; j >= 0; j--) { // reverse iteration because args were pushed in-order
|
||||||
|
if(stack.isEmpty()) {
|
||||||
|
String msg = "Too few arguments supplied to operation. Expected (" + nOperands
|
||||||
|
+ ") operands but got (" + (nOperands - j - 1) + ")";
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
operands[j] = (String) stack.pop();
|
||||||
|
}
|
||||||
|
return operands;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Static method to convert an array of Ptgs in RPN order
|
* Static method to convert an array of Ptgs in RPN order
|
||||||
* to a human readable string format in infix mode. Works
|
* to a human readable string format in infix mode. Works
|
||||||
|
@ -644,8 +644,16 @@ public final class TestFormulaParser extends TestCase {
|
|||||||
|
|
||||||
Class[] expClss;
|
Class[] expClss;
|
||||||
|
|
||||||
expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class,
|
expClss = new Class[] {
|
||||||
FuncVarPtg.class, };
|
ReferencePtg.class,
|
||||||
|
AttrPtg.class, // tAttrIf
|
||||||
|
MissingArgPtg.class,
|
||||||
|
AttrPtg.class, // tAttrSkip
|
||||||
|
ReferencePtg.class,
|
||||||
|
AttrPtg.class, // tAttrSkip
|
||||||
|
FuncVarPtg.class,
|
||||||
|
};
|
||||||
|
|
||||||
confirmTokenClasses("if(A1, ,C1)", expClss);
|
confirmTokenClasses("if(A1, ,C1)", expClss);
|
||||||
|
|
||||||
expClss = new Class[] { MissingArgPtg.class, AreaPtg.class, MissingArgPtg.class,
|
expClss = new Class[] { MissingArgPtg.class, AreaPtg.class, MissingArgPtg.class,
|
||||||
@ -814,7 +822,7 @@ public final class TestFormulaParser extends TestCase {
|
|||||||
fail("Expected exception was not thrown");
|
fail("Expected exception was not thrown");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
// expected during successful test
|
// expected during successful test
|
||||||
assertTrue(e.getMessage().startsWith("Too few arguments suppled to operation token"));
|
assertTrue(e.getMessage().startsWith("Too few arguments supplied to operation"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user