You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/05/26 20:25:04 UTC

svn commit: r660263 - in /poi/trunk/src: java/org/apache/poi/hssf/model/FormulaParser.java testcases/org/apache/poi/hssf/model/TestFormulaParser.java

Author: josh
Date: Mon May 26 11:25:02 2008
New Revision: 660263

URL: http://svn.apache.org/viewvc?rev=660263&view=rev
Log:
Small fix for FormulaParser. Need case-insentive match for IF function name

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

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java?rev=660263&r1=660262&r2=660263&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java Mon May 26 11:25:02 2008
@@ -382,7 +382,7 @@
         } 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 @@
                 }
             }
 
-            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 @@
         }
         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

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java?rev=660263&r1=660262&r2=660263&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java Mon May 26 11:25:02 2008
@@ -644,8 +644,16 @@
 
 		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 @@
 			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"));
 		}
 	}
 	/**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org