]> source.dussan.org Git - poi.git/commitdiff
Small fix for FormulaParser. Need case-insentive match for IF function name
authorJosh Micich <josh@apache.org>
Mon, 26 May 2008 18:25:02 +0000 (18:25 +0000)
committerJosh Micich <josh@apache.org>
Mon, 26 May 2008 18:25:02 +0000 (18:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@660263 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/FormulaParser.java
src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java

index b6c711729045474abbbf2177b6c5dc3cada542b9..94cf9978a66a69c038014900d844a36a117d3d41 100644 (file)
@@ -382,7 +382,7 @@ public final class FormulaParser {
         } else {
             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()
             return retval;
         }
@@ -1014,19 +1014,8 @@ end;
                 }
             }
 
-            final OperationPtg o = (OperationPtg) ptg;
-            int nOperands = 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();
-            }
+            OperationPtg o = (OperationPtg) ptg;
+            String[] operands = getOperands(stack, o.getNumberOfOperands());
             stack.push(o.toFormulaString(operands));
         }
         if(stack.isEmpty()) {
@@ -1042,6 +1031,20 @@ end;
         }
         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
      *  to a human readable string format in infix mode. Works
index f2821140f3c325ae6cfdaac482463a9539635b12..29619501e0a330896d7ef67ed814fab9219c8338 100644 (file)
@@ -644,8 +644,16 @@ public final class TestFormulaParser extends TestCase {
 
                Class[] expClss;
 
-               expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class,
-                               FuncVarPtg.class, };
+               expClss = new Class[] { 
+                               ReferencePtg.class, 
+                               AttrPtg.class, // tAttrIf
+                               MissingArgPtg.class, 
+                               AttrPtg.class, // tAttrSkip
+                               ReferencePtg.class,
+                               AttrPtg.class, // tAttrSkip
+                               FuncVarPtg.class, 
+               };
+
                confirmTokenClasses("if(A1, ,C1)", expClss);
 
                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");
                } catch (IllegalStateException e) {
                        // 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"));
                }
        }
        /**