From c38fc6e7a00ba03c2acd93bf756de683b237527b Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Sun, 26 May 2002 23:19:58 +0000 Subject: [PATCH] Patches from Werner Froidevaux PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352649 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/record/formula/FormulaParser.java | 33 +++-- .../apache/poi/hssf/record/formula/Ptg.java | 14 +-- .../poi/hssf/record/formula/StringPtg.java | 119 ++++++++++++++++++ 3 files changed, 146 insertions(+), 20 deletions(-) create mode 100644 src/java/org/apache/poi/hssf/record/formula/StringPtg.java diff --git a/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java b/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java index 6fd242caf..6498ae9ee 100644 --- a/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java +++ b/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java @@ -70,7 +70,7 @@ import java.io.File; * Lets Build a Compiler, by Jack Crenshaw * BNF for the formula expression is : * ::= [ ]* - * ::= [ ::= [ ]* * ::= | () | | * ::= ([expression [, expression]*]) * @@ -281,8 +281,13 @@ public class FormulaParser { numArgs++; Expression(); } - while (Look == ',') { //TODO handle EmptyArgs - Match(','); + while (Look == ',' || Look == ';') { //TODO handle EmptyArgs + if(Look == ',') { + Match(','); + } + else { + Match(';'); + } Expression(); numArgs++; } @@ -454,15 +459,19 @@ end; String[] operands; for (int i=0;i 0) { + o = (OperationPtg) ptgs[i]; + numOperands = o.getNumberOfOperands(); + operands = new String[numOperands]; + for (int j=0;j. + */ + +package org.apache.poi.hssf.record.formula; + +import org.apache.poi.util.LittleEndian; + +/** + * Number + * Stores a String value in a formula value stored in the format char[] + * @author Werner Froidevaux + */ + +public class StringPtg + extends Ptg +{ + public final static int SIZE = 9; + public final static byte sid = 0x17; + private String field_1_value; + + + /** Create a StringPtg from a byte array read from disk */ + public StringPtg(byte [] data, int offset) + { + setValue(new String(data, offset+3, data[offset+1] + 256*data[offset+2])); + } + + /** Create a StringPtg from a string representation of the number + * Number format is not checked, it is expected to be validated in the parser + * that calls this method. + * @param value : String representation of a floating point number + */ + protected StringPtg(String value) { + setValue(value); + } + + + public void setValue(String value) + { + field_1_value = value; + } + + + public String getValue() + { + return field_1_value; + } + + public void writeBytes(byte [] array, int offset) + { + array[ offset + 0 ] = sid; + array[ offset + 1 ] = (byte)(getValue().length() % 256); + array[ offset + 2 ] = (byte)(getValue().length() / 256); + System.arraycopy(getValue().getBytes(), 0, array, offset + 3, getValue().length()); + } + + public int getSize() + { + return field_1_value.length() + 3; + } + + public String toFormulaString() + { + return getValue(); + } + +} +