]> source.dussan.org Git - poi.git/commitdiff
unary plus: patch by Amol Deshmukh, test added
authorAvik Sengupta <avik@apache.org>
Wed, 18 May 2005 18:58:57 +0000 (18:58 +0000)
committerAvik Sengupta <avik@apache.org>
Wed, 18 May 2005 18:58:57 +0000 (18:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353685 13f79535-47bb-0310-9956-ffa450edef68

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

index 78a94bff48510276b2afc9b201e3e1175104c163..2141b53ed086616e33c68b28bc3a4b6282251965 100644 (file)
@@ -115,7 +115,7 @@ public class FormulaParser {
     private void Abort(String s) {
         Error(s);
         //System.exit(1);  //throw exception??
-        throw new RuntimeException("Cannot Parse, sorry : "+s);
+        throw new RuntimeException("Cannot Parse, sorry : "+s + " [Formula String was: '"+formulaString+"']");
     }
     
     
@@ -466,6 +466,11 @@ public class FormulaParser {
                Factor();
                tokens.add(new UnaryMinusPtg());
        }
+        else if (look == '+') {
+            Match('+');
+            Factor();
+            tokens.add(new UnaryPlusPtg());
+        }
         else if (look == '(' ) {
             Match('(');
             Expression();
index ec840ba3b9e118bddc30d682b3853a83198047f0..1e69ce0ed36f244896d151c458adaba215ecfeee 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.record.formula.ReferencePtg;
 import org.apache.poi.hssf.record.formula.StringPtg;
 import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
+import org.apache.poi.hssf.record.formula.UnaryPlusPtg;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -323,7 +324,17 @@ public class TestFormulaParser extends TestCase {
                Ptg[] ptg = fp.getRPNPtg();
                assertTrue("got 2 ptgs", ptg.length == 2);
                assertTrue("first ptg is reference",ptg[0] instanceof ReferencePtg);
-               assertTrue("second ptg is string",ptg[1] instanceof UnaryMinusPtg);
+               assertTrue("second ptg is Minus",ptg[1] instanceof UnaryMinusPtg);
+     }
+    
+    public void testUnaryPlus()
+    {
+               FormulaParser fp = new FormulaParser("+A1", null);
+               fp.parse();
+               Ptg[] ptg = fp.getRPNPtg();
+               assertTrue("got 2 ptgs", ptg.length == 2);
+               assertTrue("first ptg is reference",ptg[0] instanceof ReferencePtg);
+               assertTrue("second ptg is Plus",ptg[1] instanceof UnaryPlusPtg);
      }
     
        public void testLeadingSpaceInString()